UNPKG

904 BJavaScriptView Raw
1const test = require('./config').test
2const { scan } = require('..')
3
4test('scan over single callback output', t => {
5 const reducer = (acc, x) => acc + x
6 const initState = 10
7 const cpsFun = cb => cb(42)
8 t.plan(1)
9 scan(reducer)(initState)(cpsFun)(t.cis(52))
10})
11
12test('scan over single repeated callback output', t => {
13 let called = false
14 const reducer = (acc, x) => acc + x
15 const initState = 10
16 const cpsFun = cb => { cb(2); cb(8) }
17 const newCps = scan(reducer)(initState)(cpsFun)
18
19 // called twice with
20 // 12 = 10 + 2 and 20 = 10 + 2 + 8 as outputs
21 t.plan(2)
22 newCps(res => {
23 t.cis(called ? 20 : 12)(res)
24 called = true
25 })
26})
27
28test('scan over outputs from 2 callbacks', t => {
29 const r = (acc, x) => acc + x
30 const cpsFun = (cb1, cb2) => cb1(2) + cb2(3)
31 const newCps = scan(r, r)(10, 11)(cpsFun)
32
33 // called with 12 = 10 + 2 and 14 = 11 + 3
34 t.plan(2)
35 newCps(t.cis(12), t.cis(14))
36})