/
test.js
240 lines (221 loc) · 5.94 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
'use strict';
const test = require('modunit');
const isExactly = require('./index');
test('it returns false when given undefined and a number', (t, number) => {
t.assert.false(isExactly(undefined, number));
}, [
[3], [4], [10], [20], [Infinity]
]);
test('it returns false when given undefined and a string', (t, string) => {
t.assert.false(isExactly(undefined, string));
}, [
['james'], ['bob'], ['cats'], ['apples'], ['cheese and melon']
]);
test('it returns false when given null and a number', (t, number) => {
t.assert.false(isExactly(null, number));
}, [
[3], [4], [10], [20], [Infinity]
]);
test('it returns false when given null and a string', (t, string) => {
t.assert.false(isExactly(null, string));
}, [
['james'], ['bob'], ['cats'], ['apples'], ['cheese and melon']
]);
test('it returns true when given the same number twice', (t, value) => {
t.assert.true(isExactly(value, value));
}, [
[3], [4], [10], [20], [Infinity]
]);
test('it returns true when given the same string twice', (t, value) => {
t.assert.true(isExactly(value, value));
}, [
['james'], ['bob'], ['cats'], ['apples'], ['cheese and melon']
]);
test('it returns true when given the same string but concatenated', (t, value, other) => {
t.assert.true(isExactly(value, other));
}, [
['james', ('j' + 'a' + 'mes')],
['bob', ('b' + 'o' + 'b')],
['cats', ('c' + 'at' + 's')],
['apples', ('a' + 'pp' + 'le' + 's')],
['cheese and melon', 'cheese ' + 'and' + ' melon']
]);
test('it returns true when given the same boolean twice', (t, value) => {
t.assert.true(isExactly(value, value));
}, [
[true], [false]
]);
test('it returns true when given null twice', t => {
t.assert.true(isExactly(null, null));
});
test('it returns true when given undefined twice', t => {
t.assert.true(isExactly(undefined, undefined));
});
test('it returns false when given the same number but stringified', (t, value, other) => {
t.assert.false(isExactly(value, other));
}, [
[3, '3'],
[4, '4'],
[10, '10'],
[20, '20'],
[Infinity, 'Infinity']
]);
test('it returns true when given the same object twice', (t, value) => {
t.assert.true(isExactly(value, value));
}, [
[{ a : [ 2, 3 ], b : [ 4 ] }],
[{ name: 'James', country: 'UK' }],
[{ name: 'apple', flavour: 'fruity' }],
[{ species: 'cat', texture: 'furry' }]
]);
test('it returns false for objects with different keys, same count', (t, value, other) => {
t.assert.false(isExactly(value, other));
}, [
[ { a: 1, b: 2 }, { a: 1, c: 2 } ],
[ { name: 'james', age: 15 }, { name: 'james', height: 170 } ],
[ { fruit: 'apple', color: 'green' }, { fruit: 'grapefruit', size: 'large' } ]
]);
test('it returns false for objects with different key count', (t, value, other) => {
t.assert.false(isExactly(value, other));
}, [
[ { a: 1, b: 2 }, { a: 1 } ],
[ { name: 'james', age: 15 }, { name: 'james' } ],
[ { fruit: 'apple', color: 'green' }, { fruit: 'grapefruit' } ]
]);
test('it returns false for objects with same level 1, different level 2', (t, value, other) => {
t.assert.false(isExactly(value, other));
}, [
[
{
name: 'james',
birthday: {
month: 9,
day: 17
}
},
{
name: 'james',
birthday: {
month: 10,
day: 15
}
}
],
[
{
car: {
make: 'Citroen',
model: 'Saxo'
},
color: 'red'
},
{
car: {
make: 'Peugeot',
model: '106'
},
color: 'blue'
}
]
]);
test('it returns true for objects with same level 1, same level 2', (t, value) => {
t.assert.true(isExactly(value, value));
}, [
[
{
name: 'james',
birthday: {
month: 9,
day: 17
}
}
],
[
{
car: {
make: 'Citroen',
model: 'Saxo'
},
color: 'red'
}
]
]);
test('it returns false for objects with same level 1, same level 2, different level 3', (t, value, other) => {
t.assert.false(isExactly(value, other));
}, [
[
{
name: 'james',
birthday: {
month: 9,
day: 17,
time: {
hours: 15,
minutes: 30
}
}
},
{
name: 'james',
birthday: {
month: 9,
day: 17,
time: {
hours: 20,
minutes: 0
}
}
}
],
[
{
car: {
make: 'Citroen',
model: 'Saxo',
engine: {
displacement: '1600'
}
},
color: 'red'
},
{
car: {
make: 'Peugeot',
model: '106',
engine: {
displacement: '1400'
}
},
color: 'blue'
}
]
]);
test('it returns true for objects with same level 1, same level 2, same level 3', (t, value) => {
t.assert.true(isExactly(value, value));
}, [
[
{
name: 'james',
birthday: {
month: 9,
day: 17,
time: {
hours: 15,
minutes: 30
}
}
}
],
[
{
car: {
make: 'Citroen',
model: 'Saxo',
engine: {
displacement: '1600'
}
},
color: 'red'
}
]
]);