updated tests

This commit is contained in:
k 2025-09-26 11:04:35 -04:00
parent bb3bc4442a
commit f9dda928b2

View File

@ -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);
}