#include #include "basic_testing.h" #include "../chess_paths.h" struct chessboard { unsigned int C; unsigned int R; }; int value_at(const struct chessboard * c, unsigned int column, unsigned int row) { return column + row * c->C; } unsigned int columns(const struct chessboard * c) { return c->C; } unsigned int rows(const struct chessboard * c) { return c->R; }; TEST(inc_pawn) { struct chessboard c = {.C = 100000, .R = 10000 }; struct piece_position p; p.piece = PAWN; p.column = 12345; p.row = 1; assert_uint_eq(increasing_path_len(&c, &p), 9998); assert_uint_eq(p.column, 12345); assert_uint_eq(p.row, 9999); TEST_PASSED; } TEST(inc_king) { struct chessboard c = {.C = 100000, .R = 10000 }; struct piece_position p; p.piece = KING; p.column = 1; p.row = 0; assert_uint_eq(increasing_path_len(&c, &p), 99998); assert_uint_eq(p.column, 99999); assert_uint_eq(p.row, 9999); TEST_PASSED; } TEST(inc_queen) { struct chessboard c = {.C = 100000, .R = 10000 }; struct piece_position p; p.piece = QUEEN; p.column = 345; p.row = 4123; assert_uint_eq(increasing_path_len(&c, &p), 2); assert_uint_eq(p.column, 99999); assert_uint_eq(p.row, 9999); TEST_PASSED; } TEST(inc_knight) { struct chessboard c = {.C = 100000, .R = 10000 }; struct piece_position p; p.piece = KNIGHT; p.column = 12345; p.row = 1; assert_uint_eq(increasing_path_len(&c, &p), 4999); assert_uint_eq(p.column, 17344); assert_uint_eq(p.row, 9999); TEST_PASSED; } TEST(inc_bishop) { struct chessboard c = {.C = 100000, .R = 10000 }; struct piece_position p; p.piece = BISHOP; p.column = 12345; p.row = 0; assert_uint_eq(increasing_path_len(&c, &p), 1); assert_uint_eq(p.column, 22344); assert_uint_eq(p.row, 9999); TEST_PASSED; } TEST(inc_rook) { struct chessboard c = {.C = 100000, .R = 10000 }; struct piece_position p; p.piece = ROOK; p.column = 12345; p.row = 4321; assert_uint_eq(increasing_path_len(&c, &p), 2); assert_uint_eq(p.column, 99999); assert_uint_eq(p.row, 9999); TEST_PASSED; } int main() { RUN_TEST(inc_pawn); RUN_TEST(inc_king); RUN_TEST(inc_queen); RUN_TEST(inc_knight); RUN_TEST(inc_bishop); RUN_TEST(inc_rook); PRINT_TEST_RESULTS; assert(ALL_TESTS_PASSED); }