Skip to content
Snippets Groups Projects
Commit 63a13d1e authored by tanguy.cavagna's avatar tanguy.cavagna :desktop:
Browse files

Added tool init/detroy test and fixed leaks due to unproper setup prior test

parent d44389f1
Branches
No related tags found
No related merge requests found
...@@ -24,6 +24,7 @@ int main(void) { ...@@ -24,6 +24,7 @@ int main(void) {
RUN_TEST(test_generate_pattern_should_return_all_0); RUN_TEST(test_generate_pattern_should_return_all_0);
// Tool // Tool
RUN_TEST(test_tool_init_destroy);
RUN_TEST(test_compute_matches_should_remain_BALAI); RUN_TEST(test_compute_matches_should_remain_BALAI);
return UNITY_END(); return UNITY_END();
......
#include "tool-test.h" #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) { void test_compute_matches_should_remain_BALAI(void) {
// Arrange // Arrange
char **target = malloc(sizeof(char *)); char **target = malloc(sizeof(char *));
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "../../wordle/wordle.h" #include "../../wordle/wordle.h"
#include "../tool.h" #include "../tool.h"
void test_tool_init_destroy(void);
void test_compute_matches_should_remain_BALAI(void); void test_compute_matches_should_remain_BALAI(void);
#endif #endif
...@@ -191,6 +191,7 @@ void init_tool() { ...@@ -191,6 +191,7 @@ void init_tool() {
void destroy_tool() { void destroy_tool() {
for (int i = 0; i < remaining_bank_count; i++) for (int i = 0; i < remaining_bank_count; i++)
free(remaining_bank[i]); free(remaining_bank[i]);
free(remaining_bank); free(remaining_bank);
if (possibilities != NULL) if (possibilities != NULL)
......
#include "wordle-test.h" #include "wordle-test.h"
void test_gamemode_should_be_solo(void) { void test_gamemode_should_be_solo(void) {
initialize_game();
set_gamemode(SOLO); set_gamemode(SOLO);
initialize_game();
TEST_ASSERT_EQUAL_INT(SOLO, get_gamemode()); TEST_ASSERT_EQUAL_INT(SOLO, get_gamemode());
destroy_game(); destroy_game();
} }
void test_gamemode_should_be_versus(void) { void test_gamemode_should_be_versus(void) {
initialize_game();
set_gamemode(VERSUS); set_gamemode(VERSUS);
initialize_game();
TEST_ASSERT_EQUAL_INT(VERSUS, get_gamemode()); TEST_ASSERT_EQUAL_INT(VERSUS, get_gamemode());
destroy_game(); destroy_game();
} }
void test_gamemode_should_be_computer(void) { void test_gamemode_should_be_computer(void) {
initialize_game();
set_gamemode(TOOL_ASSISTED); set_gamemode(TOOL_ASSISTED);
initialize_game();
TEST_ASSERT_EQUAL_INT(TOOL_ASSISTED, get_gamemode()); TEST_ASSERT_EQUAL_INT(TOOL_ASSISTED, get_gamemode());
destroy_game(); destroy_game();
} }
void test_answer_shoud_be_balai(void) { void test_answer_shoud_be_balai(void) {
set_gamemode(SOLO);
initialize_game(); initialize_game();
char target[WORD_LENGHT + 1] = "BALAI"; char target[WORD_LENGHT + 1] = "BALAI";
set_gamemode(SOLO);
set_answer(target); set_answer(target);
TEST_ASSERT_EQUAL_STRING(target, get_answer()); TEST_ASSERT_EQUAL_STRING(target, get_answer());
...@@ -36,8 +36,8 @@ void test_answer_shoud_be_balai(void) { ...@@ -36,8 +36,8 @@ void test_answer_shoud_be_balai(void) {
} }
void test_validate_letter_should_be_false(void) { void test_validate_letter_should_be_false(void) {
initialize_game();
set_gamemode(SOLO); set_gamemode(SOLO);
initialize_game();
for (int i = '\0'; i <= '@'; i++) for (int i = '\0'; i <= '@'; i++)
TEST_ASSERT_FALSE(validate_letter(i)); TEST_ASSERT_FALSE(validate_letter(i));
...@@ -45,8 +45,8 @@ void test_validate_letter_should_be_false(void) { ...@@ -45,8 +45,8 @@ void test_validate_letter_should_be_false(void) {
} }
void test_validate_letter_should_be_true(void) { void test_validate_letter_should_be_true(void) {
initialize_game();
set_gamemode(SOLO); set_gamemode(SOLO);
initialize_game();
for (int i = 'a'; i <= 'z'; i++) for (int i = 'a'; i <= 'z'; i++)
TEST_ASSERT_TRUE(validate_letter(i)); TEST_ASSERT_TRUE(validate_letter(i));
...@@ -57,9 +57,9 @@ void test_validate_letter_should_be_true(void) { ...@@ -57,9 +57,9 @@ void test_validate_letter_should_be_true(void) {
} }
void test_generate_pattern_should_return_all_0(void) { void test_generate_pattern_should_return_all_0(void) {
set_gamemode(SOLO);
initialize_game(); initialize_game();
Pattern target[WORD_LENGHT] = {WRONG, WRONG, WRONG, WRONG, WRONG}; Pattern target[WORD_LENGHT] = {WRONG, WRONG, WRONG, WRONG, WRONG};
set_gamemode(SOLO);
set_answer("BALAI"); set_answer("BALAI");
set_try("PONTS"); set_try("PONTS");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment