-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimer.spec.ts
52 lines (49 loc) · 1.58 KB
/
timer.spec.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
import { Timer, Time, setTime, time, wait } from './timer';
import { Tree } from './tree';
import { Outputs } from './outputs';
describe('Timer', () => {
test('time should trigger outputs', async () => {
await setTime();
const obj = new class extends Tree<{time: number}> {
constructor() {
super();
this.makeRoot();
this.out = new Outputs(this, {
time: () => time(),
});
}
};
const a = obj.out!.treeValues.time;
await wait(10);
expect(obj.out!.treeValues.time).toBeGreaterThan(a);
});
describe('addToQueue', () => {
beforeEach(() => {
Timer.queue = [
{ time: 2 },
{ time: 4 },
{ time: 6 },
] as any;
});
test('1', () => {
const e = Timer.schedule(() => 0, 1 as Time);
expect(Timer.queue.indexOf(e)).toBe(0);
});
test('2', () => {
const e = Timer.schedule(() => 0, 2 as Time);
expect(Timer.queue.indexOf(e)).toBe(0);
});
test('3', () => {
const e = Timer.schedule(() => 0, 3 as Time);
expect(Timer.queue.indexOf(e)).toBe(1);
});
test('4', () => {
const e = Timer.schedule(() => 0, 4 as Time);
expect(Timer.queue.indexOf(e)).toBe(1);
});
test('7', () => {
const e = Timer.schedule(() => 0, 7 as Time);
expect(Timer.queue.indexOf(e)).toBe(3);
});
});
});