Refactor/state machine (#470)
* initial additions * Move current_blind to game vars * tmp * tmp * tmp * tmp * tmp * tmp * tmp * Compile but is broken * temp fix for token location * tmp * Working, lets clean up * remove todo * Remove odd reroll blind variable * fix skipping blind screen * fix reroll * remove magic for blind token locations * clang format * Cleanup button highlight in blind menu * some cleanup * Add layout file for global UI rects * remove dead code * Clang format * clang format it up * Move reset top left funct to gfx utils * make note of soon-to-be removed vars * Cleanup gamevars declaration * Cleanup layout file * Apply suggestions from code review Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * Add include for stdbool.h in common_ui.h * Cleanup rect declaration * Start moving state machine stuff to new file * quick tmp * oops, add new files * working call list * fixed pointer stuff * working as per norm * working replacement * move defines to static const * fix compile issue * Add some missing "void"s * Working new substates * add statemachine to blind select * Fix game restart statemachine leak * clang-format * Clang format * Rework shop exit logic * Use new state machine in shop * Remove substates entirely * Remove debug stuff * Clang format * document state machine better * update list tests * clang-format * Update for PR * Claaaaang format * another clang-format * Remove extra state in round_end * cleanup docs for removals in lists * clang-format... again * update doxygen format * Clang format * Update list docs * Update lists tests * Fix bad conflict resolution --------- Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
co-authored by
Copilot Autofix powered by AI
parent
2329c4c681
commit
92cb9f9883
+83
-12
@@ -5,13 +5,13 @@
|
||||
#include <stdio.h>
|
||||
|
||||
// As simple as it gets, just needs to be initialized correctly
|
||||
// - list_create
|
||||
// - list_init
|
||||
// - list_is_empty
|
||||
// - list_get_len
|
||||
// - list_clear
|
||||
void create_and_clear_list(void)
|
||||
{
|
||||
List my_cool_list = list_create();
|
||||
List my_cool_list = list_init();
|
||||
|
||||
// verify no data
|
||||
assert(my_cool_list.head == NULL);
|
||||
@@ -26,7 +26,7 @@ void create_and_clear_list(void)
|
||||
|
||||
// Push back one entry, make sure it looks as expected
|
||||
// tests:
|
||||
// - list_create
|
||||
// - list_init
|
||||
// - list_push_back
|
||||
// - list_is_empty
|
||||
// - list_get_len
|
||||
@@ -34,7 +34,7 @@ void create_and_clear_list(void)
|
||||
// - list_clear
|
||||
void push_back_one_entry(void)
|
||||
{
|
||||
List my_cool_list = list_create();
|
||||
List my_cool_list = list_init();
|
||||
|
||||
// verify no data
|
||||
assert(my_cool_list.head == NULL);
|
||||
@@ -69,7 +69,7 @@ void push_back_one_entry(void)
|
||||
}
|
||||
|
||||
// Push front one entry, make sure it looks as expected
|
||||
// - list_create
|
||||
// - list_init
|
||||
// - list_push_front
|
||||
// - list_is_empty
|
||||
// - list_get_len
|
||||
@@ -77,7 +77,7 @@ void push_back_one_entry(void)
|
||||
// - list_clear
|
||||
void push_front_one_entry(void)
|
||||
{
|
||||
List my_cool_list = list_create();
|
||||
List my_cool_list = list_init();
|
||||
|
||||
// verify no data
|
||||
assert(my_cool_list.head == NULL);
|
||||
@@ -123,7 +123,7 @@ void push_front_one_entry(void)
|
||||
// Lastly, push to the front the same 3 entries and verify the state of the list
|
||||
// before detroying.
|
||||
//
|
||||
// - list_create
|
||||
// - list_init
|
||||
// - list_push_front
|
||||
// - list_is_empty
|
||||
// - list_get_len
|
||||
@@ -135,7 +135,7 @@ void push_front_one_entry(void)
|
||||
// - list_itr_remove_node_current;
|
||||
void push_back_three_remove_push_front_three_entries(void)
|
||||
{
|
||||
List my_cool_list = list_create();
|
||||
List my_cool_list = list_init();
|
||||
|
||||
// verify no data
|
||||
assert(my_cool_list.head == NULL);
|
||||
@@ -287,7 +287,7 @@ void push_back_three_remove_push_front_three_entries(void)
|
||||
}
|
||||
|
||||
// Test inserting at head, middle, and tail of list
|
||||
// - list_create
|
||||
// - list_init
|
||||
// - list_push_back
|
||||
// - list_insert
|
||||
// - list_is_empty
|
||||
@@ -299,7 +299,7 @@ void push_back_three_remove_push_front_three_entries(void)
|
||||
// - list_get_at_idx
|
||||
void test_list_insertion(void)
|
||||
{
|
||||
List my_cool_list = list_create();
|
||||
List my_cool_list = list_init();
|
||||
|
||||
// verify no data
|
||||
assert(my_cool_list.head == NULL);
|
||||
@@ -515,7 +515,7 @@ void test_list_insertion(void)
|
||||
}
|
||||
|
||||
// Test inserting at head, middle, and tail of list
|
||||
// - list_create
|
||||
// - list_init
|
||||
// - list_push_back
|
||||
// - list_swap
|
||||
// - list_is_empty
|
||||
@@ -526,7 +526,7 @@ void test_list_insertion(void)
|
||||
// - list_get_at_idx
|
||||
void test_list_swap(void)
|
||||
{
|
||||
List my_cool_list = list_create();
|
||||
List my_cool_list = list_init();
|
||||
|
||||
// verify no data
|
||||
assert(my_cool_list.head == NULL);
|
||||
@@ -662,6 +662,74 @@ void test_list_swap(void)
|
||||
}
|
||||
|
||||
|
||||
// Test the "list_remove_data" function
|
||||
// - list_init
|
||||
// - list_is_empty
|
||||
// - list_get_len
|
||||
// - list_clear
|
||||
void test_remove_data(void)
|
||||
{
|
||||
// this value MUST be 5
|
||||
const int initial_list_size = 5;
|
||||
const int midpoint = initial_list_size / 2;
|
||||
List my_cool_list = list_init();
|
||||
|
||||
// verify no data
|
||||
assert(my_cool_list.head == NULL);
|
||||
assert(my_cool_list.tail == NULL);
|
||||
assert(list_get_len(&my_cool_list) == 0);
|
||||
assert(list_is_empty(&my_cool_list));
|
||||
|
||||
int test_data[initial_list_size];
|
||||
|
||||
for(int i = 0; i < initial_list_size; i++)
|
||||
{
|
||||
// 0 -> 1 -> 2 -> 3 -> 4
|
||||
test_data[i] = i;
|
||||
list_push_back(&my_cool_list, &test_data[i]);
|
||||
}
|
||||
|
||||
assert(list_get_len(&my_cool_list) == initial_list_size);
|
||||
|
||||
// remove from the front
|
||||
assert(list_remove_data(&my_cool_list, &test_data[0]));
|
||||
|
||||
assert(my_cool_list.head->data == &test_data[1]);
|
||||
assert(list_get_len(&my_cool_list) == initial_list_size - 1);
|
||||
|
||||
// remove from the back
|
||||
assert(list_remove_data(&my_cool_list, &test_data[initial_list_size - 1]));
|
||||
|
||||
assert(my_cool_list.head->data == &test_data[1]);
|
||||
assert(my_cool_list.tail->data == &test_data[initial_list_size - 2]);
|
||||
assert(list_get_len(&my_cool_list) == initial_list_size - 2);
|
||||
|
||||
// remove from the middle
|
||||
assert(list_remove_data(&my_cool_list, &test_data[midpoint]));
|
||||
|
||||
assert(my_cool_list.head->data == &test_data[1]);
|
||||
assert(my_cool_list.tail->data == &test_data[initial_list_size - 2]);
|
||||
assert(list_get_len(&my_cool_list) == initial_list_size - 3);
|
||||
|
||||
// fail on removal of pointer not in list
|
||||
assert(!list_remove_data(&my_cool_list, NULL));
|
||||
|
||||
assert(my_cool_list.head->data == &test_data[1]);
|
||||
assert(my_cool_list.tail->data == &test_data[initial_list_size - 2]);
|
||||
assert(list_get_len(&my_cool_list) == initial_list_size - 3);
|
||||
|
||||
// remove last two elements, make sure list can be emptied
|
||||
assert(!list_is_empty(&my_cool_list));
|
||||
assert(list_remove_data(&my_cool_list, &test_data[1]));
|
||||
assert(!list_is_empty(&my_cool_list));
|
||||
assert(list_remove_data(&my_cool_list, &test_data[3]));
|
||||
assert(list_is_empty(&my_cool_list));
|
||||
|
||||
list_clear(&my_cool_list);
|
||||
|
||||
assert(list_is_empty(&my_cool_list));
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
printf("Testing List Create and Clear.\n");
|
||||
@@ -682,6 +750,9 @@ int main(void)
|
||||
printf("Testing List Swap.\n");
|
||||
test_list_swap();
|
||||
|
||||
printf("Testing List Remove Data.\n");
|
||||
test_remove_data();
|
||||
|
||||
printf("-------------------------------------------------------------------------------\n");
|
||||
printf("List Tests Passed :)\n");
|
||||
printf("-------------------------------------------------------------------------------\n");
|
||||
|
||||
Reference in New Issue
Block a user