updated vector to video version, will probably break a lot

This commit is contained in:
herbglitch 2024-08-27 03:23:29 -06:00
parent c1e60a6d2f
commit 93dc0fa053
12 changed files with 461 additions and 97 deletions

153
tests/src/vector.c Normal file
View file

@ -0,0 +1,153 @@
#include "../test.h"
#include "arc/std/bool.h"
#include "arc/std/errno.h"
#include "arc/std/vector.h"
#include <stdint.h>
ARC_Bool TEST_Vector_CompareDataFn(void *dataA, void *dataB){
if(*(int32_t *)dataA == *(int32_t *)dataB){
return ARC_True;
}
return ARC_False;
}
ARC_TEST(Vector_Add_RemoveIndex_Get){
ARC_Vector *vector;
ARC_Vector_Create(&vector, NULL);
int32_t val0 = 0;
int32_t val1 = 1;
int32_t val2 = 2;
int32_t val3 = 3;
int32_t val4 = 4;
ARC_Vector_Add(vector, &val0);
ARC_Vector_Add(vector, &val1);
ARC_Vector_Add(vector, &val2);
ARC_Vector_Add(vector, &val3);
ARC_Vector_Add(vector, &val4);
ARC_CHECK(0 == *(int32_t *)ARC_Vector_Get(vector, 0));
ARC_CHECK(1 == *(int32_t *)ARC_Vector_Get(vector, 1));
ARC_CHECK(2 == *(int32_t *)ARC_Vector_Get(vector, 2));
ARC_CHECK(3 == *(int32_t *)ARC_Vector_Get(vector, 3));
ARC_CHECK(4 == *(int32_t *)ARC_Vector_Get(vector, 4));
ARC_Vector_RemoveIndex(vector, 0);
ARC_CHECK(1 == *(int32_t *)ARC_Vector_Get(vector, 0));
ARC_CHECK(2 == *(int32_t *)ARC_Vector_Get(vector, 1));
ARC_CHECK(3 == *(int32_t *)ARC_Vector_Get(vector, 2));
ARC_CHECK(4 == *(int32_t *)ARC_Vector_Get(vector, 3));
ARC_Vector_RemoveIndex(vector, 3);
ARC_CHECK(1 == *(int32_t *)ARC_Vector_Get(vector, 0));
ARC_CHECK(2 == *(int32_t *)ARC_Vector_Get(vector, 1));
ARC_CHECK(3 == *(int32_t *)ARC_Vector_Get(vector, 2));
ARC_Vector_RemoveIndex(vector, 1);
ARC_CHECK(1 == *(int32_t *)ARC_Vector_Get(vector, 0));
ARC_CHECK(3 == *(int32_t *)ARC_Vector_Get(vector, 1));
ARC_Vector_RemoveIndex(vector, 1);
ARC_CHECK(1 == *(int32_t *)ARC_Vector_Get(vector, 0));
ARC_Vector_RemoveIndex(vector, 0);
ARC_Vector_Destroy(vector);
}
ARC_TEST(Vector_Add_Remove_Get){
ARC_Vector *vector;
ARC_Vector_CompareDataFn testCompareDataFn = TEST_Vector_CompareDataFn;
ARC_Vector_Create(&vector, &testCompareDataFn);
int32_t val0 = 0;
int32_t val1 = 1;
int32_t val2 = 2;
int32_t val3 = 3;
int32_t val4 = 4;
ARC_Vector_Add(vector, &val0);
ARC_Vector_Add(vector, &val1);
ARC_Vector_Add(vector, &val2);
ARC_Vector_Add(vector, &val3);
ARC_Vector_Add(vector, &val4);
ARC_CHECK(0 == *(int32_t *)ARC_Vector_Get(vector, 0));
ARC_CHECK(1 == *(int32_t *)ARC_Vector_Get(vector, 1));
ARC_CHECK(2 == *(int32_t *)ARC_Vector_Get(vector, 2));
ARC_CHECK(3 == *(int32_t *)ARC_Vector_Get(vector, 3));
ARC_CHECK(4 == *(int32_t *)ARC_Vector_Get(vector, 4));
ARC_Vector_Remove(vector, &val0);
ARC_CHECK(1 == *(int32_t *)ARC_Vector_Get(vector, 0));
ARC_CHECK(2 == *(int32_t *)ARC_Vector_Get(vector, 1));
ARC_CHECK(3 == *(int32_t *)ARC_Vector_Get(vector, 2));
ARC_CHECK(4 == *(int32_t *)ARC_Vector_Get(vector, 3));
ARC_Vector_Remove(vector, &val4);
ARC_CHECK(1 == *(int32_t *)ARC_Vector_Get(vector, 0));
ARC_CHECK(2 == *(int32_t *)ARC_Vector_Get(vector, 1));
ARC_CHECK(3 == *(int32_t *)ARC_Vector_Get(vector, 2));
ARC_Vector_Remove(vector, &val2);
ARC_CHECK(1 == *(int32_t *)ARC_Vector_Get(vector, 0));
ARC_CHECK(3 == *(int32_t *)ARC_Vector_Get(vector, 1));
ARC_Vector_Remove(vector, &val1);
ARC_CHECK(3 == *(int32_t *)ARC_Vector_Get(vector, 0));
ARC_Vector_Remove(vector, &val3);
ARC_Vector_Destroy(vector);
}
ARC_TEST(Vector_Add_RemoveIndex_GetSize){
ARC_Vector *vector;
ARC_Vector_Create(&vector, NULL);
int32_t val0 = 0;
int32_t val1 = 1;
int32_t val2 = 2;
int32_t val3 = 3;
int32_t val4 = 4;
ARC_Vector_Add(vector, &val0);
ARC_Vector_Add(vector, &val1);
ARC_Vector_Add(vector, &val2);
ARC_Vector_Add(vector, &val3);
ARC_Vector_Add(vector, &val4);
ARC_CHECK(5 == ARC_Vector_GetSize(vector));
ARC_Vector_RemoveIndex(vector, 0);
ARC_CHECK(4 == ARC_Vector_GetSize(vector));
ARC_Vector_RemoveIndex(vector, 0);
ARC_CHECK(3 == ARC_Vector_GetSize(vector));
ARC_Vector_RemoveIndex(vector, 0);
ARC_CHECK(2 == ARC_Vector_GetSize(vector));
ARC_Vector_RemoveIndex(vector, 0);
ARC_CHECK(1 == ARC_Vector_GetSize(vector));
ARC_Vector_RemoveIndex(vector, 0);
ARC_CHECK(0 == ARC_Vector_GetSize(vector));
ARC_Vector_Destroy(vector);
}
ARC_TEST(Vector_Add_RemoveIndex_Get_Try_Out_Of_Bounds){
ARC_Vector *vector;
ARC_Vector_Create(&vector, NULL);
int32_t val0 = 0;
ARC_Vector_Add(vector, &val0);
ARC_CHECK(NULL == ARC_Vector_Get(vector, 1));
arc_errno = 0;
ARC_Vector_RemoveIndex(vector, 0);
ARC_Vector_Destroy(vector);
}

22
tests/test.c Normal file
View file

@ -0,0 +1,22 @@
#include "test.h"
#include "arc/std/errno.h"
#include <stdio.h>
#include <stdlib.h>
uint32_t *temp_arc_test_num_checks_run__ARC_TEST__ = NULL;
uint32_t *temp_arc_test_num_checks_passed__ARC_TEST__ = NULL;
void ARC_Test_SetErrnoStream(void){
arc_errno_log_file = fopen("tests/test_error_out.txt", "w");
}
void ARC_Test_UnsetErrnoStream(void){
fclose(arc_errno_log_file);
}
#ifndef ARC_TEST_NO_MAIN
int main(void){
return 0;
}
#endif

44
tests/test.h Normal file
View file

@ -0,0 +1,44 @@
#ifndef ARC_TEST_H_
#define ARC_TEST_H_
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
#include <stdio.h>
extern uint32_t *temp_arc_test_num_checks_run__ARC_TEST__;
extern uint32_t *temp_arc_test_num_checks_passed__ARC_TEST__;
void ARC_Test_SetErrnoStream(void) __attribute__ ((constructor));
void ARC_Test_UnsetErrnoStream(void) __attribute__ ((destructor));
#define ARC_TEST_START_MESSAGE(MESSAGE) void ARC_TEST_START_MESSAGE__ ## MESSAGE(void) __attribute__ ((constructor));\
uint32_t arc_test_num_checks_run__ARC_TEST__ ## MESSAGE = 0;\
uint32_t arc_test_num_checks_passed__ARC_TEST__ ## MESSAGE = 0;\
void ARC_TEST_START_MESSAGE__ ## MESSAGE(void){\
printf("[ARC TEST] Running: %s\n", #MESSAGE);\
temp_arc_test_num_checks_run__ARC_TEST__ = &arc_test_num_checks_run__ARC_TEST__ ## MESSAGE; \
temp_arc_test_num_checks_passed__ARC_TEST__ = &arc_test_num_checks_passed__ARC_TEST__ ## MESSAGE; \
}
#define ARC_TEST_END_MESSAGE(MESSAGE) void ARC_TEST_END_MESSAGE__ ## MESSAGE(void) __attribute__ ((destructor));\
void ARC_TEST_END_MESSAGE__ ## MESSAGE(void){\
printf("[ARC TEST] RUN: %4u, PASSED: %4u, FAILED: %4u, Completed: %s\n", arc_test_num_checks_run__ARC_TEST__ ## MESSAGE, arc_test_num_checks_passed__ARC_TEST__ ## MESSAGE, arc_test_num_checks_run__ARC_TEST__ ## MESSAGE - arc_test_num_checks_passed__ARC_TEST__ ## MESSAGE, #MESSAGE);\
}
#define ARC_TEST(MESSAGE) ARC_TEST_START_MESSAGE(MESSAGE) ARC_TEST_END_MESSAGE(MESSAGE) void ARC_TEST__ ## MESSAGE(void) __attribute__ ((constructor)); void ARC_TEST__ ## MESSAGE (void)
#define ARC_CHECK(TEST)\
if(temp_arc_test_num_checks_run__ARC_TEST__ == NULL || temp_arc_test_num_checks_passed__ARC_TEST__ == NULL){ return; }\
printf(" %4u) ", *temp_arc_test_num_checks_run__ARC_TEST__);\
++*temp_arc_test_num_checks_run__ARC_TEST__;\
if(TEST){ printf("PASS\t\n"); ++*temp_arc_test_num_checks_passed__ARC_TEST__; }\
else { printf("FAIL\t%s\n", #TEST); }
#ifdef __cplusplus
}
#endif
#endif // !ARC_TEST_H_