-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
111 lines (96 loc) · 2.96 KB
/
test.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import test from 'mvt'
import levenSort from './index.js'
test(`sorts simple text array`, (assert) => {
const sourceName = 'Bill Griffin'
const nameAry = [
'Carl Martinez',
'Roger Davis',
'William George',
null,
'Andrew Torres',
'Billy Campbell',
'Alan King',
'Benjamin Wilson',
'Bill Griffin',
'Dennis Smith',
'Billy Griffith'
]
const expect = [
'Bill Griffin',
'Billy Griffith',
'Billy Campbell',
'Carl Martinez',
'William George',
'Roger Davis',
'Benjamin Wilson',
'Dennis Smith',
'Andrew Torres',
'Alan King',
null
]
const levSorted = levenSort(nameAry, sourceName)
assert.deepEqual(levSorted, expect)
})
test(`sorts array of objects, with secondary sort`, (assert) => {
const sourceFirst = 'Bill'
const sourceLast = 'Griffin'
const nameObjAry = [
{ first: 'Carl', last: 'Martinez' },
{ first: 'Roger', last: 'Davis' },
{ first: 'William', last: 'George' },
{ first: 'Andrew', last: 'Torres' },
{ first: 'Billy', last: 'Campbell' },
{ first: null, last: null },
{ first: 'Alan', last: 'King' },
{ first: 'Benjamin', last: 'Wilson' },
{ first: 'Bill', last: 'Griffin' },
{ first: 'Dennis', last: 'Smith' },
{ first: 'Billy', last: 'Griffith' }
]
const expect = [
{ first: 'Bill', last: 'Griffin' },
{ first: 'Billy', last: 'Griffith' },
{ first: 'Billy', last: 'Campbell' },
{ first: 'William', last: 'George' },
{ first: 'Dennis', last: 'Smith' },
{ first: 'Carl', last: 'Martinez' },
{ first: 'Benjamin', last: 'Wilson' },
{ first: 'Roger', last: 'Davis' },
{ first: 'Andrew', last: 'Torres' },
{ first: 'Alan', last: 'King' },
{ first: null, last: null }
]
const levSorted = levenSort(nameObjAry, sourceFirst, 'first', sourceLast, 'last')
assert.deepEqual(levSorted, expect)
})
test(`sorts array of objects by multiple keys`, (assert) => {
const source = 'Bill'
const nameObjAry = [
{ first: 'Carl', last: 'Martinez' },
{ first: 'Roger', last: 'Davis' },
{ first: 'William', last: 'George' },
{ first: 'Andrew', last: 'Torres' },
{ first: 'Billy', last: 'Campbell' },
{ first: 'Alan', last: 'King' },
{ first: null, last: null },
{ first: 'Benjamin', last: 'Wilson' },
{ first: 'Bill', last: 'Griffin' },
{ first: 'Dennis', last: 'Smith' },
{ first: 'Billy', last: 'Griffith' }
]
const expect = [
{ first: 'Bill', last: 'Griffin' },
{ first: 'Billy', last: 'Campbell' },
{ first: 'Billy', last: 'Griffith' },
{ first: 'William', last: 'George' },
{ first: 'Benjamin', last: 'Wilson' },
{ first: 'Carl', last: 'Martinez' },
{ first: 'Roger', last: 'Davis' },
{ first: 'Alan', last: 'King' },
{ first: 'Dennis', last: 'Smith' },
{ first: 'Andrew', last: 'Torres' },
{ first: null, last: null }
]
const levSorted = levenSort(nameObjAry, source, ['first', 'last'])
assert.deepEqual(levSorted, expect)
})