-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.test.js
43 lines (37 loc) · 991 Bytes
/
index.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
const {printHeap, printHeapPerformant} = require('.');
test('should console the two min values of the array with a time complexity of O(n2)', () => {
const old = console.log;
console.log = jest.fn();
// Arrange
const data = "" +
"5-" +
"1 4-" +
"1 9-" +
"3-" +
"2 4-" +
"3";
// Act
printHeap(data);
// Assert
expect(console.log.mock.calls.length).toEqual(2);
expect(console.log.mock.calls[0][0]).toEqual("4");
expect(console.log.mock.calls[1][0]).toEqual("9");
});
test('should console the two min values of the array with a time complexity of O(n)', () => {
const old = console.log;
console.log = jest.fn();
// Arrange
const data = "" +
"5-" +
"1 4-" +
"1 9-" +
"3-" +
"2 4-" +
"3";
// Act
printHeapPerformant(data);
// Assert
expect(console.log.mock.calls.length).toEqual(2);
expect(console.log.mock.calls[0][0]).toEqual("4");
expect(console.log.mock.calls[1][0]).toEqual("9");
});