forked from indiesquidge/javascript-challenges
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathobject-diff-test.js
115 lines (96 loc) · 2.09 KB
/
object-diff-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
112
113
114
115
const test = require('tape')
const diff = require('./object-diff')
test('it calculates the diff of shallow object properties', assert => {
const newCode = {
apples: 3,
oranges: 4
}
const oldCode = {
apples: 3,
grapes: 5
}
const objectDiff = [
['-', 'grapes', 5],
['+', 'oranges', 4]
]
assert.deepEqual(diff(newCode, oldCode), objectDiff)
assert.equal(diff(newCode, oldCode).length, 2)
assert.end()
})
test.skip('it calculates the diff of nested object properties', assert => {
const newCode = {
apples: 3,
oranges: {
navel: 5
}
}
const oldCode = {
apples: 3,
oranges: {
valencia: 4
}
}
const objectDiff = [
['-', 'oranges.valencia', 4],
['+', 'oranges.navel', 5]
]
assert.deepEqual(diff(newCode, oldCode), objectDiff)
assert.equal(diff(newCode, oldCode).length, 2)
assert.end()
})
test.skip('it calculates the diff of doubly nested object properties', assert => {
const newCode = {
apples: 3,
oranges: {
bergamot: 3,
navel: {
peaches: 1,
apples: 3
}
}
}
const oldCode = {
apples: 3,
oranges: {
bergamot: 3,
valencia: {
pears: 2,
oranges: 4
}
}
}
const objectDiff = [
[ '-', 'oranges.valencia.pears', 2 ],
[ '-', 'oranges.valencia.oranges', 4 ],
[ '+', 'oranges.navel.peaches', 1 ],
[ '+', 'oranges.navel.apples', 3 ]
]
assert.deepEqual(diff(newCode, oldCode), objectDiff)
assert.equal(diff(newCode, oldCode).length, 4)
assert.end()
})
test.skip('it calculates the diff of diference sized objects', assert => {
const newCode = {
apples: 3,
oranges: 5
}
const oldCode = {
apples: 3,
oranges: {
bergamot: 3,
valencia: {
pears: 2,
oranges: 4
}
}
}
const objectDiff = [
['-', 'oranges.bergamot', 3],
['-', 'oranges.valencia.pears', 2],
['-', 'oranges.valencia.oranges', 4],
['+', 'oranges', 5]
]
assert.deepEqual(diff(newCode, oldCode), objectDiff)
assert.equal(diff(newCode, oldCode).length, 4)
assert.end()
})