-
Notifications
You must be signed in to change notification settings - Fork 3
/
cmp.test.ts
62 lines (52 loc) · 2.03 KB
/
cmp.test.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
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
import { cmp } from '../../';
// cmp(v1, comparator, v2): Pass in a comparison string, and it'll call the
// corresponding function above. "===" and "!==" do simple string comparison,
// but are included for completeness.
// Throws if an invalid comparison string is provided.
describe('test cmp', () => {
it('cmp(v1, ">", v2)', () => {
expect(cmp('2', '>', '1')).toBeTruthy();
expect(cmp('2', '>', '2')).toBeFalsy();
expect(cmp('1', '>', '2')).toBeFalsy();
});
it('cmp(v1, ">=", v2)', () => {
expect(cmp('2', '>=', '1')).toBeTruthy();
expect(cmp('2', '>=', '2')).toBeTruthy();
expect(cmp('1', '>=', '2')).toBeFalsy();
});
it('cmp(v1, "<", v2)', () => {
expect(cmp('1', '<', '2')).toBeTruthy();
expect(cmp('2', '<', '2')).toBeFalsy();
expect(cmp('2', '<', '1')).toBeFalsy();
});
it('cmp(v1, "<=", v2)', () => {
expect(cmp('1', '<=', '2')).toBeTruthy();
expect(cmp('2', '<=', '2')).toBeTruthy();
expect(cmp('2', '<=', '1')).toBeFalsy();
});
it('cmp(v1, "==", v2)', () => {
expect(cmp('2', '==', '2')).toBeTruthy();
expect(cmp('2', '==', '2.0')).toBeTruthy();
expect(cmp('2', '==', '1')).toBeFalsy();
});
it('cmp(v1, "!=", v2)', () => {
expect(cmp('2', '!=', '1')).toBeTruthy();
expect(cmp('2', '!=', '2')).toBeFalsy();
expect(cmp('2', '!=', '2.0')).toBeFalsy();
});
it('cmp(v1, "===", v2)', () => {
expect(cmp('2', '===', '2')).toBeTruthy();
expect(cmp('2', '===', '1')).toBeFalsy();
expect(cmp('2', '===', '2.0')).toBeFalsy();
});
it('cmp(v1, "!==", v2)', () => {
expect(cmp('2', '!==', '2')).toBeFalsy();
expect(cmp('2', '!==', '2.0')).toBeTruthy();
expect(cmp('2', '!==', '1')).toBeTruthy();
});
it('cmp(v1, "nonsense", v2)', () => {
expect(() => {cmp('2', 'nonsense', '2')}).toThrow(new Error('Invalid comparator: nonsense'));
expect(() => {cmp('2', '!====', '2')}).toThrow(new Error('Invalid comparator: !===='));
expect(() => {cmp('2', '>broken', '2')}).toThrow(new Error('Invalid comparator: >broken'));
});
});