Implemented a few basic tests and ideas for future ones

This commit is contained in:
2026-04-29 13:18:27 +02:00
parent d7c7320443
commit 750bad7f83
6 changed files with 84 additions and 7 deletions

View File

@@ -51,4 +51,44 @@ pub const RoadManager = struct {
self.roads.clearRetainingCapacity();
self.next_id = 0;
}
};
};
const Vector2 = @import("raylib").Vector2;
const expect = std.testing.expect;
test "id tracking" {
var gpa: std.heap.DebugAllocator(.{}) = .init;
defer _ = gpa.deinit();
const allocator = gpa.allocator();
var road_man: RoadManager = .init();
defer road_man.deinit(allocator);
const n = 5;
const start: Node = .init(0, .{.x = 0, .y = 0});
const start_ptr = try allocator.create(Node);
start_ptr.* = start;
const end: Node = .init(1, .{.x = 100, .y = 100});
const end_ptr = try allocator.create(Node);
end_ptr.* = end;
defer {
start_ptr.deinit(allocator);
end_ptr.deinit(allocator);
allocator.destroy(start_ptr);
allocator.destroy(end_ptr);
}
for (0..n) |_| {
try road_man.addRoad(allocator, start_ptr, end_ptr);
}
try expect(road_man.next_id == n);
try expect(road_man.roads.items.len == n);
}
// TODO tests
// force resize pointer test
// destroy road and then verify the nodes do not have a pointer to it