diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2020-05-23 16:38:43 -0400 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2020-05-23 16:38:43 -0400 |
| commit | 8f6d7b32086c70164926e5bb95886e5bdf737bfd (patch) | |
| tree | 6733b4e803cf6a7bd1ef90e63ad318f0f26aeb8f /lib/std | |
| parent | 1a90a5e63adfd585836aee2658275c02856a4427 (diff) | |
| download | zig-8f6d7b32086c70164926e5bb95886e5bdf737bfd.tar.gz zig-8f6d7b32086c70164926e5bb95886e5bdf737bfd.zip | |
std: update singly linked list tests to new API
Diffstat (limited to 'lib/std')
| -rw-r--r-- | lib/std/linked_list.zig | 33 |
1 files changed, 13 insertions, 20 deletions
diff --git a/lib/std/linked_list.zig b/lib/std/linked_list.zig index c4c56df181..03520b0640 100644 --- a/lib/std/linked_list.zig +++ b/lib/std/linked_list.zig @@ -121,27 +121,20 @@ pub fn SinglyLinkedList(comptime T: type) type { } test "basic SinglyLinkedList test" { - const allocator = testing.allocator; - var list = SinglyLinkedList(u32).init(); + const L = SinglyLinkedList(u32); + var list = L{}; - var one = try list.createNode(1, allocator); - var two = try list.createNode(2, allocator); - var three = try list.createNode(3, allocator); - var four = try list.createNode(4, allocator); - var five = try list.createNode(5, allocator); - defer { - list.destroyNode(one, allocator); - list.destroyNode(two, allocator); - list.destroyNode(three, allocator); - list.destroyNode(four, allocator); - list.destroyNode(five, allocator); - } + var one = L.Node{.data = 1}; + var two = L.Node{.data = 2}; + var three = L.Node{.data = 3}; + var four = L.Node{.data = 4}; + var five = L.Node{.data = 5}; - list.prepend(two); // {2} - list.insertAfter(two, five); // {2, 5} - list.prepend(one); // {1, 2, 5} - list.insertAfter(two, three); // {1, 2, 3, 5} - list.insertAfter(three, four); // {1, 2, 3, 4, 5} + list.prepend(&two); // {2} + two.insertAfter(&five); // {2, 5} + list.prepend(&one); // {1, 2, 5} + two.insertAfter(&three); // {1, 2, 3, 5} + three.insertAfter(&four); // {1, 2, 3, 4, 5} // Traverse forwards. { @@ -154,7 +147,7 @@ test "basic SinglyLinkedList test" { } _ = list.popFirst(); // {2, 3, 4, 5} - _ = list.remove(five); // {2, 3, 4} + _ = list.remove(&five); // {2, 3, 4} _ = two.removeNext(); // {2, 4} testing.expect(list.first.?.data == 2); |
