Reworking structures for easy testing, read more

I was reworking bits of the containers to address issue #131, then
realized that the table's tests depended on a specific initial size. I'm
too buggered to finish it tonight, so I'll fix it tomorrow.
This commit is contained in:
2024-10-18 20:48:33 +11:00
parent c3ee92fcef
commit 98ea0e5884
11 changed files with 115 additions and 57 deletions

View File

@@ -21,7 +21,7 @@ int test_scope_allocation() {
if (scope == NULL ||
scope->next != NULL ||
scope->table == NULL ||
scope->table->capacity != 16 ||
scope->table->capacity != 8 ||
scope->refCount != 1 ||
false)
@@ -54,27 +54,27 @@ int test_scope_allocation() {
scope == NULL ||
scope->next == NULL ||
scope->table == NULL ||
scope->table->capacity != 16 ||
scope->table->capacity != 8 ||
scope->refCount != 1 ||
scope->next->next == NULL ||
scope->next->table == NULL ||
scope->next->table->capacity != 16 ||
scope->next->table->capacity != 8 ||
scope->next->refCount != 2 ||
scope->next->next->next == NULL ||
scope->next->next->table == NULL ||
scope->next->next->table->capacity != 16 ||
scope->next->next->table->capacity != 8 ||
scope->next->next->refCount != 3 ||
scope->next->next->next->next == NULL ||
scope->next->next->next->table == NULL ||
scope->next->next->next->table->capacity != 16 ||
scope->next->next->next->table->capacity != 8 ||
scope->next->next->next->refCount != 4 ||
scope->next->next->next->next->next != NULL ||
scope->next->next->next->next->table == NULL ||
scope->next->next->next->next->table->capacity != 16 ||
scope->next->next->next->next->table->capacity != 8 ||
scope->next->next->next->next->refCount != 5 || //refCount includes all ancestors
false)
@@ -115,17 +115,17 @@ int test_scope_allocation() {
scope == NULL ||
scope->next == NULL ||
scope->table == NULL ||
scope->table->capacity != 16 ||
scope->table->capacity != 8 ||
scope->refCount != 1 ||
scope->next->next == NULL ||
scope->next->table == NULL ||
scope->next->table->capacity != 16 ||
scope->next->table->capacity != 8 ||
scope->next->refCount != 2 ||
scope->next->next->next != NULL ||
scope->next->next->table == NULL ||
scope->next->next->table->capacity != 16 ||
scope->next->next->table->capacity != 8 ||
scope->next->next->refCount != 3 ||
false)
@@ -160,19 +160,19 @@ int test_scope_allocation() {
scopeBase == NULL ||
scopeBase->next != NULL ||
scopeBase->table == NULL ||
scopeBase->table->capacity != 16 ||
scopeBase->table->capacity != 8 ||
scopeBase->refCount != 3 ||
scopeA == NULL ||
scopeA->next != scopeBase ||
scopeA->table == NULL ||
scopeA->table->capacity != 16 ||
scopeA->table->capacity != 8 ||
scopeA->refCount != 1 ||
scopeB == NULL ||
scopeB->next != scopeBase ||
scopeB->table == NULL ||
scopeB->table->capacity != 16 ||
scopeB->table->capacity != 8 ||
scopeB->refCount != 1 ||
scopeA->next != scopeB->next || //double check
@@ -212,20 +212,20 @@ int test_scope_allocation() {
scopeA == NULL ||
scopeA->next != NULL ||
scopeA->table == NULL ||
scopeA->table->capacity != 16 ||
scopeA->table->capacity != 8 ||
scopeA->refCount != 2 ||
//scopeB still exists in memory until scopeC is popped
scopeB == NULL ||
scopeB->next != scopeA ||
scopeB->table == NULL ||
scopeB->table->capacity != 16 ||
scopeB->table->capacity != 8 ||
scopeB->refCount != 1 ||
scopeC == NULL ||
scopeC->next != scopeB ||
scopeC->table == NULL ||
scopeC->table->capacity != 16 ||
scopeC->table->capacity != 8 ||
scopeC->refCount != 1 ||
false)
@@ -259,19 +259,19 @@ int test_scope_allocation() {
scopeA == NULL ||
scopeA->next != NULL ||
scopeA->table == NULL ||
scopeA->table->capacity != 16 ||
scopeA->table->capacity != 8 ||
scopeA->refCount != 3 ||
scopeB == NULL ||
scopeB->next != scopeA ||
scopeB->table == NULL ||
scopeB->table->capacity != 16 ||
scopeB->table->capacity != 8 ||
scopeB->refCount != 1 ||
scopeB == NULL ||
scopeB->next != scopeA ||
scopeB->table == NULL ||
scopeB->table->capacity != 16 ||
scopeB->table->capacity != 8 ||
scopeB->refCount != 1 ||
scopeB == scopeCopy ||
@@ -335,7 +335,7 @@ int test_scope_elements() {
if (scope == NULL ||
scope->next != NULL ||
scope->table == NULL ||
scope->table->capacity != 16 ||
scope->table->capacity != 8 ||
scope->refCount != 1 ||
TOY_VALUE_IS_INTEGER(result) != true ||
@@ -360,7 +360,7 @@ int test_scope_elements() {
if (scope == NULL ||
scope->next != NULL ||
scope->table == NULL ||
scope->table->capacity != 16 ||
scope->table->capacity != 8 ||
scope->refCount != 1 ||
TOY_VALUE_IS_FLOAT(resultTwo) != true ||

View File

@@ -11,7 +11,7 @@ int test_stack_basics() {
//check if it worked
if (
stack == NULL ||
stack->capacity != 64 ||
stack->capacity != 8 ||
stack->count != 0)
{
fprintf(stderr, TOY_CC_ERROR "ERROR: failed to allocate Toy_Stack\n" TOY_CC_RESET);
@@ -32,7 +32,7 @@ int test_stack_basics() {
Toy_pushStack(&stack, TOY_VALUE_FROM_INTEGER(420));
if (
stack == NULL ||
stack->capacity != 64 ||
stack->capacity != 8 ||
stack->count != 3)
{
fprintf(stderr, TOY_CC_ERROR "ERROR: failed to push Toy_Stack\n" TOY_CC_RESET);
@@ -55,7 +55,7 @@ int test_stack_basics() {
Toy_Value top2 = Toy_popStack(&stack);
if (
stack == NULL ||
stack->capacity != 64 ||
stack->capacity != 8 ||
stack->count != 2 ||
TOY_VALUE_IS_INTEGER(top2) != true ||
TOY_VALUE_AS_INTEGER(top2) != 420)

View File

@@ -36,7 +36,7 @@ int test_table_simple_insert_lookup_and_remove() {
//insert
Toy_insertTable(&table, key, value);
if (table == NULL ||
table->capacity != 16 ||
table->capacity != 8 ||
table->count != 1)
{
fprintf(stderr, TOY_CC_ERROR "ERROR: Failed to insert into a table\n" TOY_CC_RESET);
@@ -49,7 +49,7 @@ int test_table_simple_insert_lookup_and_remove() {
//check lookup
if (table == NULL ||
table->capacity != 16 ||
table->capacity != 8 ||
table->count != 1 ||
TOY_VALUE_AS_INTEGER(result) != 42)
{
@@ -63,7 +63,7 @@ int test_table_simple_insert_lookup_and_remove() {
//check remove
if (table == NULL ||
table->capacity != 16 ||
table->capacity != 8 ||
table->count != 0)
{
fprintf(stderr, TOY_CC_ERROR "ERROR: Failed to remove from a table\n" TOY_CC_RESET);
@@ -97,7 +97,7 @@ int test_table_contents_no_expansion() {
//check the state
if (table == NULL ||
table->capacity != 16 ||
table->capacity != 8 ||
table->count != 1 ||
TEST_ENTRY_STATE(7, 1, 42, 0)
@@ -124,7 +124,7 @@ int test_table_contents_no_expansion() {
//check the state
if (table == NULL ||
table->capacity != 16 ||
table->capacity != 8 ||
table->count != 3 ||
TEST_ENTRY_STATE(7, 1, 42, 0) ||
@@ -154,7 +154,7 @@ int test_table_contents_no_expansion() {
//check the state
if (table == NULL ||
table->capacity != 16 ||
table->capacity != 8 ||
table->count != 4 ||
TEST_ENTRY_STATE(7, 1, 42, 0) ||
@@ -184,7 +184,7 @@ int test_table_contents_no_expansion() {
//check the state
if (table == NULL ||
table->capacity != 16 ||
table->capacity != 8 ||
table->count != 3 ||
TEST_ENTRY_STATE(15, 17, 42, 0) ||
@@ -216,7 +216,7 @@ int test_table_contents_no_expansion() {
//check the state
if (table == NULL ||
table->capacity != 16 ||
table->capacity != 8 ||
table->count != 3 ||
TOY_VALUE_IS_INTEGER(result) != true ||
@@ -245,7 +245,7 @@ int test_table_contents_no_expansion() {
//check the state
if (table == NULL ||
table->capacity != 16 ||
table->capacity != 8 ||
table->count != 4 ||
TEST_ENTRY_STATE(15, 17, 42, 0) ||
@@ -279,7 +279,7 @@ int test_table_contents_no_expansion() {
//check the state
if (table == NULL ||
table->capacity != 16 ||
table->capacity != 8 ||
table->count != 3 ||
TEST_ENTRY_STATE(15, 17, 42, 0) ||