| ... | ... | @@ -473,46 +473,53 @@ test "iterator hash map" { |
| 473 | 473 | var reset_map = AutoHashMap(i32, i32).init(std.testing.allocator); |
| 474 | 474 | defer reset_map.deinit(); |
| 475 | 475 | |
| 476 | | try reset_map.putNoClobber(1, 11); |
| 477 | | try reset_map.putNoClobber(2, 22); |
| 478 | | try reset_map.putNoClobber(3, 33); |
| 476 | try reset_map.putNoClobber(0, 11); |
| 477 | try reset_map.putNoClobber(1, 22); |
| 478 | try reset_map.putNoClobber(2, 33); |
| 479 | 479 | |
| 480 | | // TODO this test depends on the hashing algorithm, because it assumes the |
| 481 | | // order of the elements in the hashmap. This should not be the case. |
| 482 | 480 | var keys = [_]i32{ |
| 483 | | 1, |
| 484 | | 3, |
| 485 | | 2, |
| 481 | 0, 2, 1, |
| 486 | 482 | }; |
| 483 | |
| 487 | 484 | var values = [_]i32{ |
| 488 | | 11, |
| 489 | | 33, |
| 490 | | 22, |
| 485 | 11, 33, 22, |
| 486 | }; |
| 487 | |
| 488 | var buffer = [_]i32{ |
| 489 | 0, 0, 0, |
| 491 | 490 | }; |
| 492 | 491 | |
| 493 | 492 | var it = reset_map.iterator(); |
| 493 | const first_entry = it.next().?; |
| 494 | it.reset(); |
| 495 | |
| 494 | 496 | var count: usize = 0; |
| 495 | | while (it.next()) |next| { |
| 496 | | testing.expect(next.key == keys[count]); |
| 497 | | testing.expect(next.value == values[count]); |
| 498 | | count += 1; |
| 497 | while (it.next()) |kv| : (count += 1) { |
| 498 | buffer[@intCast(usize, kv.key)] = kv.value; |
| 499 | 499 | } |
| 500 | | |
| 501 | 500 | testing.expect(count == 3); |
| 502 | 501 | testing.expect(it.next() == null); |
| 502 | |
| 503 | for (buffer) |v, i| { |
| 504 | testing.expect(buffer[@intCast(usize, keys[i])] == values[i]); |
| 505 | } |
| 506 | |
| 503 | 507 | it.reset(); |
| 504 | 508 | count = 0; |
| 505 | | while (it.next()) |next| { |
| 506 | | testing.expect(next.key == keys[count]); |
| 507 | | testing.expect(next.value == values[count]); |
| 509 | while (it.next()) |kv| { |
| 510 | buffer[@intCast(usize, kv.key)] = kv.value; |
| 508 | 511 | count += 1; |
| 509 | | if (count == 2) break; |
| 512 | if (count >= 2) break; |
| 513 | } |
| 514 | |
| 515 | for (buffer[0..2]) |v, i| { |
| 516 | testing.expect(buffer[@intCast(usize, keys[i])] == values[i]); |
| 510 | 517 | } |
| 511 | 518 | |
| 512 | 519 | it.reset(); |
| 513 | 520 | var entry = it.next().?; |
| 514 | | testing.expect(entry.key == keys[0]); |
| 515 | | testing.expect(entry.value == values[0]); |
| 521 | testing.expect(entry.key == first_entry.key); |
| 522 | testing.expect(entry.value == first_entry.value); |
| 516 | 523 | } |
| 517 | 524 | |
| 518 | 525 | test "ensure capacity" { |