diff --git a/src/cmc/utl/futils.h b/src/cmc/utl/futils.h index 6921e42..3fdd79d 100644 --- a/src/cmc/utl/futils.h +++ b/src/cmc/utl/futils.h @@ -43,6 +43,7 @@ #include #include #include +#include #include /** @@ -124,6 +125,11 @@ static inline int cmc_double_cmp(double x1, double x2) // String +static inline int cmc_chr_cmp(char ch1, char ch2) +{ + return (ch1 > ch2) - (ch1 < ch2); +} + static inline int cmc_str_cmp(char *ch1, char *ch2) { // Assuming ch1 and ch2 are both null terminated character sequences @@ -227,6 +233,11 @@ static inline bool cmc_double_str(FILE *file, double element) // String +static inline bool cmc_chr_chr(FILE *file, char element) +{ + return fprintf(file, "%c", element) > 0; +} + static inline bool cmc_str_str(FILE *file, char *element) { return fprintf(file, "\"%s\"", element) > 0; @@ -380,6 +391,11 @@ static inline size_t cmc_double_hash(double e) // String +static inline size_t cmc_chr_hash(char e) +{ + return cmc_u8_hash((uint8_t)e); +} + // Both djb2 and java are based on a Linear Congruential Generator // https://en.wikipedia.org/wiki/Linear_congruential_generator diff --git a/tests/Makefile b/tests/Makefile index cb3c559..08b4f63 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -13,6 +13,10 @@ dev: main mkdir -p ./coverage mv *.gcov ./coverage +single: + $(CC) ./single.c $(INCLUDE) $(CFLAGS) -o ./$(OUTDIR)/$@.exe -DTEST=$(TEST) + ./$(OUTDIR)/$@.exe + clean: rm ./*.gcov ./*.gcda ./*.gcno ./*.exe -f rm ./coverage ./$(OUTDIR) -rf diff --git a/tests/single.c b/tests/single.c new file mode 100644 index 0000000..099c2a9 --- /dev/null +++ b/tests/single.c @@ -0,0 +1,63 @@ +#include +#include + +#include "cmc/utl/log.h" + +#define CMC_ARGS_FALLTHROUGH + +#define CMC_EXT_INIT +#define CMC_EXT_ITER +#define CMC_EXT_NODE +#define CMC_EXT_SEQ +#define CMC_EXT_SETF +#define CMC_EXT_STR + +#include "unt_bitset.h" +#include "unt_deque.h" +#include "unt_hashbidimap.h" +#include "unt_hashmap.h" +#include "unt_hashmultimap.h" +#include "unt_hashmultiset.h" +#include "unt_hashset.h" +#include "unt_heap.h" +#include "unt_intervalheap.h" +#include "unt_linkedlist.h" +#include "unt_list.h" +#include "unt_queue.h" +#include "unt_sortedlist.h" +#include "unt_stack.h" +#include "unt_treemap.h" +#include "unt_treeset.h" + +#define cmc_run(unit, unit_fails, test_fails) \ + do \ + { \ + uintmax_t f = unit(); \ + if (f != 0) \ + unit_fails += 1; \ + test_fails += f; \ + } while (0) + +int main(void) +{ + cmc_log_config.tlevel = CMC_LOG_TRACE; + + struct cmc_timer timer; + + cmc_timer_start(timer); + uintmax_t tests = 0, units = 0; + + cmc_run(CMC_(CMC, TEST), units, tests); + cmc_run(CMC_(CMC, CMC_(TEST, Iter)), units, tests); + + printf(" +---------------------------------------------------------------+\n"); + printf(" | SUMMARY |\n"); + printf(" +---------------------------------------------------------------+\n"); + printf(" | Total Units Failed : %25" PRIuMAX " units |\n", units); + printf(" | Total Tests Failed : %25" PRIuMAX " tests |\n", tests); + printf(" | Total Asserts Failed : %25" PRIuMAX " asserts |\n", cmc_assert_failed); + printf(" | Total Runtime : %25.0lf milliseconds |\n", timer.result); + printf(" +---------------------------------------------------------------+\n"); + + return tests; +}