aocc23

Advent of Code 2023
git clone git://www.tkruger.se/aocc23.git
Log | Files | Refs | README

tests.c (3310B)


      1 #include <CUnit/Basic.h>
      2 #include <assert.h>
      3 #include <stdio.h>
      4 #include <stdlib.h>
      5 
      6 #include "test_ht.h"
      7 #include "test_reading.h"
      8 #include "test_sd.h"
      9 #include "test_set_u64.h"
     10 #include "test_smallset.h"
     11 #include "test_stack_sd.h"
     12 #include "test_stack_str.h"
     13 #include "test_stack_u64.h"
     14 
     15 static CU_pSuite add_suite(char *name, CU_InitializeFunc pInit,
     16                            CU_CleanupFunc pClean) {
     17   CU_pSuite pSuite = NULL;
     18 
     19   if (CUE_SUCCESS != CU_initialize_registry())
     20     exit(CU_get_error());
     21 
     22   pSuite = CU_add_suite(name, pInit, pClean);
     23   if (NULL == pSuite) {
     24     CU_cleanup_registry();
     25     exit(CU_get_error());
     26   }
     27 
     28   return (pSuite);
     29 }
     30 
     31 static void add_test(CU_pSuite s, char *desc, CU_TestFunc fn) {
     32   if (NULL == CU_add_test(s, desc, fn)) {
     33     CU_cleanup_registry();
     34     exit(CU_get_error());
     35   }
     36 }
     37 
     38 int main() {
     39   if (CUE_SUCCESS != CU_initialize_registry())
     40     return CU_get_error();
     41 
     42   CU_pSuite s_all = add_suite("suite_all", NULL, NULL);
     43 
     44   add_test(s_all, "reading - readall()", test_reading_readall);
     45   add_test(s_all, "reading - readlines()", test_reading_readlines);
     46   add_test(s_all, "reading - read_next_u64()", test_reading_read_next_u64);
     47   add_test(s_all, "reading - sread_next_u64()", test_reading_sread_next_u64);
     48 
     49   add_test(s_all, "stack_u64 - init()", test_stack_u64_init);
     50   add_test(s_all, "stack_u64 - push()", test_stack_u64_push);
     51   add_test(s_all, "stack_u64 - get_getlast()", test_stack_u64_get_getlast);
     52   add_test(s_all, "stack_u64 - pop()", test_stack_u64_pop);
     53 
     54   add_test(s_all, "stack_str - init()", test_stack_str_init);
     55   add_test(s_all, "stack_str - push()", test_stack_str_push);
     56   add_test(s_all, "stack_str - get_getlast()", test_stack_str_get_getlast);
     57   add_test(s_all, "stack_str - pop()", test_stack_str_pop);
     58 
     59   add_test(s_all, "sd - init()", test_sd_init);
     60   add_test(s_all, "sd - cmp()", test_sd_cmp);
     61   add_test(s_all, "sd - hash()", test_sd_hash);
     62   add_test(s_all, "sd - sd_conv_u64()", test_sd_conv_u64);
     63   add_test(s_all, "sd - sd_get_str()", test_sd_get_str);
     64 
     65   add_test(s_all, "smallset - init()", test_smallset_init);
     66   add_test(s_all, "smallset - insert()", test_smallset_insert);
     67   add_test(s_all, "smallset - lookup()", test_smallset_lookup);
     68   add_test(s_all, "smallset - intersection()", test_smallset_intersection);
     69   add_test(s_all, "smallset - minus()", test_smallset_minus);
     70   add_test(s_all, "smallset - tonstr()", test_smallset_tonstr);
     71   add_test(s_all, "smallset - empty()", test_smallset_empty);
     72   add_test(s_all, "smallset - cardinality()", test_smallset_cardinality);
     73 
     74   add_test(s_all, "stack_sd - init()", test_stack_sd_init);
     75   add_test(s_all, "stack_sd - push()", test_stack_sd_push);
     76   add_test(s_all, "stack_sd - get()", test_stack_sd_get);
     77   add_test(s_all, "stack_sd - getlast()", test_stack_sd_getlast);
     78   add_test(s_all, "stack_sd - pop()", test_stack_sd_pop);
     79   add_test(s_all, "stack_sd - lookup()", test_stack_sd_lookup);
     80 
     81   add_test(s_all, "ht - init()", test_ht_init);
     82   add_test(s_all, "ht - insert()", test_ht_insert);
     83   add_test(s_all, "ht - lookup()", test_ht_lookup);
     84 
     85   add_test(s_all, "set_u64 - init()", test_set_u64_init);
     86 
     87   /* Run all tests using the CUnit Basic interface */
     88   CU_basic_set_mode(CU_BRM_VERBOSE);
     89   CU_basic_run_tests();
     90   CU_cleanup_registry();
     91   return CU_get_error();
     92 }