-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCodeSpecs.js
131 lines (106 loc) · 3.75 KB
/
CodeSpecs.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
//Main test suite
describe('Dependency and Package Installer', function() {
it('input accepts an array of strings', function() {
var inputObj = ['p:q','r:s'];
var installer = new pkgInstaller(['p:q','r:s']);
expect(installer.inputObj).toEqual(inputObj);
});
it('type is an object', function() {
expect(typeof pkgInstaller).toBe('function');
});
it('output returns a string', function() {
expect(new pkgInstaller(['p:q','r:s']).checkInsDep()).toEqual(jasmine.any(String));
});
describe('program fails when', function() {
it('given an object', function() {
expect(function() { new pkgInstaller({ p:'q' }); }).toThrow();
});
it('given a number', function() {
expect(function() { new pkgInstaller(1); }).toThrow();
});
it('given a string', function() {
expect(function() { new pkgInstaller('p'); }).toThrow();
});
it('array contains object', function() {
expect(function() { new pkgInstaller([{p:'q'},{r:'s'}]); }).toThrow();
});
it('array contains numbers', function() {
expect(function() { new pkgInstaller([1,2]); }).toThrow();
});
});
describe('should thorw error', function() {
it('because of a invalid round check', function () {
expect(function () {
var packageInstaller = pkgInstaller(['p:q', 'r:s']);
packageInstaller.checkInsDep();
}).toThrow('Invalid dependency link');
});
});
describe('will be successfull', function() {
it('when valid input links are passed', function() {
var input = ['p:'];
expect(new pkgInstaller(input).checkInsDep()).toEqual('p');
});
it('with symbols and quotes', function() {
var input = [
'!@#$%^&*()_+""{}[]:'
];
expect(new pkgInstaller(input).checkInsDep()).toEqual('!@#$%^&*()_+""{}[]');
});
it('with lots of singles', function() {
var input = ('akasjdlaksjdlaksjdasdla').split('').map(function(a) { return a + ':'; });
expect(new pkgInstaller(input).checkInsDep()).toEqual(('akasjdlaksjdlaksjdasdla').split('').join(', '));
});
it('with words with spaces', function() {
var input = [
'Kitten Service:Camel Caser',
'Camel Caser:'
];
expect(new pkgInstaller(input).checkInsDep()).toEqual('Camel Caser, Kitten Service');
});
it('even when a package contains many dependencies', function() {
var input = [
'p:',
'q:p',
'r:p',
's:r',
't:r'
];
expect(new pkgInstaller(input).checkInsDep()).toEqual('p, q, r, s, t');
});
it('when a inputObj are out of order', function() {
var input = [
'b:a',
'c:b',
'a:',
];
expect(new pkgInstaller(input).checkInsDep()).toEqual('a, b, c');
});
});
describe('will handle duplicates', function() {
it('when given duplicate inputObj', function() {
var input = ['p:','q:', 'q:p'];
expect(new pkgInstaller(input).checkInsDep()).toEqual('a, b');
});
});
describe('checking sample', function() {
it('expects the first to function', function(){
var input = [
'KittenService:CamelCaser',
'CamelCaser:'
];
expect(new pkgInstaller(input).checkInsDep()).toEqual('CamelCaser, KittenService');
});
it('expects the output', function() {
var input = [
'KittenService:',
'Letmeme:Cyberportal',
'Cyberportal:Ice',
'CamelCaser:KittenService',
'Fraudstream:Letmeme',
'Ice:'
];
expect(new pkgInstaller(input).checkInsDep()).toEqual('KittenService, Ice, Cyberportal, Letmeme, CamelCaser, Fraudstream');
});
});
});