-
Notifications
You must be signed in to change notification settings - Fork 0
/
progvm.test.ts
51 lines (45 loc) · 1.33 KB
/
progvm.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
import { equal, notEqual, ok } from 'node:assert/strict'
import { describe, it } from 'node:test'
import { firstValueFrom } from 'rxjs'
import { ProgVm, BaseSpeed, SpeedMultiplier } from './progvm.js'
describe('ProgVm', () => {
it('pauses', async () => {
const prog = new ProgVm()
prog.pause()
const paused = await firstValueFrom(prog.paused)
equal(paused, true)
})
it('unpauses', async () => {
const prog = new ProgVm()
prog.pause()
prog.unpause()
const paused = await firstValueFrom(prog.paused)
equal(paused, false)
})
it('speeds up', async () => {
const prog = new ProgVm()
prog.speedUp()
const perTick = await firstValueFrom(prog.perTick)
equal(perTick, BaseSpeed * SpeedMultiplier)
})
it('slows down', async () => {
const prog = new ProgVm()
prog.slowDown()
const perTick = await firstValueFrom(prog.perTick)
equal(perTick, BaseSpeed / SpeedMultiplier)
})
it('finishes', async () => {
const prog = new ProgVm()
prog.finish()
const percent = await firstValueFrom(prog.percent)
equal(percent, 1)
})
it('ticks forward', async () => {
const prog = new ProgVm()
const start = await firstValueFrom(prog.percent)
await prog.tick()
const end = await firstValueFrom(prog.percent)
notEqual(start, end)
ok(end > start)
})
})