-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.js
51 lines (42 loc) · 1.28 KB
/
tests.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
module.exports = new(function() {
this.cases = [{
'set': [1, 99, -5, 878, 2, 7, 3, 9, -1],
'solution': [-5, -1, 1, 2, 3, 7, 9, 99, 878]
},
{
'set': [],
'solution': []
},
{
'set': [1, 2, 3, 4, 5],
'solution': [1, 2, 3, 4, 5]
},
{
'set': [0],
'solution': [0]
}
]
this.check = function(set, solution) {
for (var i = 0; i < set.length; i++) {
if (set[i] !== solution[i]) {
return false
}
}
return true
}
this.run = function(fn) {
for (var i = 0; i < this.cases.length; i++) {
var deepCopy = []
for (var j = 0; j < this.cases[i].set.length; j++) {
deepCopy[j] = this.cases[i].set[j]
}
var candidate = fn(deepCopy)
if (this.check(deepCopy, this.cases[i].solution)) {
console.log('Case" `' + JSON.stringify(this.cases[i].set) + '` => passed')
} else {
console.warn('\nCase" `' + JSON.stringify(this.cases[i].set) + '` => did not pass')
console.warn('Err: `' + JSON.stringify(candidate) + '`\n')
}
}
}
})()