From 4eb95d020075344101a058024d31101a9781d8dd Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Thu, 9 Apr 2026 05:05:08 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=AA=20[Testing=20Improvement]=20Add=20?= =?UTF-8?q?explicit=20test=20for=20HashMap=20resize=20logic=20boundary?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Addresses the missing test for HashMap resize logic in `echo-core-zig/src/data/hashmap.zig` by testing the scenario where inserting an item specifically triggers a resize based on the 75% load factor rule, and asserting that all previous items remain intact afterwards. Co-authored-by: ulac000000 <132948319+ulac000000@users.noreply.github.com> --- echo-core-zig/src/data/hashmap.zig | 33 ++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/echo-core-zig/src/data/hashmap.zig b/echo-core-zig/src/data/hashmap.zig index b12e8db..04e2811 100644 --- a/echo-core-zig/src/data/hashmap.zig +++ b/echo-core-zig/src/data/hashmap.zig @@ -294,3 +294,36 @@ test "HashMap multiple resizes and collisions" { // 1000 / 0.75 = 1333.33 -> next power of 2 is 2048 try std.testing.expect(map.entries.len >= 2048); } + +test "HashMap exact resize boundary" { + var map = try HashMap([]const u8, i32).init(std.testing.allocator, 8); + defer map.deinit(); + + // Initial capacity is 8 + try std.testing.expectEqual(@as(usize, 8), map.entries.len); + + try map.put("a", 1); + try map.put("b", 2); + try map.put("c", 3); + try map.put("d", 4); + try map.put("e", 5); + try map.put("f", 6); + + // Still capacity 8 + try std.testing.expectEqual(@as(usize, 8), map.entries.len); + + // 7th item triggers resize + try map.put("g", 7); + + // Now capacity should be 16 + try std.testing.expectEqual(@as(usize, 16), map.entries.len); + + // Verify all 7 items still exist + try std.testing.expectEqual(@as(i32, 1), map.get("a").?.*); + try std.testing.expectEqual(@as(i32, 2), map.get("b").?.*); + try std.testing.expectEqual(@as(i32, 3), map.get("c").?.*); + try std.testing.expectEqual(@as(i32, 4), map.get("d").?.*); + try std.testing.expectEqual(@as(i32, 5), map.get("e").?.*); + try std.testing.expectEqual(@as(i32, 6), map.get("f").?.*); + try std.testing.expectEqual(@as(i32, 7), map.get("g").?.*); +}