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

groupWith.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
import { equals } from './equals.js'import { groupWith } from './groupWith.js'
test('issue is fixed', () => { const result = groupWith(equals, [ 1, 2, 2, 3 ]) const expected = [ [ 1 ], [ 2, 2 ], [ 3 ] ] expect(result).toEqual(expected)})
test('long list', () => { const result = groupWith(equals, [ 0, 1, 1, 2, 3, 5, 8, 13, 21, 21, 21, 1, 2 ])
const expected = [ [ 0 ], [ 1, 1 ], [ 2 ], [ 3 ], [ 5 ], [ 8 ], [ 13 ], [ 21, 21, 21 ], [ 1 ], [ 2 ], ] expect(result).toEqual(expected)})
test('readme example', () => { const list = [ 4, 3, 6, 2, 2, 1 ]
const result = groupWith((a, b) => a - b === 1, list) const expected = [ [ 4, 3 ], [ 6 ], [ 2 ], [ 2, 1 ] ] expect(result).toEqual(expected)})
test('throw with string as input', () => { expect(() => groupWith(equals, 'Mississippi')).toThrowErrorMatchingInlineSnapshot('"list.reduce is not a function"')})
const isConsecutive = function (a, b){ return a + 1 === b}
test('fix coverage', () => { expect(groupWith(isConsecutive, [ 1, 2, 3, 0 ])).toEqual([ [ 1, 2, 3 ], [ 0 ] ])})
test('from ramda 0', () => { expect(groupWith(equals, [])).toEqual([]) expect(groupWith(isConsecutive, [])).toEqual([])})
test('from ramda 1', () => { expect(groupWith(isConsecutive, [ 4, 3, 2, 1 ])).toEqual([ [ 4 ], [ 3 ], [ 2 ], [ 1 ], ])})
test('from ramda 2', () => { expect(groupWith(isConsecutive, [ 1, 2, 3, 4 ])).toEqual([ [ 1, 2, 3, 4 ] ])})
test('from ramda 3', () => { expect(groupWith(isConsecutive, [ 1, 2, 2, 3 ])).toEqual([ [ 1, 2 ], [ 2, 3 ], ]) expect(groupWith(isConsecutive, [ 1, 2, 9, 3, 4 ])).toEqual([ [ 1, 2 ], [ 9 ], [ 3, 4 ], ])})
test('list with single item', () => { const result = groupWith(equals, [ 0 ])
const expected = [ [ 0 ] ] expect(result).toEqual(expected)})
rambda

Version Info

Tagged at
2 months ago