forked from eighttrigrams/tsfun
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cond.spec.ts
69 lines (55 loc) · 1.39 KB
/
cond.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import {filter, map} from '../../src/associative'
import {cond, val} from '../../src/composition'
import {gt, includedIn, is} from '../../src/comparator'
import {identity} from '../../src/core'
/**
* tsfun | cond
*/
describe('cond', () => {
const times = (x: number) => (y: number) => x * y
it('cond', () =>
expect(
map(cond(
gt(3),
times(2),
val(18)))
({a: 3, b: 4, c: 5})
).toEqual({a: 18, b: 8, c: 10}))
it('pass through', () =>
expect(
map(cond(
gt(3),
times(2)))
([3, 4, 5])
).toEqual([3, 8, 10]))
it('boolean', () =>
expect(
map(cond(
true,
times(2)))
([3, 4, 5])
).toEqual([6, 8, 10]))
it('value', () =>
expect(
map(cond(
true,
0))
([3, 4, 5])
).toEqual([0, 0, 0]))
it('value on false', () =>
expect(
map(cond(
is(17),
identity,
3))
([17, 4, 5])
).toEqual([17, 3, 3]))
it('use with filter', () =>
expect(
filter(
cond(
includedIn([-2, 4]),
gt(0)))
([-2, 4, 5])
).toEqual([4, 5]))
})