From 3c45e0ad751a1bfd6e15445b791515f515bbda3f Mon Sep 17 00:00:00 2001 From: Tait Hoyem <44244401+TTWNO@users.noreply.github.com> Date: Mon, 8 Apr 2019 22:08:24 +0000 Subject: [PATCH] Add some tests for checking only valid moves --- tests/tests_main.cpp | 4 ++++ tests/valid_moves.h | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 tests/valid_moves.h diff --git a/tests/tests_main.cpp b/tests/tests_main.cpp index 1c97bc4..d4af8dd 100755 --- a/tests/tests_main.cpp +++ b/tests/tests_main.cpp @@ -1,6 +1,7 @@ #define CATCH_CONFIG_MAIN #include "catch.hpp" #include "test_boards.h" +#include "valid_moves.h" #include #include @@ -146,6 +147,7 @@ TEST_CASE("Test that invalid position ints return false", "[is_valid_position]") TEST_CASE("Test what pieces may move where functon", "[get_possible_movers]"){ std::unordered_set H1_possible_movers = {Position::H2, Position::G1}; + CHECK(get_possible_movers(BISHOP_BLOCKED1_KING_POS, BISHOP_BLOCKED1_BOARD) == BISHOP_BLOCKED1_CAN_MOVE_TO_B_KING); CHECK(get_possible_movers(Position::H3, DEFAULT_BOARD) == H1_possible_movers); } @@ -154,6 +156,8 @@ TEST_CASE("Test where this piece may move to", "[get_possible_moves]"){ std::unordered_set black_A_pawn_possible_moves = {Position::A6,Position::A5}; CHECK(get_possible_moves(Position::G1, DEFAULT_BOARD) == white_right_knight_possible_moves); CHECK(get_possible_moves(Position::A7, DEFAULT_BOARD) == black_A_pawn_possible_moves); + CHECK(get_possible_moves(KNIGHT_BLOCKED1_POS, KNIGHT_BLOCKED1_BOARD) == KNIGHT_BLOCKED1_MOVES); + CHECK(get_possible_moves(BISHOP_BLOCKED1_POS, BISHOP_BLOCKED1_BOARD) == BISHOP_BLOCKED1_MOVES); } TEST_CASE("Test all possible and impossible moves for black pieces", "[get_all_moves][black]"){ diff --git a/tests/valid_moves.h b/tests/valid_moves.h new file mode 100644 index 0000000..0ffff2f --- /dev/null +++ b/tests/valid_moves.h @@ -0,0 +1,43 @@ +#include +#include + +const Position KNIGHT_BLOCKED1_POS = B8; +const std::array KNIGHT_BLOCKED1_BOARD = { + NONE, B_KNIGHT, NONE, NONE, NONE, NONE, NONE, NONE, + NONE, NONE, NONE, B_PAWN, NONE, NONE, NONE, NONE, + NONE, NONE, W_PAWN, NONE, NONE, NONE, NONE, NONE, + NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, + NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, + NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, + NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, + NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE +}; +// Should NOT inclde D7 +const std::unordered_set KNIGHT_BLOCKED1_MOVES = { + A6, C6 +}; + +const Position BISHOP_BLOCKED1_POS = D5; +const std::array BISHOP_BLOCKED1_BOARD = { + NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, + NONE, B_QUEEN, NONE , B_PAWN , NONE, W_KING, NONE, NONE, + NONE, NONE , NONE , NONE , NONE, NONE, NONE, NONE, + NONE, NONE , W_ROOK, W_BISHOP, NONE, NONE, NONE, NONE, + NONE, NONE , NONE , NONE , NONE, NONE, NONE, NONE, + NONE, NONE , NONE , NONE , NONE, B_KING, NONE, NONE, + NONE, NONE , NONE , NONE , NONE, NONE, NONE, NONE, + NONE, NONE , NONE , NONE , NONE, NONE, NONE, NONE +}; +// Should NOT include A8, H8, G2, or H1 +const std::unordered_set BISHOP_BLOCKED1_MOVES = { + B7, + C6,E6, + C4,E4, + B3,F3, + A2 +}; +// Should NOT include B2 (black queen) as it is obstructed by the bishop on D5 +const std::unordered_set BISHOP_BLOCKED1_CAN_MOVE_TO_B_KING = { + D5 +}; +const Position BISHOP_BLOCKED1_KING_POS = F3;