Skip to content

Commit

Permalink
This test invalidate wrongly correct answers that didn't consider Uns…
Browse files Browse the repository at this point in the history
…igned types and its overflow. E.g. abs(queen_1.row - queen_2.row) == abs(queen_1.column - queen_2.column)

Tests if Queens can attack each other even when they crossed sides of the board, which is a common position on chest.
Also it ensure that the students start to take into account overflows that happens often in C/C++
  • Loading branch information
edu-bm7 committed Sep 10, 2024
1 parent 1181299 commit 560e4ca
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions exercises/practice/queen-attack/test_queen_attack.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,19 @@ test_cannot_attack_if_falling_diagonals_only_same_when_reflected_across_longest_
TEST_ASSERT_EQUAL(CAN_NOT_ATTACK, can_attack(white_queen, black_queen));
}

static void
test_can_attack_if_queens_crossed_sides_and_on_the_same_diagonal(void)
{
TEST_IGNORE();
position_t white_queen;
position_t black_queen;

white_queen.column = 2;
white_queen.row = 7;
black_queen.column = 6;
black_queen.row = 1;
TEST_ASSERT_EQUAL(CAN_ATTACK, can_attack(white_queen, black_queen));
}
int main(void)
{
UNITY_BEGIN();
Expand All @@ -210,6 +223,7 @@ int main(void)
RUN_TEST(test_can_attack_on_fourth_diagonal);
RUN_TEST(
test_cannot_attack_if_falling_diagonals_only_same_when_reflected_across_longest_falling_diagonal);
RUN_TEST(test_can_attack_if_queens_crossed_sides_and_on_the_same_diagonal);

return UNITY_END();
}

0 comments on commit 560e4ca

Please sign in to comment.