deno.land / x / rambda@v9.1.1 / source / unapply.spec.js

unapply.spec.js
نووسراو ببینە
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import { apply } from './apply.js'import { converge } from './converge.js'import { identity } from './identity.js'import { prop } from './prop.js'import { sum } from './sum.js'import { unapply } from './unapply.js'
test('happy', () => { const fn = unapply(identity) expect(fn( 1, 2, 3 )).toEqual([ 1, 2, 3 ]) expect(fn()).toEqual([])})
test('returns a function which is always passed one argument', () => { const fn = unapply(function (){ return arguments.length }) expect(fn('x')).toBe(1) expect(fn('x', 'y')).toBe(1) expect(fn( 'x', 'y', 'z' )).toBe(1)})
test('forwards arguments to decorated function as an array', () => { const fn = unapply(xs => '[' + xs + ']') expect(fn(2)).toBe('[2]') expect(fn(2, 4)).toBe('[2,4]') expect(fn( 2, 4, 6 )).toBe('[2,4,6]')})
test('returns a function with length 0', () => { const fn = unapply(identity) expect(fn).toHaveLength(0)})
test('is the inverse of R.apply', () => { let a, b, c, d, e, f, g, n const rand = function (){ return Math.floor(200 * Math.random()) - 100 }
f = Math.max g = unapply(apply(f)) n = 1 while (n <= 100){ a = rand() b = rand() c = rand() d = rand() e = rand() expect(f( a, b, c, d, e )).toEqual(g( a, b, c, d, e )) n += 1 }
f = function (xs){ return '[' + xs + ']' } g = apply(unapply(f)) n = 1 while (n <= 100){ a = rand() b = rand() c = rand() d = rand() e = rand() expect(f([ a, b, c, d, e ])).toEqual(g([ a, b, c, d, e ])) n += 1 }})
test('it works with converge', () => { const fn = unapply(sum) const convergeFn = converge(fn, [ prop('a'), prop('b'), prop('c') ]) const obj = { a : 1337, b : 42, c : 1, } const expected = 1337 + 42 + 1 expect(convergeFn(obj)).toEqual(expected)})
rambda

Version Info

Tagged at
2 months ago