-
Notifications
You must be signed in to change notification settings - Fork 16
/
simple-tests.js
54 lines (40 loc) · 1.26 KB
/
simple-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
52
53
54
var SinglyLinkedList = require('./singly-linked-list.js');
/* LinkedList initialization */
var LinkedList = new SinglyLinkedList();
/* We're creating our "base" linkedList */
for (var i=2; i<15; i=i+2){
LinkedList.append(i);
}
// check insertAtHead method
LinkedList.prepend("Breakfast Burrito");
/* print */
console.log("\nBefore:");
LinkedList.print();
/* Run your functions here */
// Insert functions here to test.
/* Print again to see your results */
// check length method
var length = LinkedList.length();
console.log(" Length: " + length + " (expected 8)");
// check exists method
var foundData = LinkedList.exists(12);
console.log(" Does 12 exist in our list: " + foundData + " (expected true)");
// check indexOf methodd
var indexOfSix = LinkedList.indexOf(6);
console.log(" Index of six: " + indexOfSix + " (expected 3)");
// check insertAt method
LinkedList.insertAt(3, 'Bertha');
console.log("\nInserted Bertha at 3:");
LinkedList.print();
// check delete methodd
LinkedList.delete(10);
console.log("\nDeleted 10:");
LinkedList.print();
// check each method
function accessor(node) {
console.log(" " + node.data + " has been accessed.")
}
console.log('\nAccessing each node:');
LinkedList.each(accessor);
console.log("\nAfter:");
LinkedList.print();