From f9dda928b2b9da0c5c27143859ae98b03fd9ba5f Mon Sep 17 00:00:00 2001 From: k Date: Fri, 26 Sep 2025 11:04:35 -0400 Subject: [PATCH] updated tests --- src/main.zig | 39 ++++++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/src/main.zig b/src/main.zig index d5195dc..486a233 100644 --- a/src/main.zig +++ b/src/main.zig @@ -65,7 +65,7 @@ fn uci(str: []const u8, game: *c.game, alloc: std.mem.Allocator) uciRet { return .{ .pass = {} }; } -fn uciPos(str: []const u8, alloc: std.mem.Allocator) [*c]c.game { +fn uciPos(str: []const u8, alloc: std.mem.Allocator) *c.game { const pos = std.mem.indexOfAny(u8, str, " \t\n\r") orelse str.len; const tok = str[0..pos]; var game = fenGame("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1", alloc); @@ -112,25 +112,46 @@ fn uciGo(game: *c.game) []const u8 { } test "uci uci" { - const game = uciPos("fen rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1"); - const out = uci("uci", game); + var gpa = std.heap.GeneralPurposeAllocator(.{}){}; + defer _ = gpa.deinit(); + const alloc = gpa.allocator(); + const game = uciPos("fen rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1", alloc); + defer alloc.destroy(game); + + const out = uci("uci", game, alloc); try std.testing.expect(out == .text); } test "uci ready" { - const game = uciPos("fen rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1"); - const out = uci("isready", game); + var gpa = std.heap.GeneralPurposeAllocator(.{}){}; + defer _ = gpa.deinit(); + const alloc = gpa.allocator(); + const game = uciPos("fen rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1", alloc); + defer alloc.destroy(game); + + const out = uci("isready", game, alloc); try std.testing.expect(out == .text); } test "uci go" { - const game = uciPos("fen rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1"); - const out = uci("go", game); + var gpa = std.heap.GeneralPurposeAllocator(.{}){}; + defer _ = gpa.deinit(); + const alloc = gpa.allocator(); + const game = uciPos("fen rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1", alloc); + defer alloc.destroy(game); + + const out = uci("go", game, alloc); try std.testing.expect(out == .move); } test "uci position" { - const game = uciPos("fen rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1"); - const out = uci("position startpos", game); + var gpa = std.heap.GeneralPurposeAllocator(.{}){}; + defer _ = gpa.deinit(); + const alloc = gpa.allocator(); + const game = uciPos("fen rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1", alloc); + defer alloc.destroy(game); + + const out = uci("position startpos", game, alloc); try std.testing.expect(out == .game); + alloc.destroy(out.game); }