105 lines
2.3 KiB
C
105 lines
2.3 KiB
C
#include <assert.h>
|
|
|
|
#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(simple_pawn) {
|
|
struct chessboard c = { .C = 3, .R = 3 };
|
|
struct piece_position p;
|
|
p.piece = PAWN;
|
|
p.column = 0;
|
|
p.row = 0;
|
|
assert_uint_eq(simple_path_len(&c, &p), 2);
|
|
assert_uint_eq(p.column, 0);
|
|
assert_uint_eq(p.row, 2);
|
|
TEST_PASSED;
|
|
}
|
|
|
|
TEST(simple_king) {
|
|
struct chessboard c = { .C = 3, .R = 3 };
|
|
struct piece_position p;
|
|
p.piece = KING;
|
|
p.column = 0;
|
|
p.row = 0;
|
|
assert_uint_eq(simple_path_len(&c, &p), 8);
|
|
assert_uint_eq(p.column, 2);
|
|
assert_uint_eq(p.row, 0);
|
|
TEST_PASSED;
|
|
}
|
|
|
|
TEST(simple_queen) {
|
|
struct chessboard c = { .C = 3, .R = 3 };
|
|
struct piece_position p;
|
|
p.piece = QUEEN;
|
|
p.column = 0;
|
|
p.row = 0;
|
|
assert_uint_eq(simple_path_len(&c, &p), 8);
|
|
assert_uint_eq(p.column, 2);
|
|
assert_uint_eq(p.row, 0);
|
|
TEST_PASSED;
|
|
}
|
|
|
|
TEST(simple_knight) {
|
|
struct chessboard c = { .C = 3, .R = 3 };
|
|
struct piece_position p;
|
|
p.piece = KNIGHT;
|
|
p.column = 0;
|
|
p.row = 0;
|
|
assert_uint_eq(simple_path_len(&c, &p), 7);
|
|
assert_uint_eq(p.column, 2);
|
|
assert_uint_eq(p.row, 1);
|
|
TEST_PASSED;
|
|
}
|
|
|
|
TEST(simple_bishop) {
|
|
struct chessboard c = { .C = 3, .R = 3 };
|
|
struct piece_position p;
|
|
p.piece = BISHOP;
|
|
p.column = 0;
|
|
p.row = 0;
|
|
assert_uint_eq(simple_path_len(&c, &p), 4);
|
|
assert_uint_eq(p.column, 2);
|
|
assert_uint_eq(p.row, 0);
|
|
TEST_PASSED;
|
|
}
|
|
|
|
TEST(simple_rook) {
|
|
struct chessboard c = { .C = 3, .R = 3 };
|
|
struct piece_position p;
|
|
p.piece = ROOK;
|
|
p.column = 0;
|
|
p.row = 0;
|
|
assert_uint_eq(simple_path_len(&c, &p), 6);
|
|
assert_uint_eq(p.column, 0);
|
|
assert_uint_eq(p.row, 1);
|
|
TEST_PASSED;
|
|
}
|
|
|
|
int main() {
|
|
RUN_TEST(simple_pawn);
|
|
RUN_TEST(simple_king);
|
|
RUN_TEST(simple_queen);
|
|
RUN_TEST(simple_knight);
|
|
RUN_TEST(simple_bishop);
|
|
RUN_TEST(simple_rook);
|
|
PRINT_TEST_RESULTS;
|
|
assert(ALL_TESTS_PASSED);
|
|
}
|