Implemented a few basic tests and ideas for future ones
This commit is contained in:
@@ -73,4 +73,32 @@ pub const NodeManager = struct {
|
||||
self.nodes.clearRetainingCapacity();
|
||||
self.next_id = 0;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
const expect = std.testing.expect;
|
||||
|
||||
test "id tracking" {
|
||||
var gpa: std.heap.DebugAllocator(.{}) = .init;
|
||||
defer _ = gpa.deinit();
|
||||
const allocator = gpa.allocator();
|
||||
|
||||
var node_man: NodeManager = .init();
|
||||
defer node_man.deinit(allocator);
|
||||
const n = 5;
|
||||
|
||||
for (0..n) |_| {
|
||||
const node: Node = .init(node_man.getNextID(), Vector2 {
|
||||
.x = 500,
|
||||
.y = 500,
|
||||
});
|
||||
const node_ptr = try allocator.create(Node);
|
||||
node_ptr.* = node;
|
||||
try node_man.nodes.append(allocator, node_ptr);
|
||||
}
|
||||
|
||||
try expect(node_man.next_id == n);
|
||||
try expect(node_man.nodes.items.len == n);
|
||||
}
|
||||
|
||||
// TODO tests
|
||||
// force resize pointer test
|
||||
Reference in New Issue
Block a user