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

@ -2,7 +2,7 @@
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;
@ -14,7 +14,7 @@ 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;
@ -26,7 +26,7 @@ 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;
@ -38,7 +38,7 @@ 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;
@ -51,7 +51,7 @@ 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;
@ -61,9 +61,9 @@ START_TEST(test_no_collision) {
} }
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);

View file

@ -2,7 +2,7 @@
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);
@ -12,7 +12,7 @@ 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);
} }
} }
@ -20,19 +20,20 @@ START_TEST(test_all_shapes_exist) {
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++) {
@ -42,9 +43,9 @@ START_TEST(test_o_figure_unchanged) {
} }
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);

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>
// ============================================================================ // ============================================================================
@ -134,7 +134,7 @@ 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);
@ -147,7 +147,7 @@ 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);
@ -161,7 +161,7 @@ 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;
@ -176,7 +176,7 @@ 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++) {
@ -195,7 +195,7 @@ 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++) {
@ -222,7 +222,7 @@ START_TEST(test_do_gameover_clears_next) {
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++)
@ -247,7 +247,7 @@ 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;
@ -263,7 +263,7 @@ 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;
@ -286,12 +286,11 @@ START_TEST(test_moving_to_down) {
} }
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;
@ -305,7 +304,7 @@ 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;
@ -325,10 +324,9 @@ START_TEST(test_automatic_falling) {
} }
END_TEST END_TEST
Suite *fsm_suite(void) {
Suite* fsm_suite(void) { Suite *s = suite_create("FSM");
Suite* s = suite_create("FSM"); TCase *tc = tcase_create("Core");
TCase* tc = tcase_create("Core");
tcase_add_test(tc, test_game_start); tcase_add_test(tc, test_game_start);
tcase_add_test(tc, test_pause_toggle); tcase_add_test(tc, test_pause_toggle);
@ -354,4 +352,3 @@ Suite* fsm_suite(void) {
suite_add_tcase(s, tc); suite_add_tcase(s, tc);
return s; return s;
} }

View file

@ -48,7 +48,7 @@ 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++) {
@ -61,9 +61,9 @@ START_TEST(test_incomplete_line) {
} }
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);

View file

@ -1,13 +1,13 @@
#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());

View file

@ -2,7 +2,7 @@
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();
@ -21,7 +21,7 @@ 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);
@ -39,16 +39,16 @@ 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);