| ... | ... | @@ -121,27 +121,20 @@ pub fn SinglyLinkedList(comptime T: type) type { |
| 121 | 121 | } |
| 122 | 122 | |
| 123 | 123 | test "basic SinglyLinkedList test" { |
| 124 | | const allocator = testing.allocator; |
| 125 | | var list = SinglyLinkedList(u32).init(); |
| 124 | const L = SinglyLinkedList(u32); |
| 125 | var list = L{}; |
| 126 | 126 | |
| 127 | | var one = try list.createNode(1, allocator); |
| 128 | | var two = try list.createNode(2, allocator); |
| 129 | | var three = try list.createNode(3, allocator); |
| 130 | | var four = try list.createNode(4, allocator); |
| 131 | | var five = try list.createNode(5, allocator); |
| 132 | | defer { |
| 133 | | list.destroyNode(one, allocator); |
| 134 | | list.destroyNode(two, allocator); |
| 135 | | list.destroyNode(three, allocator); |
| 136 | | list.destroyNode(four, allocator); |
| 137 | | list.destroyNode(five, allocator); |
| 138 | | } |
| 127 | var one = L.Node{.data = 1}; |
| 128 | var two = L.Node{.data = 2}; |
| 129 | var three = L.Node{.data = 3}; |
| 130 | var four = L.Node{.data = 4}; |
| 131 | var five = L.Node{.data = 5}; |
| 139 | 132 | |
| 140 | | list.prepend(two); // {2} |
| 141 | | list.insertAfter(two, five); // {2, 5} |
| 142 | | list.prepend(one); // {1, 2, 5} |
| 143 | | list.insertAfter(two, three); // {1, 2, 3, 5} |
| 144 | | list.insertAfter(three, four); // {1, 2, 3, 4, 5} |
| 133 | list.prepend(&two); // {2} |
| 134 | two.insertAfter(&five); // {2, 5} |
| 135 | list.prepend(&one); // {1, 2, 5} |
| 136 | two.insertAfter(&three); // {1, 2, 3, 5} |
| 137 | three.insertAfter(&four); // {1, 2, 3, 4, 5} |
| 145 | 138 | |
| 146 | 139 | // Traverse forwards. |
| 147 | 140 | { |
| ... | ... | @@ -154,7 +147,7 @@ test "basic SinglyLinkedList test" { |
| 154 | 147 | } |
| 155 | 148 | |
| 156 | 149 | _ = list.popFirst(); // {2, 3, 4, 5} |
| 157 | | _ = list.remove(five); // {2, 3, 4} |
| 150 | _ = list.remove(&five); // {2, 3, 4} |
| 158 | 151 | _ = two.removeNext(); // {2, 4} |
| 159 | 152 | |
| 160 | 153 | testing.expect(list.first.?.data == 2); |