feat: complete human-vs-human gameplay end to end
This commit is contained in:
@@ -31,6 +31,7 @@ static void test_role_views_and_golden_schema(void) {
|
||||
state.phase = PHASE_IN_PROGRESS;
|
||||
state.mode = MODE_HUMAN;
|
||||
state.current_player = 1U;
|
||||
state.winner = kPlayerCapacity;
|
||||
set_board(&state.boards[0]);
|
||||
set_board(&state.boards[1]);
|
||||
char output[kStateMessageCapacity] = {0};
|
||||
@@ -50,6 +51,7 @@ static void test_role_views_and_golden_schema(void) {
|
||||
assert_hidden(output, 0);
|
||||
assert_hidden(output, 1);
|
||||
assert(board_start(output, 0)[1] == '2' && board_start(output, 1)[2] == '3');
|
||||
assert(strstr(output, "\"winner\":null,\"statistics\":[[0,0,0,0],[0,0,0,0]]") != NULL);
|
||||
}
|
||||
|
||||
static void test_finished_and_failure_are_safe(void) {
|
||||
@@ -71,10 +73,23 @@ static void test_finished_and_failure_are_safe(void) {
|
||||
lifecycle.game.state = state;
|
||||
lifecycle.game.state.phase = PHASE_REMATCH_WAIT;
|
||||
lifecycle.game.state.mode = MODE_HUMAN;
|
||||
lifecycle.game.state.winner = 1U;
|
||||
lifecycle.game.state.statistics[0] = (match_statistics_t){.shots = 9U, .hits = 4U, .misses = 5U, .ships_sunk = 2U};
|
||||
lifecycle.game.state.statistics[1] = (match_statistics_t){.shots = 8U, .hits = 5U, .misses = 3U, .ships_sunk = 3U};
|
||||
lifecycle.cumulative[0].wins = UINT16_MAX;
|
||||
lifecycle.cumulative[1].wins = UINT16_MAX;
|
||||
assert(state_presenter_write_lifecycle(&lifecycle, ROLE_SPECTATOR, output, sizeof(output), &written));
|
||||
assert(written == 371U);
|
||||
assert(written < sizeof(output));
|
||||
assert(strstr(output, "\"winner\":1,\"statistics\":[[9,4,5,2],[8,5,3,3]]") != NULL);
|
||||
|
||||
lifecycle.game.state.statistics[0] = (match_statistics_t){UINT16_MAX, UINT16_MAX, UINT16_MAX, UINT8_MAX};
|
||||
lifecycle.game.state.statistics[1] = (match_statistics_t){UINT16_MAX, UINT16_MAX, UINT16_MAX, UINT8_MAX};
|
||||
assert(state_presenter_write_lifecycle(&lifecycle, ROLE_SPECTATOR, output, sizeof(output), &written));
|
||||
assert(written < sizeof(output));
|
||||
|
||||
state.boards[0].ships[0] = (ship_t){.x = 2U, .y = 0U, .length = 1U, .hits = 1U, .horizontal = true};
|
||||
assert(state_presenter_write(&state, ROLE_SPECTATOR, output, sizeof(output), &written));
|
||||
assert(board_start(output, 0)[2] == '4');
|
||||
|
||||
char unchanged[16];
|
||||
memset(unchanged, 'X', sizeof(unchanged));
|
||||
|
||||
Reference in New Issue
Block a user