diff --git a/test.c b/test.c index ebb653cc6156b4624e985b855e876068288f2638..4a0fb4805bc92d4e15ae47932b73f6303f9fd071 100644 --- a/test.c +++ b/test.c @@ -24,6 +24,7 @@ int main(void) { RUN_TEST(test_generate_pattern_should_return_all_0); // Tool + RUN_TEST(test_tool_init_destroy); RUN_TEST(test_compute_matches_should_remain_BALAI); return UNITY_END(); diff --git a/tool/test/tool-test.c b/tool/test/tool-test.c index 87564859ece068304714ac25b3590049c108f83b..c25caf7461d71bf9eff5ff4c7e25a8ea0689f0e3 100644 --- a/tool/test/tool-test.c +++ b/tool/test/tool-test.c @@ -1,5 +1,12 @@ #include "tool-test.h" +void test_tool_init_destroy(void) { + set_gamemode(TOOL_ASSISTED); + initialize_game(); + + destroy_game(); +} + void test_compute_matches_should_remain_BALAI(void) { // Arrange char **target = malloc(sizeof(char *)); diff --git a/tool/test/tool-test.h b/tool/test/tool-test.h index 537255eb9fadc7eed435c0cb54c678201d04964f..9762640f702ee5b605c7d025338da4ae1605d591 100644 --- a/tool/test/tool-test.h +++ b/tool/test/tool-test.h @@ -5,6 +5,7 @@ #include "../../wordle/wordle.h" #include "../tool.h" +void test_tool_init_destroy(void); void test_compute_matches_should_remain_BALAI(void); #endif diff --git a/tool/tool.c b/tool/tool.c index d377ec0c44801cc98d9e2f8ec7ae79c137b9318b..dd33536a7eebee457812cdd0193118f33a7bfe96 100644 --- a/tool/tool.c +++ b/tool/tool.c @@ -191,6 +191,7 @@ void init_tool() { void destroy_tool() { for (int i = 0; i < remaining_bank_count; i++) free(remaining_bank[i]); + free(remaining_bank); if (possibilities != NULL) diff --git a/wordle/test/wordle-test.c b/wordle/test/wordle-test.c index 398cf8302efec55f64bbc466f18bc2d839d4bfb2..9e099f33c520085e38bf520bbc38b62840d8db7d 100644 --- a/wordle/test/wordle-test.c +++ b/wordle/test/wordle-test.c @@ -1,34 +1,34 @@ #include "wordle-test.h" void test_gamemode_should_be_solo(void) { - initialize_game(); set_gamemode(SOLO); + initialize_game(); TEST_ASSERT_EQUAL_INT(SOLO, get_gamemode()); destroy_game(); } void test_gamemode_should_be_versus(void) { - initialize_game(); set_gamemode(VERSUS); + initialize_game(); TEST_ASSERT_EQUAL_INT(VERSUS, get_gamemode()); destroy_game(); } void test_gamemode_should_be_computer(void) { - initialize_game(); set_gamemode(TOOL_ASSISTED); + initialize_game(); TEST_ASSERT_EQUAL_INT(TOOL_ASSISTED, get_gamemode()); destroy_game(); } void test_answer_shoud_be_balai(void) { + set_gamemode(SOLO); initialize_game(); char target[WORD_LENGHT + 1] = "BALAI"; - set_gamemode(SOLO); set_answer(target); TEST_ASSERT_EQUAL_STRING(target, get_answer()); @@ -36,8 +36,8 @@ void test_answer_shoud_be_balai(void) { } void test_validate_letter_should_be_false(void) { - initialize_game(); set_gamemode(SOLO); + initialize_game(); for (int i = '\0'; i <= '@'; i++) TEST_ASSERT_FALSE(validate_letter(i)); @@ -45,8 +45,8 @@ void test_validate_letter_should_be_false(void) { } void test_validate_letter_should_be_true(void) { - initialize_game(); set_gamemode(SOLO); + initialize_game(); for (int i = 'a'; i <= 'z'; i++) TEST_ASSERT_TRUE(validate_letter(i)); @@ -57,9 +57,9 @@ void test_validate_letter_should_be_true(void) { } void test_generate_pattern_should_return_all_0(void) { + set_gamemode(SOLO); initialize_game(); Pattern target[WORD_LENGHT] = {WRONG, WRONG, WRONG, WRONG, WRONG}; - set_gamemode(SOLO); set_answer("BALAI"); set_try("PONTS");