forked from lorem--ipsum/cammy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
unit.spec.js
178 lines (142 loc) · 5.39 KB
/
unit.spec.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
describe('$nom', function() {
beforeEach(module('nomnom'));
describe('$herlock', function() {
xit('should generate dots for a side size = 1', inject(function($herlock) {
var expectedResult = [{ x : -0.5, y : -0.5 }, { x : -0.5, y : 0.5 }, { x : 0.5, y : -0.5 }, { x : 0.5, y : 0.5 }];
expect($herlock.dots(1)).toEqual(expectedResult);
}));
it('should generate proper amount of dots', inject(function($herlock) {
expect($herlock.dots(5).length).toBe(5*5);
expect($herlock.dots(15).length).toBe(15*15);
expect($herlock.dots(25).length).toBe(25*25);
}));
it('should link dots for a 3x3 grid', inject(function($herlock) {
var vertices = [
{color: "a"}, {color: "b"}, {color: "c"},
{color: "d"}, {color: "e"}, {color: "f"},
{color: "g"}, {color: "h"}, {color: "i"}
];
var expectedResult =[
{from: 0, to: 1},
{from: 1, to: 2},
{from: 3, to: 4},
{from: 4, to: 5},
{from: 6, to: 7},
{from: 7, to: 8},
{from: 0, to: 3},
{from: 3, to: 6},
{from: 1, to: 4},
{from: 4, to: 7},
{from: 2, to: 5},
{from: 5, to: 8}
]
expect($herlock.link(3, 3, vertices)).toEqual(expectedResult);
}));
it('should link dots for a 5x5 grid', inject(function($herlock) {
var vertices = [
{color: "a"}, {color: "b"}, {color: "c"}, {color: "0"}, {color: "5"},
{color: "d"}, {color: "e"}, {color: "f"}, {color: "1"}, {color: "6"},
{color: "g"}, {color: "h"}, {color: "i"}, {color: "2"}, {color: "7"},
{color: "j"}, {color: "k"}, {color: "l"}, {color: "3"}, {color: "8"},
{color: "m"}, {color: "n"}, {color: "o"}, {color: "4"}, {color: "9"}
];
var expectedResult = [
{from: 0, to: 1},
{from: 1, to: 2},
{from: 2, to: 3},
{from: 3, to: 4},
{from: 5, to: 6},
{from: 6, to: 7},
{from: 7, to: 8},
{from: 8, to: 9},
{from: 10, to: 11},
{from: 11, to: 12},
{from: 12, to: 13},
{from: 13, to: 14},
{from: 15, to: 16},
{from: 16, to: 17},
{from: 17, to: 18},
{from: 18, to: 19},
{from: 20, to: 21},
{from: 21, to: 22},
{from: 22, to: 23},
{from: 23, to: 24},
{from: 0, to: 5},
{from: 5, to: 10},
{from: 10, to: 15},
{from: 15, to: 20},
{from: 1, to: 6},
{from: 6, to: 11},
{from: 11, to: 16},
{from: 16, to: 21},
{from: 2, to: 7},
{from: 7, to: 12},
{from: 12, to: 17},
{from: 17, to: 22},
{from: 3, to: 8},
{from: 8, to: 13},
{from: 13, to: 18},
{from: 18, to: 23},
{from: 4, to: 9},
{from: 9, to: 14},
{from: 14, to: 19},
{from: 19, to: 24}
];
expect($herlock.link(5, 5, vertices)).toEqual(expectedResult);
}));
it('should work with 50x50 vertices', inject(function($herlock) {
$herlock.link(50, 50);
}))
});
describe('unit behavior', function() {
it('should detect an invalid expression', inject(function($n) {
expect(function() {$n.om(12, 'toto');}).toThrow();
// If the first expression is true, the next is never evaluated.
// This should be changed.
expect(function() {$n.om(12, '11').or(78);}).toThrow();
}));
it('should detect an inside value', inject(function($n) {
expect($n.om(12, ']10,15[')()).toBeTruthy();
}));
it('should treat a single value as an equality', inject(function($n) {
expect($n.om(12, '12')()).toBeTruthy();
expect($n.om(12, '11')()).toBeFalsy();
}));
it('should detect an outside value', inject(function($n) {
expect($n.om(18, ']10,15[')()).toBeFalsy();
}));
it('should detect a border value', inject(function($n) {
expect($n.om(15, ']10,15]')()).toBeTruthy();
}));
})
describe('OR chaining', function() {
it('should handle new expression', inject(function($n) {
expect($n.om(27, ']10,15]').or('[24,42[')()).toBeTruthy();
expect($n.om(27, ']10,15]').or('[24,25[')()).toBeFalsy();
expect($n.om(27, ']10,15]').or('[24,42[').or('[0,10]')).toBeTruthy();
expect($n.om(180, '[0,10]').or('[170,190]')()).toBeTruthy();
expect($n.om(180, '[0,10]').or('[170,190]').or('[350,360]')()).toBeTruthy();
}));
it('should handle new value and new expression', inject(function($n) {
expect($n.om(27,']10,15]').or('[28,42[').or(9,'[0,10]')).toBeTruthy();
}));
});
describe('AND chaining', function() {
it('should handle new expression', inject(function($n) {
expect($n.om(12, ']10,15]').and('[9,42[')()).toBeTruthy();
expect($n.om(12, ']10,15]').and('[9,42[').and('[0,100]')()).toBeTruthy();
expect($n.om(12, ']10,15]').and('[9,42[').and('[90,100]')()).toBeFalsy();
}));
it('should handle new value and new expression', inject(function($n) {
expect($n.om(12,']10,15]').and('[0,42[').and(9,'[0,10]')).toBeTruthy();
}));
});
it('should throw an error when mixing operators', inject(function($n) {
expect(function() {
$n.om(12, ']10,15]').and('[9,42[').or('[0,100]')()
}).toThrow();
expect(function() {
$n.om(12, ']10,15]').or('[9,42[').and('[0,100]')()
}).toThrow();
}));
})