-
Notifications
You must be signed in to change notification settings - Fork 3
/
loo.js-tests.html
204 lines (178 loc) · 7.38 KB
/
loo.js-tests.html
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js">
</script>
<link rel="stylesheet"
href="http://code.jquery.com/qunit/git/qunit.css"
type="text/css" media="screen" />
<script type="text/javascript"
src="http://code.jquery.com/qunit/git/qunit.js">
</script>
<script type="text/javascript" src="loo.js">
</script>
<script>
$(document).ready(function(){
module('loo.max_occupants');
test("<=0 stalls", function(){
equal(
loo.max_occupants(0), 0,
"No stalls, zero occupants"
);
equal(
loo.max_occupants(-1), 0,
"Negative number of stalls, zero occupants"
);
});
test("1 through 5 stalls", function(){
equal(
loo.max_occupants(1), 1,
"One stall, maximum one occupant"
);
equal(
loo.max_occupants(2), 1,
"Two stalls, maximum one occupant"
);
equal(
loo.max_occupants(3), 2,
"Three stalls, two maximum occupants"
);
equal(
loo.max_occupants(4), 2,
"Four stalls, two maximum occupants"
);
equal(
loo.max_occupants(5), 3,
"Five stalls, three maximum occupants"
);
});
test("50 stalls", function(){
equal(
loo.max_occupants(5), 3,
"50 stalls, 34 maximum occupants"
);
});
test("8 billion stalls (for every person on earth)",
function(){
equal(
loo.max_occupants(8000000000), 3705032704,
"Eight billion stalls, ~3.7 billion occupants"
);
});
module('loo.minesweeper');
test("0 stalls", function(){
deepEqual(loo.minesweeper([]), [],
"No stalls, no minesweeper map"
);
});
test("1 stall", function(){
deepEqual(loo.minesweeper([true]), [0],
"One occupied stall"
);
deepEqual(loo.minesweeper([false]), [undefined],
"One vacant stall"
);
});
test("3 stalls", function(){
deepEqual(loo.minesweeper([false, false, false]),
[undefined, undefined, undefined],
"Three vacant stalls"
);
deepEqual(loo.minesweeper([false, true, false]),
[1, 0, 1],
"vacant, occupied, vacant"
);
deepEqual(loo.minesweeper([true, false, true]),
[0, 1, 0],
"occupied, vacant, occupied"
);
deepEqual(loo.minesweeper([true, false, false]),
[0, 1, 2],
"occupied, vacant, vacant"
);
});
test("5 stalls", function(){
deepEqual(
loo.minesweeper(
[true, false, true, false, true]
),
[0, 1, 0, 1, 0],
"occupied, vacant, occupied, vacant, occupied"
);
deepEqual(
loo.minesweeper(
[true, false, false, false, true]
),
[0, 1, 2, 1, 0],
"occupied, vacant, vacant, vacant, occupied"
);
deepEqual(
loo.minesweeper(
[false, false, true, false, false]
),
[2, 1, 0, 1, 2],
"vacant, vacant, occupied, vacant, vacant"
);
deepEqual(
loo.minesweeper(
[false, false, false, true, false]
),
[3, 2, 1, 0, 1],
"vacant, vacant, vacant, occupied, vacant"
);
});
module('loo.choose');
test("0 stalls", function(){
deepEqual(loo.choose([]), [],
"No stalls, no acceptable choice"
);
});
test("1 stall", function(){
deepEqual(loo.choose([false]), [0],
"One empty stall, one obvious choice"
);
deepEqual(loo.choose([true]), [],
"One occuplied stall, no obvious choice"
);
});
test("3 stalls", function(){
deepEqual(loo.choose([false, false, false]),
[0, 1, 2],
"Three open stalls, three equal choices"
);
deepEqual(loo.choose([true, false, false]), [2],
"Two open stalls, one obvious choice"
);
deepEqual(loo.choose([false, true, false]), [0, 2],
"Two open stalls, two choices"
);
deepEqual(loo.choose([true, true, true]), [],
"Three occupied stalls, no choices"
);
});
module('loo.is_talking_allowed');
test("Is talking allowed?", function(){
deepEqual(loo.is_talking_allowed(), false,
"No, talking is not allowed."
);
});
});
</script>
</head>
<body>
<h1 id="qunit-header">
loo.js unit tests
</h1>
<h2 id="qunit-banner">
</h2>
<div id="qunit-testrunner-toolbar">
</div>
<h2 id="qunit-userAgent">
</h2>
<ol id="qunit-tests">
</ol>
<div id="qunit-fixture">
</div>
</body>
</html>