-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestingFrameWork.js
More file actions
41 lines (33 loc) · 840 Bytes
/
testingFrameWork.js
File metadata and controls
41 lines (33 loc) · 840 Bytes
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
const add = function (a, b) {
return a + b;
};
const sub = function (a, b) {
return a - b;
};
const areEqual = function (array1, array2) {
if (array1.length !== array2.length) {
return false;
}
for (let index = 0; index < array1.length; index++) {
if (array1[index] !== array2[index]) {
return false;
}
}
return true;
}
function testAll([funsName, parameters, expected]) {
const failed = [];
const actual = funsName(parameters[0], parameters[1]);
if (actual !== expected) {
failed.push([funsName, parameters, expected, actual]);
console.table(failed);
}
}
function allTestCases() {
testAll([add, [2, 3], 5]);
testAll([add, [0, 3], 5]);
testAll([sub, [0, 2], 4]);
testAll([areEqual, [[1, 2], [1, 3]], false]);
testAll([areEqual, [[1, 2], [1, 3]], true]);
}
allTestCases();