feat: apply clang-format and remove nested repo

This commit is contained in:
Rorikstr | Rust Dev 2025-10-24 19:43:39 +03:00
parent d4d99109fa
commit 532ca2e5ee
7 changed files with 464 additions and 466 deletions

View file

@ -101,14 +101,14 @@ dist: clean
style:
@if [ -f ../materials/linters/.clang-format ]; then \
clang-format -n $(TETRIS_SRC) $(CLI_SRC); \
clang-format -n $(TETRIS_SRC) $(CLI_SRC) $(TEST_SRC); \
else \
echo ".clang-format not found"; \
fi
format:
@if [ -f ../materials/linters/.clang-format ]; then \
clang-format -i $(TETRIS_SRC) $(CLI_SRC); \
clang-format -i $(TETRIS_SRC) $(CLI_SRC) $(TEST_SRC); \
else \
echo ".clang-format not found"; \
fi

View file

@ -1,76 +1,76 @@
#include "test_helper.h"
START_TEST(test_collision_bottom) {
test_setup();
GameState_t* state = get_game_state();
state->curr.y = FIELD_HEIGHT;
state->curr.x = 5;
state->curr.mtrx[0][0] = 1;
ck_assert_int_eq(check_collision(), 1);
test_setup();
GameState_t *state = get_game_state();
state->curr.y = FIELD_HEIGHT;
state->curr.x = 5;
state->curr.mtrx[0][0] = 1;
ck_assert_int_eq(check_collision(), 1);
}
END_TEST
START_TEST(test_collision_left) {
test_setup();
GameState_t* state = get_game_state();
state->curr.x = -1;
state->curr.y = 5;
state->curr.mtrx[0][0] = 1;
ck_assert_int_eq(check_collision(), 1);
test_setup();
GameState_t *state = get_game_state();
state->curr.x = -1;
state->curr.y = 5;
state->curr.mtrx[0][0] = 1;
ck_assert_int_eq(check_collision(), 1);
}
END_TEST
START_TEST(test_collision_right) {
test_setup();
GameState_t* state = get_game_state();
state->curr.x = FIELD_WIDTH;
state->curr.y = 5;
state->curr.mtrx[0][0] = 1;
ck_assert_int_eq(check_collision(), 1);
test_setup();
GameState_t *state = get_game_state();
state->curr.x = FIELD_WIDTH;
state->curr.y = 5;
state->curr.mtrx[0][0] = 1;
ck_assert_int_eq(check_collision(), 1);
}
END_TEST
START_TEST(test_collision_placed_block) {
test_setup();
GameState_t* state = get_game_state();
state->field[10][5] = 2;
state->curr.y = 10;
state->curr.x = 5;
state->curr.mtrx[0][0] = 1;
ck_assert_int_eq(check_collision(), 1);
test_setup();
GameState_t *state = get_game_state();
state->field[10][5] = 2;
state->curr.y = 10;
state->curr.x = 5;
state->curr.mtrx[0][0] = 1;
ck_assert_int_eq(check_collision(), 1);
}
END_TEST
START_TEST(test_no_collision) {
test_setup();
GameState_t* state = get_game_state();
state->curr.y = 5;
state->curr.x = 5;
state->curr.mtrx[0][0] = 1;
ck_assert_int_eq(check_collision(), 0);
test_setup();
GameState_t *state = get_game_state();
state->curr.y = 5;
state->curr.x = 5;
state->curr.mtrx[0][0] = 1;
ck_assert_int_eq(check_collision(), 0);
}
END_TEST
Suite* collision_suite(void) {
Suite* s = suite_create("Collision");
TCase* tc = tcase_create("Core");
tcase_add_test(tc, test_collision_bottom);
tcase_add_test(tc, test_collision_left);
tcase_add_test(tc, test_collision_right);
tcase_add_test(tc, test_collision_placed_block);
tcase_add_test(tc, test_no_collision);
suite_add_tcase(s, tc);
return s;
Suite *collision_suite(void) {
Suite *s = suite_create("Collision");
TCase *tc = tcase_create("Core");
tcase_add_test(tc, test_collision_bottom);
tcase_add_test(tc, test_collision_left);
tcase_add_test(tc, test_collision_right);
tcase_add_test(tc, test_collision_placed_block);
tcase_add_test(tc, test_no_collision);
suite_add_tcase(s, tc);
return s;
}

View file

@ -1,56 +1,57 @@
#include "test_helper.h"
START_TEST(test_generate_figure) {
generate_next_figure();
GameState_t* state = get_game_state();
ck_assert(state->next.sprite >= I && state->next.sprite < FIGURE_COUNT);
ck_assert_int_eq(state->next.rotation, 0);
generate_next_figure();
GameState_t *state = get_game_state();
ck_assert(state->next.sprite >= I && state->next.sprite < FIGURE_COUNT);
ck_assert_int_eq(state->next.rotation, 0);
}
END_TEST
START_TEST(test_all_shapes_exist) {
for (int sprite = I; sprite < FIGURE_COUNT; sprite++) {
for (int rotation = 0; rotation < 4; rotation++) {
const int (*shape)[4] = get_figure_shape(sprite, rotation);
ck_assert_ptr_nonnull(shape);
}
for (int sprite = I; sprite < FIGURE_COUNT; sprite++) {
for (int rotation = 0; rotation < 4; rotation++) {
const int(*shape)[4] = get_figure_shape(sprite, rotation);
ck_assert_ptr_nonnull(shape);
}
}
}
END_TEST
START_TEST(test_i_figure_horizontal) {
const int (*shape)[4] = get_figure_shape(I, 0);
int count = 0;
for (int j = 0; j < 4; j++) {
if (shape[1][j]) count++;
}
ck_assert_int_eq(count, 4);
const int(*shape)[4] = get_figure_shape(I, 0);
int count = 0;
for (int j = 0; j < 4; j++) {
if (shape[1][j])
count++;
}
ck_assert_int_eq(count, 4);
}
END_TEST
START_TEST(test_o_figure_unchanged) {
const int (*s1)[4] = get_figure_shape(O, 0);
const int (*s2)[4] = get_figure_shape(O, 2);
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
ck_assert_int_eq(s1[i][j], s2[i][j]);
}
const int(*s1)[4] = get_figure_shape(O, 0);
const int(*s2)[4] = get_figure_shape(O, 2);
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
ck_assert_int_eq(s1[i][j], s2[i][j]);
}
}
}
END_TEST
Suite* figures_suite(void) {
Suite* s = suite_create("Figures");
TCase* tc = tcase_create("Core");
tcase_add_test(tc, test_generate_figure);
tcase_add_test(tc, test_all_shapes_exist);
tcase_add_test(tc, test_i_figure_horizontal);
tcase_add_test(tc, test_o_figure_unchanged);
suite_add_tcase(s, tc);
return s;
Suite *figures_suite(void) {
Suite *s = suite_create("Figures");
TCase *tc = tcase_create("Core");
tcase_add_test(tc, test_generate_figure);
tcase_add_test(tc, test_all_shapes_exist);
tcase_add_test(tc, test_i_figure_horizontal);
tcase_add_test(tc, test_o_figure_unchanged);
suite_add_tcase(s, tc);
return s;
}

View file

@ -1,5 +1,5 @@
#include <check.h>
#include "test_helper.h"
#include <check.h>
#include <unistd.h>
// ============================================================================
@ -7,351 +7,348 @@
// ============================================================================
START_TEST(test_game_start) {
userInput(Start, false);
GameInfo_t state = updateCurrentState();
// После Start игра должна инициализироваться
ck_assert_int_eq(state.level, 1);
ck_assert_int_eq(state.score, 0);
ck_assert_int_eq(state.pause, 0);
userInput(Start, false);
GameInfo_t state = updateCurrentState();
// После Start игра должна инициализироваться
ck_assert_int_eq(state.level, 1);
ck_assert_int_eq(state.score, 0);
ck_assert_int_eq(state.pause, 0);
}
END_TEST
START_TEST(test_pause_toggle) {
userInput(Start, false);
updateCurrentState();
userInput(Pause, false);
GameInfo_t state = updateCurrentState();
ck_assert_int_eq(state.pause, 1);
userInput(Pause, false);
state = updateCurrentState();
ck_assert_int_eq(state.pause, 0);
userInput(Start, false);
updateCurrentState();
userInput(Pause, false);
GameInfo_t state = updateCurrentState();
ck_assert_int_eq(state.pause, 1);
userInput(Pause, false);
state = updateCurrentState();
ck_assert_int_eq(state.pause, 0);
}
END_TEST
START_TEST(test_field_initialization) {
userInput(Start, false);
GameInfo_t state = updateCurrentState();
int non_zero_count = 0;
for (int i = 0; i < FIELD_HEIGHT; i++) {
for (int j = 0; j < FIELD_WIDTH; j++) {
if (state.field[i][j] != 0) {
non_zero_count++;
}
}
userInput(Start, false);
GameInfo_t state = updateCurrentState();
int non_zero_count = 0;
for (int i = 0; i < FIELD_HEIGHT; i++) {
for (int j = 0; j < FIELD_WIDTH; j++) {
if (state.field[i][j] != 0) {
non_zero_count++;
}
}
ck_assert_int_le(non_zero_count, 4);
}
ck_assert_int_le(non_zero_count, 4);
}
END_TEST
START_TEST(test_next_figure_exists) {
userInput(Start, false);
GameInfo_t state = updateCurrentState();
int has_blocks = 0;
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
if (state.next[i][j]) {
has_blocks = 1;
}
}
userInput(Start, false);
GameInfo_t state = updateCurrentState();
int has_blocks = 0;
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
if (state.next[i][j]) {
has_blocks = 1;
}
}
ck_assert_int_eq(has_blocks, 1);
}
ck_assert_int_eq(has_blocks, 1);
}
END_TEST
START_TEST(test_movement_left) {
userInput(Start, false);
updateCurrentState();
userInput(Left, false);
GameInfo_t state = updateCurrentState();
ck_assert_int_eq(state.pause, 0);
userInput(Start, false);
updateCurrentState();
userInput(Left, false);
GameInfo_t state = updateCurrentState();
ck_assert_int_eq(state.pause, 0);
}
END_TEST
START_TEST(test_movement_right) {
userInput(Start, false);
updateCurrentState();
userInput(Right, false);
GameInfo_t state = updateCurrentState();
ck_assert_int_eq(state.pause, 0);
ck_assert_int_ge(state.level, 1);
userInput(Start, false);
updateCurrentState();
userInput(Right, false);
GameInfo_t state = updateCurrentState();
ck_assert_int_eq(state.pause, 0);
ck_assert_int_ge(state.level, 1);
}
END_TEST
START_TEST(test_rotation) {
userInput(Start, false);
updateCurrentState();
userInput(Action, false);
GameInfo_t state = updateCurrentState();
int has_figure = 0;
for (int i = 0; i < FIELD_HEIGHT; i++) {
for (int j = 0; j < FIELD_WIDTH; j++) {
if (state.field[i][j] == 1) {
has_figure = 1;
}
}
userInput(Start, false);
updateCurrentState();
userInput(Action, false);
GameInfo_t state = updateCurrentState();
int has_figure = 0;
for (int i = 0; i < FIELD_HEIGHT; i++) {
for (int j = 0; j < FIELD_WIDTH; j++) {
if (state.field[i][j] == 1) {
has_figure = 1;
}
}
ck_assert_int_eq(has_figure, 1);
}
ck_assert_int_eq(has_figure, 1);
}
END_TEST
START_TEST(test_user_input_actions) {
userInput(Start, false);
userInput(Left, false);
userInput(Right, false);
userInput(Action, false);
userInput(Pause, false);
userInput(Terminate, false);
ck_assert_int_eq(1, 1);
userInput(Start, false);
userInput(Left, false);
userInput(Right, false);
userInput(Action, false);
userInput(Pause, false);
userInput(Terminate, false);
ck_assert_int_eq(1, 1);
}
END_TEST
START_TEST(test_multiple_updates) {
userInput(Start, false);
for (int i = 0; i < 10; i++) {
updateCurrentState();
}
GameInfo_t state = updateCurrentState();
ck_assert_int_eq(state.level, 1);
userInput(Start, false);
for (int i = 0; i < 10; i++) {
updateCurrentState();
}
GameInfo_t state = updateCurrentState();
ck_assert_int_eq(state.level, 1);
}
END_TEST
START_TEST(test_instant_drop_down_key) {
userInput(Start, false);
updateCurrentState();
GameState_t* state = get_game_state();
state->down_key_was_released = 1;
userInput(Down, false);
ck_assert_int_eq(state->down_key_was_released, 0);
userInput(Start, false);
updateCurrentState();
GameState_t *state = get_game_state();
state->down_key_was_released = 1;
userInput(Down, false);
ck_assert_int_eq(state->down_key_was_released, 0);
}
END_TEST
START_TEST(test_up_key_release) {
userInput(Start, false);
updateCurrentState();
GameState_t* state = get_game_state();
state->down_key_was_released = 0;
userInput(Up, false);
updateCurrentState();
ck_assert_int_eq(state->down_key_was_released, 1);
userInput(Start, false);
updateCurrentState();
GameState_t *state = get_game_state();
state->down_key_was_released = 0;
userInput(Up, false);
updateCurrentState();
ck_assert_int_eq(state->down_key_was_released, 1);
}
END_TEST
START_TEST(test_terminate_with_high_score) {
userInput(Start, false);
updateCurrentState();
GameState_t* state = get_game_state();
state->info->high_score = 100;
state->info->score = 500;
userInput(Terminate, false);
int loaded = load_high_score();
ck_assert_int_ge(loaded, 500);
userInput(Start, false);
updateCurrentState();
GameState_t *state = get_game_state();
state->info->high_score = 100;
state->info->score = 500;
userInput(Terminate, false);
int loaded = load_high_score();
ck_assert_int_ge(loaded, 500);
}
END_TEST
START_TEST(test_game_over_state) {
userInput(Start, false);
updateCurrentState();
GameState_t* state = get_game_state();
for (int i = 0; i < 2; i++) {
for (int j = 0; j < FIELD_WIDTH; j++) {
state->field[i][j] = 2;
}
userInput(Start, false);
updateCurrentState();
GameState_t *state = get_game_state();
for (int i = 0; i < 2; i++) {
for (int j = 0; j < FIELD_WIDTH; j++) {
state->field[i][j] = 2;
}
state->state = Spawn;
updateCurrentState();
ck_assert_int_eq(state->state, GameOver);
}
state->state = Spawn;
updateCurrentState();
ck_assert_int_eq(state->state, GameOver);
}
END_TEST
START_TEST(test_do_gameover_clears_next) {
userInput(Start, false);
updateCurrentState();
GameState_t* state = get_game_state();
for (int i = 0; i < 2; i++) {
for (int j = 0; j < FIELD_WIDTH; j++) {
state->field[i][j] = 2;
}
userInput(Start, false);
updateCurrentState();
GameState_t *state = get_game_state();
for (int i = 0; i < 2; i++) {
for (int j = 0; j < FIELD_WIDTH; j++) {
state->field[i][j] = 2;
}
state->state = Spawn;
updateCurrentState();
state->state = GameOver;
updateCurrentState();
int has_blocks = 0;
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
if (state->next.mtrx[i][j]) {
has_blocks = 1;
}
}
}
state->state = Spawn;
updateCurrentState();
state->state = GameOver;
updateCurrentState();
int has_blocks = 0;
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
if (state->next.mtrx[i][j]) {
has_blocks = 1;
}
}
ck_assert_int_eq(has_blocks, 0);
}
ck_assert_int_eq(has_blocks, 0);
}
END_TEST
START_TEST(test_place_figure_directly) {
GameState_t* state = get_game_state();
for (int i = 0; i < FIELD_HEIGHT; i++)
for (int j = 0; j < FIELD_WIDTH; j++)
state->field[i][j] = 0;
state->curr.x = 5;
state->curr.y = 10;
for (int i = 0; i < 4; i++)
for (int j = 0; j < 4; j++)
state->curr.mtrx[i][j] = 0;
state->curr.mtrx[0][0] = 1;
state->curr.mtrx[0][1] = 1;
place_figure();
ck_assert_int_eq(state->field[10][5], 2);
ck_assert_int_eq(state->field[10][6], 2);
GameState_t *state = get_game_state();
for (int i = 0; i < FIELD_HEIGHT; i++)
for (int j = 0; j < FIELD_WIDTH; j++)
state->field[i][j] = 0;
state->curr.x = 5;
state->curr.y = 10;
for (int i = 0; i < 4; i++)
for (int j = 0; j < 4; j++)
state->curr.mtrx[i][j] = 0;
state->curr.mtrx[0][0] = 1;
state->curr.mtrx[0][1] = 1;
place_figure();
ck_assert_int_eq(state->field[10][5], 2);
ck_assert_int_eq(state->field[10][6], 2);
}
END_TEST
START_TEST(test_attach_state_transition) {
userInput(Start, false);
updateCurrentState();
GameState_t* state = get_game_state();
state->state = Attaching;
state->attach_start_time = 0;
state->attach_completed = 0;
updateCurrentState();
ck_assert_int_gt(state->attach_start_time, 0);
userInput(Start, false);
updateCurrentState();
GameState_t *state = get_game_state();
state->state = Attaching;
state->attach_start_time = 0;
state->attach_completed = 0;
updateCurrentState();
ck_assert_int_gt(state->attach_start_time, 0);
}
END_TEST
START_TEST(test_moving_to_down) {
userInput(Start, false);
updateCurrentState();
GameState_t* state = get_game_state();
state->curr.y = 5;
state->curr.x = 5;
for (int i = 0; i < 4; i++)
for (int j = 0; j < 4; j++)
state->curr.mtrx[i][j] = 0;
state->curr.mtrx[0][0] = 1;
int initial_y = state->curr.y;
state->state = Moving;
state->moving_type = ToDown;
long long start = get_current_time_ms();
updateCurrentState();
long long elapsed = get_current_time_ms() - start;
ck_assert(state->curr.y > initial_y || state->state == Attaching);
ck_assert_int_lt(elapsed, 1000);
userInput(Start, false);
updateCurrentState();
GameState_t *state = get_game_state();
state->curr.y = 5;
state->curr.x = 5;
for (int i = 0; i < 4; i++)
for (int j = 0; j < 4; j++)
state->curr.mtrx[i][j] = 0;
state->curr.mtrx[0][0] = 1;
int initial_y = state->curr.y;
state->state = Moving;
state->moving_type = ToDown;
long long start = get_current_time_ms();
updateCurrentState();
long long elapsed = get_current_time_ms() - start;
ck_assert(state->curr.y > initial_y || state->state == Attaching);
ck_assert_int_lt(elapsed, 1000);
}
END_TEST
START_TEST(test_moving_do_nothing) {
userInput(Start, false);
updateCurrentState();
GameState_t* state = get_game_state();
state->state = Moving;
state->moving_type = DoNothing;
updateCurrentState();
ck_assert_int_eq(state->state, Move);
userInput(Start, false);
updateCurrentState();
GameState_t *state = get_game_state();
state->state = Moving;
state->moving_type = DoNothing;
updateCurrentState();
ck_assert_int_eq(state->state, Move);
}
END_TEST
START_TEST(test_automatic_falling) {
userInput(Start, false);
updateCurrentState();
GameState_t* state = get_game_state();
state->curr.y = 5;
state->curr.x = 5;
for (int i = 0; i < 4; i++)
for (int j = 0; j < 4; j++)
state->curr.mtrx[i][j] = 0;
state->curr.mtrx[0][0] = 1;
state->state = Move;
state->last_move_time = 0;
int initial_y = state->curr.y;
updateCurrentState();
ck_assert(state->curr.y > initial_y || state->state == Attaching);
userInput(Start, false);
updateCurrentState();
GameState_t *state = get_game_state();
state->curr.y = 5;
state->curr.x = 5;
for (int i = 0; i < 4; i++)
for (int j = 0; j < 4; j++)
state->curr.mtrx[i][j] = 0;
state->curr.mtrx[0][0] = 1;
state->state = Move;
state->last_move_time = 0;
int initial_y = state->curr.y;
updateCurrentState();
ck_assert(state->curr.y > initial_y || state->state == Attaching);
}
END_TEST
Suite *fsm_suite(void) {
Suite *s = suite_create("FSM");
TCase *tc = tcase_create("Core");
Suite* fsm_suite(void) {
Suite* s = suite_create("FSM");
TCase* tc = tcase_create("Core");
tcase_add_test(tc, test_game_start);
tcase_add_test(tc, test_pause_toggle);
tcase_add_test(tc, test_field_initialization);
tcase_add_test(tc, test_next_figure_exists);
tcase_add_test(tc, test_movement_left);
tcase_add_test(tc, test_movement_right);
tcase_add_test(tc, test_rotation);
tcase_add_test(tc, test_user_input_actions);
tcase_add_test(tc, test_multiple_updates);
tcase_add_test(tc, test_instant_drop_down_key);
tcase_add_test(tc, test_up_key_release);
tcase_add_test(tc, test_terminate_with_high_score);
tcase_add_test(tc, test_game_over_state);
tcase_add_test(tc, test_do_gameover_clears_next);
tcase_add_test(tc, test_place_figure_directly);
tcase_add_test(tc, test_attach_state_transition);
tcase_add_test(tc, test_moving_to_down);
tcase_add_test(tc, test_moving_do_nothing);
tcase_add_test(tc, test_automatic_falling);
suite_add_tcase(s, tc);
return s;
tcase_add_test(tc, test_game_start);
tcase_add_test(tc, test_pause_toggle);
tcase_add_test(tc, test_field_initialization);
tcase_add_test(tc, test_next_figure_exists);
tcase_add_test(tc, test_movement_left);
tcase_add_test(tc, test_movement_right);
tcase_add_test(tc, test_rotation);
tcase_add_test(tc, test_user_input_actions);
tcase_add_test(tc, test_multiple_updates);
tcase_add_test(tc, test_instant_drop_down_key);
tcase_add_test(tc, test_up_key_release);
tcase_add_test(tc, test_terminate_with_high_score);
tcase_add_test(tc, test_game_over_state);
tcase_add_test(tc, test_do_gameover_clears_next);
tcase_add_test(tc, test_place_figure_directly);
tcase_add_test(tc, test_attach_state_transition);
tcase_add_test(tc, test_moving_to_down);
tcase_add_test(tc, test_moving_do_nothing);
tcase_add_test(tc, test_automatic_falling);
suite_add_tcase(s, tc);
return s;
}

View file

@ -1,76 +1,76 @@
#include "test_helper.h"
START_TEST(test_clear_one_line) {
test_setup();
fill_line(FIELD_HEIGHT - 1);
clear_lines();
ck_assert_int_eq(get_game_state()->info->score, 100);
test_setup();
fill_line(FIELD_HEIGHT - 1);
clear_lines();
ck_assert_int_eq(get_game_state()->info->score, 100);
}
END_TEST
START_TEST(test_clear_two_lines) {
test_setup();
fill_line(FIELD_HEIGHT - 1);
fill_line(FIELD_HEIGHT - 2);
clear_lines();
ck_assert_int_eq(get_game_state()->info->score, 300);
test_setup();
fill_line(FIELD_HEIGHT - 1);
fill_line(FIELD_HEIGHT - 2);
clear_lines();
ck_assert_int_eq(get_game_state()->info->score, 300);
}
END_TEST
START_TEST(test_clear_three_lines) {
test_setup();
fill_line(FIELD_HEIGHT - 1);
fill_line(FIELD_HEIGHT - 2);
fill_line(FIELD_HEIGHT - 3);
clear_lines();
ck_assert_int_eq(get_game_state()->info->score, 700);
test_setup();
fill_line(FIELD_HEIGHT - 1);
fill_line(FIELD_HEIGHT - 2);
fill_line(FIELD_HEIGHT - 3);
clear_lines();
ck_assert_int_eq(get_game_state()->info->score, 700);
}
END_TEST
START_TEST(test_clear_four_lines) {
test_setup();
fill_line(FIELD_HEIGHT - 1);
fill_line(FIELD_HEIGHT - 2);
fill_line(FIELD_HEIGHT - 3);
fill_line(FIELD_HEIGHT - 4);
clear_lines();
ck_assert_int_eq(get_game_state()->info->score, 1500);
test_setup();
fill_line(FIELD_HEIGHT - 1);
fill_line(FIELD_HEIGHT - 2);
fill_line(FIELD_HEIGHT - 3);
fill_line(FIELD_HEIGHT - 4);
clear_lines();
ck_assert_int_eq(get_game_state()->info->score, 1500);
}
END_TEST
START_TEST(test_incomplete_line) {
test_setup();
GameState_t* state = get_game_state();
// Не полная линия
for (int j = 0; j < FIELD_WIDTH - 1; j++) {
state->field[FIELD_HEIGHT - 1][j] = 2;
}
clear_lines();
ck_assert_int_eq(state->info->score, 0);
test_setup();
GameState_t *state = get_game_state();
// Не полная линия
for (int j = 0; j < FIELD_WIDTH - 1; j++) {
state->field[FIELD_HEIGHT - 1][j] = 2;
}
clear_lines();
ck_assert_int_eq(state->info->score, 0);
}
END_TEST
Suite* lines_suite(void) {
Suite* s = suite_create("ClearLines");
TCase* tc = tcase_create("Core");
tcase_add_test(tc, test_clear_one_line);
tcase_add_test(tc, test_clear_two_lines);
tcase_add_test(tc, test_clear_three_lines);
tcase_add_test(tc, test_clear_four_lines);
tcase_add_test(tc, test_incomplete_line);
suite_add_tcase(s, tc);
return s;
Suite *lines_suite(void) {
Suite *s = suite_create("ClearLines");
TCase *tc = tcase_create("Core");
tcase_add_test(tc, test_clear_one_line);
tcase_add_test(tc, test_clear_two_lines);
tcase_add_test(tc, test_clear_three_lines);
tcase_add_test(tc, test_clear_four_lines);
tcase_add_test(tc, test_incomplete_line);
suite_add_tcase(s, tc);
return s;
}

View file

@ -1,21 +1,21 @@
#include <check.h>
Suite* collision_suite(void);
Suite* lines_suite(void);
Suite* figures_suite(void);
Suite* score_suite(void);
Suite* fsm_suite(void);
Suite *collision_suite(void);
Suite *lines_suite(void);
Suite *figures_suite(void);
Suite *score_suite(void);
Suite *fsm_suite(void);
int main(void) {
SRunner* sr = srunner_create(collision_suite());
srunner_add_suite(sr, lines_suite());
srunner_add_suite(sr, figures_suite());
srunner_add_suite(sr, score_suite());
srunner_add_suite(sr, fsm_suite());
srunner_run_all(sr, CK_VERBOSE);
int failed = srunner_ntests_failed(sr);
srunner_free(sr);
return (failed == 0) ? 0 : 1;
SRunner *sr = srunner_create(collision_suite());
srunner_add_suite(sr, lines_suite());
srunner_add_suite(sr, figures_suite());
srunner_add_suite(sr, score_suite());
srunner_add_suite(sr, fsm_suite());
srunner_run_all(sr, CK_VERBOSE);
int failed = srunner_ntests_failed(sr);
srunner_free(sr);
return (failed == 0) ? 0 : 1;
}

View file

@ -1,60 +1,60 @@
#include "test_helper.h"
START_TEST(test_level_up) {
test_setup();
GameState_t* state = get_game_state();
fill_line(FIELD_HEIGHT - 1);
clear_lines();
fill_line(FIELD_HEIGHT - 1);
fill_line(FIELD_HEIGHT - 2);
clear_lines();
fill_line(FIELD_HEIGHT - 1);
fill_line(FIELD_HEIGHT - 2);
clear_lines();
ck_assert_int_eq(state->info->level, 2);
test_setup();
GameState_t *state = get_game_state();
fill_line(FIELD_HEIGHT - 1);
clear_lines();
fill_line(FIELD_HEIGHT - 1);
fill_line(FIELD_HEIGHT - 2);
clear_lines();
fill_line(FIELD_HEIGHT - 1);
fill_line(FIELD_HEIGHT - 2);
clear_lines();
ck_assert_int_eq(state->info->level, 2);
}
END_TEST
START_TEST(test_max_level) {
test_setup();
GameState_t* state = get_game_state();
state->info->score = 10000;
fill_line(FIELD_HEIGHT - 1);
clear_lines();
ck_assert_int_le(state->info->level, 10);
test_setup();
GameState_t *state = get_game_state();
state->info->score = 10000;
fill_line(FIELD_HEIGHT - 1);
clear_lines();
ck_assert_int_le(state->info->level, 10);
}
END_TEST
START_TEST(test_high_score_save) {
save_high_score(9999);
ck_assert_int_eq(load_high_score(), 9999);
save_high_score(9999);
ck_assert_int_eq(load_high_score(), 9999);
}
END_TEST
START_TEST(test_game_over_top) {
test_setup();
GameState_t* state = get_game_state();
state->field[0][5] = 2;
ck_assert_int_eq(is_game_over(), 1);
test_setup();
GameState_t *state = get_game_state();
state->field[0][5] = 2;
ck_assert_int_eq(is_game_over(), 1);
}
END_TEST
Suite* score_suite(void) {
Suite* s = suite_create("Score");
TCase* tc = tcase_create("Core");
tcase_add_test(tc, test_level_up);
tcase_add_test(tc, test_max_level);
tcase_add_test(tc, test_high_score_save);
tcase_add_test(tc, test_game_over_top);
suite_add_tcase(s, tc);
return s;
Suite *score_suite(void) {
Suite *s = suite_create("Score");
TCase *tc = tcase_create("Core");
tcase_add_test(tc, test_level_up);
tcase_add_test(tc, test_max_level);
tcase_add_test(tc, test_high_score_save);
tcase_add_test(tc, test_game_over_top);
suite_add_tcase(s, tc);
return s;
}