diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2019-02-09 18:57:39 -0500 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2019-02-09 18:57:39 -0500 |
| commit | 1864acd32608ae917f8afc11b11f08a4bb362cef (patch) | |
| tree | d96b50a927fc67583d88c71822513594609621fb /std/hash_map.zig | |
| parent | 48c1e235cb620dacc30254d0898390b4d97f3e73 (diff) | |
| parent | ca8580ece1ab07215b72394cc4ab3030bf9df139 (diff) | |
| download | zig-1864acd32608ae917f8afc11b11f08a4bb362cef.tar.gz zig-1864acd32608ae917f8afc11b11f08a4bb362cef.zip | |
Merge remote-tracking branch 'origin/master' into llvm8
Diffstat (limited to 'std/hash_map.zig')
| -rw-r--r-- | std/hash_map.zig | 59 |
1 files changed, 30 insertions, 29 deletions
diff --git a/std/hash_map.zig b/std/hash_map.zig index a63a549814..716f04ff34 100644 --- a/std/hash_map.zig +++ b/std/hash_map.zig @@ -1,6 +1,7 @@ const std = @import("index.zig"); const debug = std.debug; const assert = debug.assert; +const testing = std.testing; const math = std.math; const mem = std.mem; const Allocator = mem.Allocator; @@ -342,37 +343,37 @@ test "basic hash map usage" { var map = AutoHashMap(i32, i32).init(&direct_allocator.allocator); defer map.deinit(); - assert((try map.put(1, 11)) == null); - assert((try map.put(2, 22)) == null); - assert((try map.put(3, 33)) == null); - assert((try map.put(4, 44)) == null); - assert((try map.put(5, 55)) == null); + testing.expect((try map.put(1, 11)) == null); + testing.expect((try map.put(2, 22)) == null); + testing.expect((try map.put(3, 33)) == null); + testing.expect((try map.put(4, 44)) == null); + testing.expect((try map.put(5, 55)) == null); - assert((try map.put(5, 66)).?.value == 55); - assert((try map.put(5, 55)).?.value == 66); + testing.expect((try map.put(5, 66)).?.value == 55); + testing.expect((try map.put(5, 55)).?.value == 66); const gop1 = try map.getOrPut(5); - assert(gop1.found_existing == true); - assert(gop1.kv.value == 55); + testing.expect(gop1.found_existing == true); + testing.expect(gop1.kv.value == 55); gop1.kv.value = 77; - assert(map.get(5).?.value == 77); + testing.expect(map.get(5).?.value == 77); const gop2 = try map.getOrPut(99); - assert(gop2.found_existing == false); + testing.expect(gop2.found_existing == false); gop2.kv.value = 42; - assert(map.get(99).?.value == 42); + testing.expect(map.get(99).?.value == 42); const gop3 = try map.getOrPutValue(5, 5); - assert(gop3.value == 77); + testing.expect(gop3.value == 77); const gop4 = try map.getOrPutValue(100, 41); - assert(gop4.value == 41); + testing.expect(gop4.value == 41); - assert(map.contains(2)); - assert(map.get(2).?.value == 22); + testing.expect(map.contains(2)); + testing.expect(map.get(2).?.value == 22); _ = map.remove(2); - assert(map.remove(2) == null); - assert(map.get(2) == null); + testing.expect(map.remove(2) == null); + testing.expect(map.get(2) == null); } test "iterator hash map" { @@ -382,9 +383,9 @@ test "iterator hash map" { var reset_map = AutoHashMap(i32, i32).init(&direct_allocator.allocator); defer reset_map.deinit(); - assert((try reset_map.put(1, 11)) == null); - assert((try reset_map.put(2, 22)) == null); - assert((try reset_map.put(3, 33)) == null); + testing.expect((try reset_map.put(1, 11)) == null); + testing.expect((try reset_map.put(2, 22)) == null); + testing.expect((try reset_map.put(3, 33)) == null); var keys = []i32{ 3, @@ -400,26 +401,26 @@ test "iterator hash map" { var it = reset_map.iterator(); var count: usize = 0; while (it.next()) |next| { - assert(next.key == keys[count]); - assert(next.value == values[count]); + testing.expect(next.key == keys[count]); + testing.expect(next.value == values[count]); count += 1; } - assert(count == 3); - assert(it.next() == null); + testing.expect(count == 3); + testing.expect(it.next() == null); it.reset(); count = 0; while (it.next()) |next| { - assert(next.key == keys[count]); - assert(next.value == values[count]); + testing.expect(next.key == keys[count]); + testing.expect(next.value == values[count]); count += 1; if (count == 2) break; } it.reset(); var entry = it.next().?; - assert(entry.key == keys[0]); - assert(entry.value == values[0]); + testing.expect(entry.key == keys[0]); + testing.expect(entry.value == values[0]); } pub fn getHashPtrAddrFn(comptime K: type) (fn (K) u32) { |
