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

collectBy.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
import fc from 'fast-check'import { all, compose, difference, equals, head, identity, is, isEmpty, length, uniq, unnest,} from 'rambdax'
import { collectBy } from './collectBy.js'
test('returns a list of lists', () => { fc.assert(fc.property(fc.array(fc.nat()), xs => { const check = all(is(Array)) const ys = collectBy(identity)(xs)
return check(ys) }))})
test('groups items but neither adds new ones nor removes any', () => { fc.assert(fc.property(fc.array(fc.nat()), xs => { const check = compose( isEmpty, difference(xs), unnest ) const ys = collectBy(identity)(xs)
return check(ys) }))})
test('groups related items together', () => { fc.assert(fc.property(fc.array(fc.boolean()), xs => { const ys = collectBy(identity)(xs) const check = all(compose( equals(1), length, uniq ))
return check(ys) }))})
test('invokes the tag function for each item in the list', () => { fc.assert(fc.property(fc.array(fc.nat()), xs => { const id = jest.fn(x => 42) collectBy(id)(xs) const check = compose(isEmpty, difference(xs))
return check(id.mock.calls.map(call => call[ 0 ])) }))})
test('groups items according to the tag value', () => { fc.assert(fc.property(fc.array(fc.nat()), xs => { const ys = collectBy(x => 42)(xs) const check = compose( isEmpty, difference(xs), head )
return isEmpty(xs) && isEmpty(ys) ? true : check(ys) }))})
rambda

Version Info

Tagged at
2 months ago