-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrunTest.js
More file actions
35 lines (33 loc) · 951 Bytes
/
runTest.js
File metadata and controls
35 lines (33 loc) · 951 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
function assertEqual(actual, expected, message) {
if (JSON.stringify(actual) === JSON.stringify(expected)) {
console.log(`✔ ${message}`);
} else {
console.error(`✘ ${message}`);
console.error(` Expected: ${JSON.stringify(expected)}`);
console.error(` Actual: ${JSON.stringify(actual)}`);
}
}
function runSortTest(sortingFunction) {
assertEqual(
sortingFunction([5, 3, 8, 4, 2]),
[2, 3, 4, 5, 8],
"Test Case 1: Sorts an array of numbers"
);
assertEqual(
sortingFunction([1, 2, 3, 4, 5]),
[1, 2, 3, 4, 5],
"Test Case 2: Returns an already sorted array"
);
assertEqual(sortingFunction([]), [], "Test Case 3: Handles an empty array");
assertEqual(
sortingFunction([1]),
[1],
"Test Case 4: Handles an array with one element"
);
assertEqual(
sortingFunction([4, 2, 2, 8, 5, 3]),
[2, 2, 3, 4, 5, 8],
"Test Case 5: Sorts an array with duplicate elements"
);
}
module.exports = { runSortTest, assertEqual };