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: style:
@if [ -f ../materials/linters/.clang-format ]; then \ @if [ -f ../materials/linters/.clang-format ]; then \
clang-format -n $(TETRIS_SRC) $(CLI_SRC); \ clang-format -n $(TETRIS_SRC) $(CLI_SRC) $(TEST_SRC); \
else \ else \
echo ".clang-format not found"; \ echo ".clang-format not found"; \
fi fi
format: format:
@if [ -f ../materials/linters/.clang-format ]; then \ @if [ -f ../materials/linters/.clang-format ]; then \
clang-format -i $(TETRIS_SRC) $(CLI_SRC); \ clang-format -i $(TETRIS_SRC) $(CLI_SRC) $(TEST_SRC); \
else \ else \
echo ".clang-format not found"; \ echo ".clang-format not found"; \
fi fi

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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