authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-05-23 16:38:43-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-05-23 16:38:43-04:00
log8f6d7b32086c70164926e5bb95886e5bdf737bfd
tree6733b4e803cf6a7bd1ef90e63ad318f0f26aeb8f
parent1a90a5e63adfd585836aee2658275c02856a4427

std: update singly linked list tests to new API


1 files changed, 13 insertions(+), 20 deletions(-)

lib/std/linked_list.zig+13-20
...@@ -121,27 +121,20 @@ pub fn SinglyLinkedList(comptime T: type) type {...@@ -121,27 +121,20 @@ pub fn SinglyLinkedList(comptime T: type) type {
121}121}
122122
123test "basic SinglyLinkedList test" {123test "basic SinglyLinkedList test" {
124 const allocator = testing.allocator;124 const L = SinglyLinkedList(u32);
125 var list = SinglyLinkedList(u32).init();125 var list = L{};
126126
127 var one = try list.createNode(1, allocator);127 var one = L.Node{.data = 1};
128 var two = try list.createNode(2, allocator);128 var two = L.Node{.data = 2};
129 var three = try list.createNode(3, allocator);129 var three = L.Node{.data = 3};
130 var four = try list.createNode(4, allocator);130 var four = L.Node{.data = 4};
131 var five = try list.createNode(5, allocator);131 var five = L.Node{.data = 5};
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 }
139132
140 list.prepend(two); // {2}133 list.prepend(&two); // {2}
141 list.insertAfter(two, five); // {2, 5}134 two.insertAfter(&five); // {2, 5}
142 list.prepend(one); // {1, 2, 5}135 list.prepend(&one); // {1, 2, 5}
143 list.insertAfter(two, three); // {1, 2, 3, 5}136 two.insertAfter(&three); // {1, 2, 3, 5}
144 list.insertAfter(three, four); // {1, 2, 3, 4, 5}137 three.insertAfter(&four); // {1, 2, 3, 4, 5}
145138
146 // Traverse forwards.139 // Traverse forwards.
147 {140 {
...@@ -154,7 +147,7 @@ test "basic SinglyLinkedList test" {...@@ -154,7 +147,7 @@ test "basic SinglyLinkedList test" {
154 }147 }
155148
156 _ = list.popFirst(); // {2, 3, 4, 5}149 _ = list.popFirst(); // {2, 3, 4, 5}
157 _ = list.remove(five); // {2, 3, 4}150 _ = list.remove(&five); // {2, 3, 4}
158 _ = two.removeNext(); // {2, 4}151 _ = two.removeNext(); // {2, 4}
159152
160 testing.expect(list.first.?.data == 2);153 testing.expect(list.first.?.data == 2);