-
Notifications
You must be signed in to change notification settings - Fork 0
/
assert.ts
35 lines (35 loc) · 982 Bytes
/
assert.ts
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
class Assert {
static equals(v, e, m) {
if (v === e) Assert.passed(m);
else Assert.failed(m, e, v);
}
static contains(a, i, m) {
Assert.isFalse(a.indexOf(i) === -1, m);
}
static isFalse(v, m) {
Assert.equals(v, false, m);
}
static isTrue(v, m) {
Assert.equals(v, true, m);
}
static "throws"(fun, m, e) {
try {
fun();
Assert.failed(m, "an exception to be throw", "completed");
} catch (ex) {
if (e && ex !== e) {
Assert.failed(m, e, ex);
return;
}
Assert.passed(m);
}
}
static failed(m, e, v) {
document.writeln(`<span class="error">Failed</span>: ${m}; expected ${e} but was ${v}`);
}
static passed(m) {
document.writeln(`<span>Passed</span>: ${m}`);
}
}
var numbers = [1, 2, 3, 4, 1];
var objects = [{ x: 1 }, { x: 2 }, { x: 3 }, { x: 4 }, { x: 1 }];