From 4bebb90cb6f363c038d1584f9b653f9aa265bf47 Mon Sep 17 00:00:00 2001 From: Leonardo Vencovsky Date: Thu, 11 Jun 2020 21:23:42 -0300 Subject: [PATCH] Tests reworked - CI might not work --- .gitignore | 3 + .travis.yml | 3 +- Makefile | 94 ++++++++- autogen.py | 182 ++++++++++++++---- src/cmc/stack.h | 2 +- tests/Makefile | 22 --- tests/README.md | 9 - tests/include/cmc/bitset.h | 51 +++++ tests/include/cmc/deque.h | 78 ++++++++ tests/include/cmc/hashbidimap.h | 101 ++++++++++ tests/include/cmc/hashmap.h | 100 ++++++++++ tests/include/cmc/hashmultimap.h | 102 ++++++++++ tests/include/cmc/hashmultiset.h | 98 ++++++++++ tests/include/cmc/hashset.h | 88 +++++++++ tests/include/cmc/heap.h | 68 +++++++ tests/include/cmc/intervalheap.h | 72 +++++++ tests/include/cmc/linkedlist.h | 92 +++++++++ tests/include/cmc/list.h | 82 ++++++++ tests/include/cmc/queue.h | 71 +++++++ tests/include/cmc/sortedlist.h | 72 +++++++ tests/include/cmc/stack.h | 68 +++++++ tests/include/cmc/treemap.h | 92 +++++++++ tests/include/cmc/treeset.h | 84 ++++++++ tests/main.c | 102 ++++++++++ tests/main/Makefile | 107 ---------- tests/main/README.md | 3 - tests/main/main.c | 96 --------- tests/sep/Makefile | 15 -- tests/sep/collections.c | 17 -- tests/sep/collections.h | 17 -- tests/sep/main.c | 62 ------ tests/{main/src => src/cmc}/bitset.c | 48 +---- tests/{main/src => src/cmc}/deque.c | 74 ------- tests/{main/src => src/cmc}/hashbidimap.c | 97 ---------- tests/{main/src => src/cmc}/hashmap.c | 96 --------- tests/{main/src => src/cmc}/hashmultimap.c | 98 ---------- tests/{main/src => src/cmc}/hashmultiset.c | 94 --------- tests/{main/src => src/cmc}/hashset.c | 84 -------- tests/{main/src => src/cmc}/heap.c | 64 ------ tests/{main/src => src/cmc}/intervalheap.c | 68 ------- tests/{main/src => src/cmc}/linkedlist.c | 88 --------- tests/{main/src => src/cmc}/list.c | 78 -------- tests/{main/src => src/cmc}/queue.c | 67 ------- tests/{main/src => src/cmc}/sortedlist.c | 68 ------- tests/{main/src => src/cmc}/stack.c | 66 +------ tests/{main/src => src/cmc}/treemap.c | 88 --------- tests/{main/src => src/cmc}/treeset.c | 80 -------- tests/{main/unt/bitset.c => unt/cmc/bitset.h} | 34 ++-- tests/{main/unt/deque.c => unt/cmc/deque.h} | 172 +++++++++-------- .../hashbidimap.c => unt/cmc/hashbidimap.h} | 29 ++- .../{main/unt/hashmap.c => unt/cmc/hashmap.h} | 170 ++++++++-------- .../hashmultimap.c => unt/cmc/hashmultimap.h} | 24 ++- .../hashmultiset.c => unt/cmc/hashmultiset.h} | 24 ++- .../{main/unt/hashset.c => unt/cmc/hashset.h} | 28 +-- tests/{main/unt/heap.c => unt/cmc/heap.h} | 19 +- .../intervalheap.c => unt/cmc/intervalheap.h} | 29 ++- .../unt/linkedlist.c => unt/cmc/linkedlist.h} | 19 +- tests/{main/unt/list.c => unt/cmc/list.h} | 19 +- tests/{main/unt/queue.c => unt/cmc/queue.h} | 19 +- .../unt/sortedlist.c => unt/cmc/sortedlist.h} | 19 +- tests/{main/unt/stack.c => unt/cmc/stack.h} | 19 +- .../{main/unt/treemap.c => unt/cmc/treemap.h} | 19 +- .../{main/unt/treeset.c => unt/cmc/treeset.h} | 19 +- tests/{main/unt/utl.c => unt/utl.h} | 9 +- .../{main/unt/foreach.c => unt/utl/foreach.h} | 41 ++-- 65 files changed, 2071 insertions(+), 1952 deletions(-) delete mode 100644 tests/Makefile delete mode 100644 tests/README.md create mode 100644 tests/include/cmc/bitset.h create mode 100644 tests/include/cmc/deque.h create mode 100644 tests/include/cmc/hashbidimap.h create mode 100644 tests/include/cmc/hashmap.h create mode 100644 tests/include/cmc/hashmultimap.h create mode 100644 tests/include/cmc/hashmultiset.h create mode 100644 tests/include/cmc/hashset.h create mode 100644 tests/include/cmc/heap.h create mode 100644 tests/include/cmc/intervalheap.h create mode 100644 tests/include/cmc/linkedlist.h create mode 100644 tests/include/cmc/list.h create mode 100644 tests/include/cmc/queue.h create mode 100644 tests/include/cmc/sortedlist.h create mode 100644 tests/include/cmc/stack.h create mode 100644 tests/include/cmc/treemap.h create mode 100644 tests/include/cmc/treeset.h create mode 100644 tests/main.c delete mode 100644 tests/main/Makefile delete mode 100644 tests/main/README.md delete mode 100644 tests/main/main.c delete mode 100644 tests/sep/Makefile delete mode 100644 tests/sep/collections.c delete mode 100644 tests/sep/collections.h delete mode 100644 tests/sep/main.c rename tests/{main/src => src/cmc}/bitset.c (83%) rename tests/{main/src => src/cmc}/deque.c (83%) rename tests/{main/src => src/cmc}/hashbidimap.c (86%) rename tests/{main/src => src/cmc}/hashmap.c (85%) rename tests/{main/src => src/cmc}/hashmultimap.c (86%) rename tests/{main/src => src/cmc}/hashmultiset.c (86%) rename tests/{main/src => src/cmc}/hashset.c (86%) rename tests/{main/src => src/cmc}/heap.c (82%) rename tests/{main/src => src/cmc}/intervalheap.c (86%) rename tests/{main/src => src/cmc}/linkedlist.c (81%) rename tests/{main/src => src/cmc}/list.c (84%) rename tests/{main/src => src/cmc}/queue.c (82%) rename tests/{main/src => src/cmc}/sortedlist.c (83%) rename tests/{main/src => src/cmc}/stack.c (79%) rename tests/{main/src => src/cmc}/treemap.c (87%) rename tests/{main/src => src/cmc}/treeset.c (88%) rename tests/{main/unt/bitset.c => unt/cmc/bitset.h} (91%) rename tests/{main/unt/deque.c => unt/cmc/deque.h} (90%) rename tests/{main/unt/hashbidimap.c => unt/cmc/hashbidimap.h} (96%) rename tests/{main/unt/hashmap.c => unt/cmc/hashmap.h} (87%) rename tests/{main/unt/hashmultimap.c => unt/cmc/hashmultimap.h} (97%) rename tests/{main/unt/hashmultiset.c => unt/cmc/hashmultiset.h} (97%) rename tests/{main/unt/hashset.c => unt/cmc/hashset.h} (97%) rename tests/{main/unt/heap.c => unt/cmc/heap.h} (98%) rename tests/{main/unt/intervalheap.c => unt/cmc/intervalheap.h} (96%) rename tests/{main/unt/linkedlist.c => unt/cmc/linkedlist.h} (98%) rename tests/{main/unt/list.c => unt/cmc/list.h} (98%) rename tests/{main/unt/queue.c => unt/cmc/queue.h} (98%) rename tests/{main/unt/sortedlist.c => unt/cmc/sortedlist.h} (97%) rename tests/{main/unt/stack.c => unt/cmc/stack.h} (98%) rename tests/{main/unt/treemap.c => unt/cmc/treemap.h} (98%) rename tests/{main/unt/treeset.c => unt/cmc/treeset.h} (97%) rename tests/{main/unt/utl.c => unt/utl.h} (95%) rename tests/{main/unt/foreach.c => unt/utl/foreach.h} (97%) diff --git a/.gitignore b/.gitignore index a2d2de1..d755066 100644 --- a/.gitignore +++ b/.gitignore @@ -56,3 +56,6 @@ dkms.conf # Experimental folder experimental/ + +# Test / Code Coverage build folder +build diff --git a/.travis.yml b/.travis.yml index ff0bf29..d7ffa96 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,7 +12,6 @@ addons: script: - sudo ln -s /usr/bin/gcc-6 /usr/local/bin/gcc - export CC=gcc-7 -# - make -C ./tests/ - - make -C ./tests/main/ + - make coverage after_success: - bash <(curl -s https://codecov.io/bash) diff --git a/Makefile b/Makefile index ecbba47..a1c1c2a 100644 --- a/Makefile +++ b/Makefile @@ -1,13 +1,95 @@ -# This file is useful to format all the source files and header in this library using clang-format +# This file was generated by a Python script +CC = gcc +CFLAGS = -std=c11 -Wall -Wextra +CFLAGS += -Wno-missing-braces -DCMC_TEST_COLOR +CVFLAGS = --coverage -O0 -g3 +INCLUDE = ./tests/include -I src -ARGS = --verbose +# Runs the script to update tests, run all tests and code coverage +all: script coverage -all: src tests +tests: script build + ./tests/main.exe -src: FORCE +# Like build but with coverage +coverage: ./tests/build/obj/cmc/bitset.o ./tests/build/obj/cmc/deque.o ./tests/build/obj/cmc/hashbidimap.o ./tests/build/obj/cmc/hashmap.o ./tests/build/obj/cmc/hashmultimap.o ./tests/build/obj/cmc/hashmultiset.o ./tests/build/obj/cmc/hashset.o ./tests/build/obj/cmc/heap.o ./tests/build/obj/cmc/intervalheap.o ./tests/build/obj/cmc/linkedlist.o ./tests/build/obj/cmc/list.o ./tests/build/obj/cmc/queue.o ./tests/build/obj/cmc/sortedlist.o ./tests/build/obj/cmc/stack.o ./tests/build/obj/cmc/treemap.o ./tests/build/obj/cmc/treeset.o ./tests/build/obj/main.o + $(CC) $^ -o ./tests/main.exe $(CFLAGS) $(CVFLAGS) + ./tests/main.exe + gcov ./tests/build/obj/main.o ./tests/build/obj/cmc/bitset.o ./tests/build/obj/cmc/deque.o ./tests/build/obj/cmc/hashbidimap.o ./tests/build/obj/cmc/hashmap.o ./tests/build/obj/cmc/hashmultimap.o ./tests/build/obj/cmc/hashmultiset.o ./tests/build/obj/cmc/hashset.o ./tests/build/obj/cmc/heap.o ./tests/build/obj/cmc/intervalheap.o ./tests/build/obj/cmc/linkedlist.o ./tests/build/obj/cmc/list.o ./tests/build/obj/cmc/queue.o ./tests/build/obj/cmc/sortedlist.o ./tests/build/obj/cmc/stack.o ./tests/build/obj/cmc/treemap.o ./tests/build/obj/cmc/treeset.o + +# Run without coverage +run: build + ./tests/main.exe + +script: + python autogen.py + +clean: + find ./tests/build -type f -delete + rm *.gcov + +# No coverage build +build: ./tests/build/obj/cmc/bitset.o ./tests/build/obj/cmc/deque.o ./tests/build/obj/cmc/hashbidimap.o ./tests/build/obj/cmc/hashmap.o ./tests/build/obj/cmc/hashmultimap.o ./tests/build/obj/cmc/hashmultiset.o ./tests/build/obj/cmc/hashset.o ./tests/build/obj/cmc/heap.o ./tests/build/obj/cmc/intervalheap.o ./tests/build/obj/cmc/linkedlist.o ./tests/build/obj/cmc/list.o ./tests/build/obj/cmc/queue.o ./tests/build/obj/cmc/sortedlist.o ./tests/build/obj/cmc/stack.o ./tests/build/obj/cmc/treemap.o ./tests/build/obj/cmc/treeset.o ./tests/build/obj/main.o + $(CC) $^ -o ./tests/main.exe $(CFLAGS) + +./tests/build/obj/main.o: ./tests/main.c + $(CC) -c $^ -o $@ -I $(INCLUDE) $(CFLAGS) + +fmt_all: fmt_src fmt_tests + +fmt_src: FORCE find ./src/ -iname *.h | xargs clang-format --style=file --verbose -i -tests: FORCE +fmt_tests: FORCE find ./tests/ -iname *.c -o -iname *.h | xargs clang-format --style=file --verbose -i -FORCE: +.PHONY FORCE: + + +./tests/build/obj/cmc/bitset.o: ./tests/src/cmc/bitset.c ./tests/include/cmc/bitset.h + $(CC) -c $< -o $@ -I $(INCLUDE) $(CFLAGS) $(CVFLAGS) + +./tests/build/obj/cmc/deque.o: ./tests/src/cmc/deque.c ./tests/include/cmc/deque.h + $(CC) -c $< -o $@ -I $(INCLUDE) $(CFLAGS) $(CVFLAGS) + +./tests/build/obj/cmc/hashbidimap.o: ./tests/src/cmc/hashbidimap.c ./tests/include/cmc/hashbidimap.h + $(CC) -c $< -o $@ -I $(INCLUDE) $(CFLAGS) $(CVFLAGS) + +./tests/build/obj/cmc/hashmap.o: ./tests/src/cmc/hashmap.c ./tests/include/cmc/hashmap.h + $(CC) -c $< -o $@ -I $(INCLUDE) $(CFLAGS) $(CVFLAGS) + +./tests/build/obj/cmc/hashmultimap.o: ./tests/src/cmc/hashmultimap.c ./tests/include/cmc/hashmultimap.h + $(CC) -c $< -o $@ -I $(INCLUDE) $(CFLAGS) $(CVFLAGS) + +./tests/build/obj/cmc/hashmultiset.o: ./tests/src/cmc/hashmultiset.c ./tests/include/cmc/hashmultiset.h + $(CC) -c $< -o $@ -I $(INCLUDE) $(CFLAGS) $(CVFLAGS) + +./tests/build/obj/cmc/hashset.o: ./tests/src/cmc/hashset.c ./tests/include/cmc/hashset.h + $(CC) -c $< -o $@ -I $(INCLUDE) $(CFLAGS) $(CVFLAGS) + +./tests/build/obj/cmc/heap.o: ./tests/src/cmc/heap.c ./tests/include/cmc/heap.h + $(CC) -c $< -o $@ -I $(INCLUDE) $(CFLAGS) $(CVFLAGS) + +./tests/build/obj/cmc/intervalheap.o: ./tests/src/cmc/intervalheap.c ./tests/include/cmc/intervalheap.h + $(CC) -c $< -o $@ -I $(INCLUDE) $(CFLAGS) $(CVFLAGS) + +./tests/build/obj/cmc/linkedlist.o: ./tests/src/cmc/linkedlist.c ./tests/include/cmc/linkedlist.h + $(CC) -c $< -o $@ -I $(INCLUDE) $(CFLAGS) $(CVFLAGS) + +./tests/build/obj/cmc/list.o: ./tests/src/cmc/list.c ./tests/include/cmc/list.h + $(CC) -c $< -o $@ -I $(INCLUDE) $(CFLAGS) $(CVFLAGS) + +./tests/build/obj/cmc/queue.o: ./tests/src/cmc/queue.c ./tests/include/cmc/queue.h + $(CC) -c $< -o $@ -I $(INCLUDE) $(CFLAGS) $(CVFLAGS) + +./tests/build/obj/cmc/sortedlist.o: ./tests/src/cmc/sortedlist.c ./tests/include/cmc/sortedlist.h + $(CC) -c $< -o $@ -I $(INCLUDE) $(CFLAGS) $(CVFLAGS) + +./tests/build/obj/cmc/stack.o: ./tests/src/cmc/stack.c ./tests/include/cmc/stack.h + $(CC) -c $< -o $@ -I $(INCLUDE) $(CFLAGS) $(CVFLAGS) + +./tests/build/obj/cmc/treemap.o: ./tests/src/cmc/treemap.c ./tests/include/cmc/treemap.h + $(CC) -c $< -o $@ -I $(INCLUDE) $(CFLAGS) $(CVFLAGS) + +./tests/build/obj/cmc/treeset.o: ./tests/src/cmc/treeset.c ./tests/include/cmc/treeset.h + $(CC) -c $< -o $@ -I $(INCLUDE) $(CFLAGS) $(CVFLAGS) diff --git a/autogen.py b/autogen.py index 476ee47..ed5d58d 100644 --- a/autogen.py +++ b/autogen.py @@ -5,6 +5,11 @@ import sys import re import subprocess +# Make sure we have the specified directory +def assert_dir(dir): + if not os.path.exists(dir): + os.makedirs(dir) + # Compiler settings CC = 'gcc' INCLUDE = '-I ./src' @@ -22,10 +27,21 @@ UNIQUE_FLAG = '// C_MACRO_COLLECTIONS_CODE' TMP_FILE = './main.c' # Output directory -OUTPUT_DIR = './tests/main/src' +# In this directory it is assumed that the following files and folders are +# included: main.c, unt folder +OUTPUT_DIR = './tests' + +# All libraries +ALL_LIBS = ['CMC', 'SAC', 'TSC'] + +# Directory mapping +DIR_MAP = {'HEADER': 'include', 'SOURCE': 'src'} + +# File extension mapping +EXT_MAP = {'HEADER': 'h', 'SOURCE': 'c'} collections = [ - # type, header, pfx, sname, key, val + # header, library, collection, pfx, sname, size, key, val {'h': '"cmc/bitset.h"', 'LIB': 'CMC', 'COLLECTION': 'BITSET', 'PFX': 'bs', 'SNAME': 'bitset', 'SIZE': '', 'K': '', 'V': '' }, {'h': '"cmc/deque.h"', 'LIB': 'CMC', 'COLLECTION': 'DEQUE', 'PFX': 'd', 'SNAME': 'deque', 'SIZE': '', 'K': '', 'V': 'size_t'}, {'h': '"cmc/hashbidimap.h"', 'LIB': 'CMC', 'COLLECTION': 'HASHBIDIMAP', 'PFX': 'hbm', 'SNAME': 'hashbidimap', 'SIZE': '', 'K': 'size_t', 'V': 'size_t'}, @@ -45,55 +61,155 @@ collections = [ ] # Create output directory -if not os.path.exists(OUTPUT_DIR): - os.makedirs(OUTPUT_DIR) +assert_dir(OUTPUT_DIR) -for data in collections: - file = open(TMP_FILE, 'w') +# include and src +for dir in DIR_MAP.values(): + assert_dir(f'{OUTPUT_DIR}/{dir}') - file.write( - f''' - #include "macro_collections.h" +# For each library, create a folder for include and src +for lib in ALL_LIBS: + for dir in DIR_MAP.values(): + assert_dir(f'{OUTPUT_DIR}/{dir}/{lib.lower()}') - {UNIQUE_FLAG} +# Generate Header and Source separately +for ftype in ['HEADER', 'SOURCE']: + for data in collections: + file = open(TMP_FILE, 'w') - C_MACRO_COLLECTIONS_ALL({data['LIB']}, {data['COLLECTION']}, ({', '.join([data['PFX'], data['SNAME'], data['SIZE'], data['K'], data['V']])})) + file.write( + f''' + #include "macro_collections.h" - {UNIQUE_FLAG} - ''') + {UNIQUE_FLAG} - file.flush() - file.close() + C_MACRO_COLLECTIONS_ALL_{ftype}({data['LIB']}, {data['COLLECTION']}, ({', '.join([data['PFX'], data['SNAME'], data['SIZE'], data['K'], data['V']])})) - result = subprocess.getoutput(f'{CC} {FLAGS} {INCLUDE} {TMP_FILE}') + {UNIQUE_FLAG} + ''') - # (?s) makes '.' match anything, even '\n' - match = re.search(fr'(?s){UNIQUE_FLAG}(?P.+){UNIQUE_FLAG}', result) + file.flush() + file.close() - if match is None: - os.remove(TMP_FILE) - print('Didn\'t match FLAG. Probably because compilation failed.', file=sys.stderr) - exit(1) + result = subprocess.getoutput(f'{CC} {FLAGS} {INCLUDE} {TMP_FILE}') - file = open(f'{OUTPUT_DIR}/{data["SNAME"]}.c', 'w') + # (?s) makes '.' match anything, even '\n' + match = re.search(fr'(?s){UNIQUE_FLAG}(?P.+){UNIQUE_FLAG}', result) - file.write( - f'''#ifndef CMC_TEST_SRC_{data['COLLECTION']} - #define CMC_TEST_SRC_{data['COLLECTION']} + if match is None: + os.remove(TMP_FILE) + print('Didn\'t match FLAG. Probably because compilation failed.', file=sys.stderr) + exit(1) - #include {data["h"]}\n{match.group("code")} + file = open(f'{OUTPUT_DIR}/{DIR_MAP[ftype]}/{data["LIB"].lower()}/{data["SNAME"]}.{EXT_MAP[ftype]}', 'w') - #endif /* CMC_TEST_SRC_{data['COLLECTION']} */ - ''') + if ftype == 'HEADER': + file.write( + f''' + #ifndef CMC_{data['LIB']}_{data['COLLECTION']}_TEST_H + #define CMC_{data['LIB']}_{data['COLLECTION']}_TEST_H - file.flush() - file.close() + #include "macro_collections.h" + {match.group('code')} - print(f'Generated {data["h"]: >20} -> {OUTPUT_DIR}/{data["SNAME"]}.c') + #endif /* CMC_{data['LIB']}_{data['COLLECTION']}_TEST_H */ + ''') + else: + file.write( + f''' + #include {data["h"]} + + {match.group("code")} + ''') + + file.flush() + file.close() + + print(f'Generated {data["h"]: >20} -> {OUTPUT_DIR}/{DIR_MAP[ftype]}/{data["LIB"].lower()}/{data["SNAME"]}.{EXT_MAP[ftype]}') os.remove(TMP_FILE) # Format all files print('Formating files...') -subprocess.call(['clang-format', '--style=file', '-i', f'{OUTPUT_DIR}/*.c', '--verbose']) + +cmd = ['clang-format', '--style=file', '--verbose', '-i'] +dirs_to_format = [f'{OUTPUT_DIR}/{DIR_MAP[ftype]}/{lib.lower()}/*.{EXT_MAP[ftype]}' for ftype in DIR_MAP.keys() for lib in ALL_LIBS] + +cmd.extend(dirs_to_format) +subprocess.call(cmd) + +# Makefile +BUILD_DIR = f'{OUTPUT_DIR}/build' +OBJ_DIR = f'{BUILD_DIR}/obj' +INCLUDE_DIR = f"{OUTPUT_DIR}/{DIR_MAP['HEADER']}" +SRC_DIR = f"{OUTPUT_DIR}/{DIR_MAP['SOURCE']}" + +assert_dir(BUILD_DIR) +assert_dir(OBJ_DIR) + +for lib in ALL_LIBS: + assert_dir(f'{OBJ_DIR}/{lib.lower()}') + +file = open(f'Makefile', 'w') + +file.write(f'''# This file was generated by a Python script +CC = {CC} +CFLAGS = -std=c11 -Wall -Wextra +CFLAGS += -Wno-missing-braces -DCMC_TEST_COLOR +CVFLAGS = --coverage -O0 -g3 +INCLUDE = {INCLUDE_DIR} -I src + +# Runs the script to update tests, run all tests and code coverage +all: script coverage + +tests: script build +\t{OUTPUT_DIR}/main.exe + +# Like build but with coverage +coverage: {' '.join([f'{OBJ_DIR}/{data["LIB"].lower()}/{data["SNAME"]}.o' for data in collections])} {OBJ_DIR}/main.o +\t$(CC) $^ -o {OUTPUT_DIR}/main.exe $(CFLAGS) $(CVFLAGS) +\t{OUTPUT_DIR}/main.exe +\tgcov {OBJ_DIR}/main.o {' '.join([f'{OBJ_DIR}/{data["LIB"].lower()}/{data["SNAME"]}.o' for data in collections])} + +# Run without coverage +run: build +\t{OUTPUT_DIR}/main.exe + +script: +\tpython autogen.py + +clean: +\tfind {BUILD_DIR} -type f -delete +\trm *.gcov + +# No coverage build +build: {' '.join([f'{OBJ_DIR}/{data["LIB"].lower()}/{data["SNAME"]}.o' for data in collections])} {OBJ_DIR}/main.o +\t$(CC) $^ -o {OUTPUT_DIR}/main.exe $(CFLAGS) + +{OBJ_DIR}/main.o: {OUTPUT_DIR}/main.c +\t$(CC) -c $^ -o $@ -I $(INCLUDE) $(CFLAGS) +''') + +# Code formatting +file.write(''' +fmt_all: fmt_src fmt_tests + +fmt_src: FORCE + find ./src/ -iname *.h | xargs clang-format --style=file --verbose -i + +fmt_tests: FORCE + find ./tests/ -iname *.c -o -iname *.h | xargs clang-format --style=file --verbose -i + +.PHONY FORCE: + +''') + +for data in collections: + file.write(f''' +{OBJ_DIR}/{data['LIB'].lower()}/{data['SNAME']}.o: {SRC_DIR}/{data['LIB'].lower()}/{data['SNAME']}.c {INCLUDE_DIR}/{data['LIB'].lower()}/{data['SNAME']}.h +\t$(CC) -c $< -o $@ -I $(INCLUDE) $(CFLAGS) $(CVFLAGS) +''') + +file.close() + print('Done') diff --git a/src/cmc/stack.h b/src/cmc/stack.h index a5e9527..cb60b1e 100644 --- a/src/cmc/stack.h +++ b/src/cmc/stack.h @@ -378,7 +378,7 @@ return NULL; \ } \ \ - CMC_CALLBACKS_ASSIGN(_stack_, callbacks); \ + CMC_CALLBACKS_ASSIGN(result, _stack_->callbacks); \ \ if (_stack_->f_val->cpy) \ { \ diff --git a/tests/Makefile b/tests/Makefile deleted file mode 100644 index 63d94a4..0000000 --- a/tests/Makefile +++ /dev/null @@ -1,22 +0,0 @@ -CC = gcc -CFLAGS = -std=c11 -Wall -Wextra -CFLAGS += -Wno-unused -Wno-missing-braces - -main: FORCE - $(CC) foreach.c -o foreach.exe $(CFLAGS) - ./foreach.exe - $(CC) iterators.c -o iterators.exe $(CFLAGS) - ./iterators.exe - $(CC) contains.c -o contains.exe $(CFLAGS) - ./contains.exe - $(CC) types.c -o types.exe $(CFLAGS) - ./types.exe - make -C ./sep - -dev: main - rm *.exe ./sep/*.o ./sep/*.exe - -windev: main - del *.exe .\\sep\\*.o .\\sep\\*.exe - -FORCE: diff --git a/tests/README.md b/tests/README.md deleted file mode 100644 index 0755797..0000000 --- a/tests/README.md +++ /dev/null @@ -1,9 +0,0 @@ -# Tests - -* `codecov` - A stalled version for codecov; -* `main` - Unit tests for the main C Macro Collections library; -* `sep/main.c`, `sep/sep.c` and `sep/sep.h` - Tests separate header and source compilation; -* `contains.c` - Tests the `contains` function for all collections; -* `foreach.c` - Tests the ForEach macros for all collections; -* `iterators.c` - Tests all collection's iterators; -* `types.c` - Tests if all containers accept all possible C data types (struct, union, enum, pointers, function pointers) diff --git a/tests/include/cmc/bitset.h b/tests/include/cmc/bitset.h new file mode 100644 index 0000000..0918550 --- /dev/null +++ b/tests/include/cmc/bitset.h @@ -0,0 +1,51 @@ + +#ifndef CMC_CMC_BITSET_TEST_H +#define CMC_CMC_BITSET_TEST_H + +#include "macro_collections.h" + +struct bitset +{ + cmc_bitset_word *buffer; + size_t capacity; + int flag; + struct cmc_alloc_node *alloc; + struct cmc_callbacks *callbacks; +}; +struct bitset_iter +{ + struct bitset *target; + size_t cursor; + _Bool start; + _Bool end; +}; +struct bitset *bs_new(size_t n_bits); +struct bitset *bs_new_custom(size_t n_bits, struct cmc_alloc_node *alloc, struct cmc_callbacks *callbacks); +struct bitset bs_init(size_t n_bits); +struct bitset bs_init_custom(size_t n_bits, struct cmc_alloc_node *alloc, struct cmc_callbacks *callbacks); +void bs_free(struct bitset *_bitset_); +void bs_release(struct bitset _bitset_); +void bs_customize(struct bitset *_bitset_, struct cmc_alloc_node *alloc, struct cmc_callbacks *callbacks); +_Bool bs_set(struct bitset *_bitset_, size_t bit_index); +_Bool bs_set_range(struct bitset *_bitset_, size_t from, size_t to); +_Bool bs_clear(struct bitset *_bitset_, size_t bit_index); +_Bool bs_clear_range(struct bitset *_bitset_, size_t from, size_t to); +_Bool bs_flip(struct bitset *_bitset_, size_t bit_index); +_Bool bs_flip_range(struct bitset *_bitset_, size_t from, size_t to); +_Bool bs_put(struct bitset *_bitset_, size_t bit_index, _Bool state); +_Bool bs_put_range(struct bitset *_bitset_, size_t from, size_t to, _Bool state); +_Bool bs_set_all(struct bitset *_bitset_); +_Bool bs_clear_all(struct bitset *_bitset_); +_Bool bs_flip_all(struct bitset *_bitset_); +_Bool bs_get(struct bitset *_bitset_, size_t bit_index); +_Bool bs_resize(struct bitset *_bitset_, size_t n_bits); +static inline size_t bs_bit_to_index(size_t idx) +{ + static const size_t shift = + ((sizeof(cmc_bitset_word) * 8) >> 6) > 0 + ? 6 + : ((sizeof(cmc_bitset_word) * 8) >> 5) > 0 ? 5 : ((sizeof(cmc_bitset_word) * 8) >> 4) > 0 ? 4 : 3; + return idx >> shift; +} + +#endif /* CMC_CMC_BITSET_TEST_H */ diff --git a/tests/include/cmc/deque.h b/tests/include/cmc/deque.h new file mode 100644 index 0000000..b664e2a --- /dev/null +++ b/tests/include/cmc/deque.h @@ -0,0 +1,78 @@ + +#ifndef CMC_CMC_DEQUE_TEST_H +#define CMC_CMC_DEQUE_TEST_H + +#include "macro_collections.h" + +struct deque +{ + size_t *buffer; + size_t capacity; + size_t count; + size_t front; + size_t back; + int flag; + struct deque_fval *f_val; + struct cmc_alloc_node *alloc; + struct cmc_callbacks *callbacks; +}; +struct deque_fval +{ + int (*cmp)(size_t, size_t); + size_t (*cpy)(size_t); + _Bool (*str)(FILE *, size_t); + void (*free)(size_t); + size_t (*hash)(size_t); + int (*pri)(size_t, size_t); +}; +struct deque *d_new(size_t capacity, struct deque_fval *f_val); +struct deque *d_new_custom(size_t capacity, struct deque_fval *f_val, struct cmc_alloc_node *alloc, + struct cmc_callbacks *callbacks); +void d_clear(struct deque *_deque_); +void d_free(struct deque *_deque_); +void d_customize(struct deque *_deque_, struct cmc_alloc_node *alloc, struct cmc_callbacks *callbacks); +_Bool d_push_front(struct deque *_deque_, size_t value); +_Bool d_push_back(struct deque *_deque_, size_t value); +_Bool d_pop_front(struct deque *_deque_); +_Bool d_pop_back(struct deque *_deque_); +size_t d_front(struct deque *_deque_); +size_t d_back(struct deque *_deque_); +_Bool d_contains(struct deque *_deque_, size_t value); +_Bool d_empty(struct deque *_deque_); +_Bool d_full(struct deque *_deque_); +size_t d_count(struct deque *_deque_); +size_t d_capacity(struct deque *_deque_); +int d_flag(struct deque *_deque_); +_Bool d_resize(struct deque *_deque_, size_t capacity); +struct deque *d_copy_of(struct deque *_deque_); +_Bool d_equals(struct deque *_deque1_, struct deque *_deque2_); +struct deque d_init(size_t capacity, struct deque_fval *f_val); +struct deque d_init_custom(size_t capacity, struct deque_fval *f_val, struct cmc_alloc_node *alloc, + struct cmc_callbacks *callbacks); +void d_release(struct deque _deque_); +struct deque_iter +{ + struct deque *target; + size_t cursor; + size_t index; + _Bool start; + _Bool end; +}; +struct deque_iter d_iter_start(struct deque *target); +struct deque_iter d_iter_end(struct deque *target); +_Bool d_iter_at_start(struct deque_iter *iter); +_Bool d_iter_at_end(struct deque_iter *iter); +_Bool d_iter_to_start(struct deque_iter *iter); +_Bool d_iter_to_end(struct deque_iter *iter); +_Bool d_iter_next(struct deque_iter *iter); +_Bool d_iter_prev(struct deque_iter *iter); +_Bool d_iter_advance(struct deque_iter *iter, size_t steps); +_Bool d_iter_rewind(struct deque_iter *iter, size_t steps); +_Bool d_iter_go_to(struct deque_iter *iter, size_t index); +size_t d_iter_value(struct deque_iter *iter); +size_t *d_iter_rvalue(struct deque_iter *iter); +size_t d_iter_index(struct deque_iter *iter); +_Bool d_to_string(struct deque *_deque_, FILE *fptr); +_Bool d_print(struct deque *_deque_, FILE *fptr, const char *start, const char *separator, const char *end); + +#endif /* CMC_CMC_DEQUE_TEST_H */ diff --git a/tests/include/cmc/hashbidimap.h b/tests/include/cmc/hashbidimap.h new file mode 100644 index 0000000..c574437 --- /dev/null +++ b/tests/include/cmc/hashbidimap.h @@ -0,0 +1,101 @@ + +#ifndef CMC_CMC_HASHBIDIMAP_TEST_H +#define CMC_CMC_HASHBIDIMAP_TEST_H + +#include "macro_collections.h" + +struct hashbidimap +{ + struct hashbidimap_entry *(*buffer)[2]; + size_t capacity; + size_t count; + double load; + int flag; + struct hashbidimap_fkey *f_key; + struct hashbidimap_fval *f_val; + struct cmc_alloc_node *alloc; + struct cmc_callbacks *callbacks; + struct hashbidimap_iter (*it_start)(struct hashbidimap *); + struct hashbidimap_iter (*it_end)(struct hashbidimap *); +}; +struct hashbidimap_entry +{ + size_t key; + size_t value; + size_t dist[2]; + struct hashbidimap_entry **ref[2]; +}; +struct hashbidimap_fkey +{ + int (*cmp)(size_t, size_t); + size_t (*cpy)(size_t); + _Bool (*str)(FILE *, size_t); + void (*free)(size_t); + size_t (*hash)(size_t); + int (*pri)(size_t, size_t); +}; +struct hashbidimap_fval +{ + int (*cmp)(size_t, size_t); + size_t (*cpy)(size_t); + _Bool (*str)(FILE *, size_t); + void (*free)(size_t); + size_t (*hash)(size_t); + int (*pri)(size_t, size_t); +}; +struct hashbidimap_iter +{ + struct hashbidimap *target; + size_t cursor; + size_t index; + size_t first; + size_t last; + _Bool start; + _Bool end; +}; +struct hashbidimap *hbm_new(size_t capacity, double load, struct hashbidimap_fkey *f_key, + struct hashbidimap_fval *f_val); +struct hashbidimap *hbm_new_custom(size_t capacity, double load, struct hashbidimap_fkey *f_key, + struct hashbidimap_fval *f_val, struct cmc_alloc_node *alloc, + struct cmc_callbacks *callbacks); +void hbm_clear(struct hashbidimap *_map_); +void hbm_free(struct hashbidimap *_map_); +void hbm_customize(struct hashbidimap *_map_, struct cmc_alloc_node *alloc, struct cmc_callbacks *callbacks); +_Bool hbm_insert(struct hashbidimap *_map_, size_t key, size_t value); +_Bool hbm_update_key(struct hashbidimap *_map_, size_t val, size_t new_key); +_Bool hbm_update_val(struct hashbidimap *_map_, size_t key, size_t new_val); +_Bool hbm_remove_by_key(struct hashbidimap *_map_, size_t key, size_t *out_key, size_t *out_val); +_Bool hbm_remove_by_val(struct hashbidimap *_map_, size_t val, size_t *out_key, size_t *out_val); +size_t hbm_get_key(struct hashbidimap *_map_, size_t val); +size_t hbm_get_val(struct hashbidimap *_map_, size_t key); +_Bool hbm_contains_key(struct hashbidimap *_map_, size_t key); +_Bool hbm_contains_val(struct hashbidimap *_map_, size_t val); +_Bool hbm_empty(struct hashbidimap *_map_); +_Bool hbm_full(struct hashbidimap *_map_); +size_t hbm_count(struct hashbidimap *_map_); +size_t hbm_capacity(struct hashbidimap *_map_); +double hbm_load(struct hashbidimap *_map_); +int hbm_flag(struct hashbidimap *_map_); +_Bool hbm_resize(struct hashbidimap *_map_, size_t capacity); +struct hashbidimap *hbm_copy_of(struct hashbidimap *_map_); +_Bool hbm_equals(struct hashbidimap *_map1_, struct hashbidimap *_map2_); +struct hashbidimap_iter *hbm_iter_new(struct hashbidimap *target); +void hbm_iter_free(struct hashbidimap_iter *iter); +void hbm_iter_init(struct hashbidimap_iter *iter, struct hashbidimap *target); +_Bool hbm_iter_start(struct hashbidimap_iter *iter); +_Bool hbm_iter_end(struct hashbidimap_iter *iter); +void hbm_iter_to_start(struct hashbidimap_iter *iter); +void hbm_iter_to_end(struct hashbidimap_iter *iter); +_Bool hbm_iter_next(struct hashbidimap_iter *iter); +_Bool hbm_iter_prev(struct hashbidimap_iter *iter); +_Bool hbm_iter_advance(struct hashbidimap_iter *iter, size_t steps); +_Bool hbm_iter_rewind(struct hashbidimap_iter *iter, size_t steps); +_Bool hbm_iter_go_to(struct hashbidimap_iter *iter, size_t index); +size_t hbm_iter_key(struct hashbidimap_iter *iter); +size_t hbm_iter_value(struct hashbidimap_iter *iter); +size_t hbm_iter_index(struct hashbidimap_iter *iter); +_Bool hbm_to_string(struct hashbidimap *_map_, FILE *fptr); +_Bool hbm_print(struct hashbidimap *_map_, FILE *fptr, const char *start, const char *separator, const char *end, + const char *key_val_sep); + +#endif /* CMC_CMC_HASHBIDIMAP_TEST_H */ diff --git a/tests/include/cmc/hashmap.h b/tests/include/cmc/hashmap.h new file mode 100644 index 0000000..5bb61eb --- /dev/null +++ b/tests/include/cmc/hashmap.h @@ -0,0 +1,100 @@ + +#ifndef CMC_CMC_HASHMAP_TEST_H +#define CMC_CMC_HASHMAP_TEST_H + +#include "macro_collections.h" + +struct hashmap +{ + struct hashmap_entry *buffer; + size_t capacity; + size_t count; + double load; + int flag; + struct hashmap_fkey *f_key; + struct hashmap_fval *f_val; + struct cmc_alloc_node *alloc; + struct cmc_callbacks *callbacks; +}; +struct hashmap_entry +{ + size_t key; + size_t value; + size_t dist; + enum cmc_entry_state state; +}; +struct hashmap_fkey +{ + int (*cmp)(size_t, size_t); + size_t (*cpy)(size_t); + _Bool (*str)(FILE *, size_t); + void (*free)(size_t); + size_t (*hash)(size_t); + int (*pri)(size_t, size_t); +}; +struct hashmap_fval +{ + int (*cmp)(size_t, size_t); + size_t (*cpy)(size_t); + _Bool (*str)(FILE *, size_t); + void (*free)(size_t); + size_t (*hash)(size_t); + int (*pri)(size_t, size_t); +}; +struct hashmap *hm_new(size_t capacity, double load, struct hashmap_fkey *f_key, struct hashmap_fval *f_val); +struct hashmap *hm_new_custom(size_t capacity, double load, struct hashmap_fkey *f_key, struct hashmap_fval *f_val, + struct cmc_alloc_node *alloc, struct cmc_callbacks *callbacks); +void hm_clear(struct hashmap *_map_); +void hm_free(struct hashmap *_map_); +void hm_customize(struct hashmap *_map_, struct cmc_alloc_node *alloc, struct cmc_callbacks *callbacks); +_Bool hm_insert(struct hashmap *_map_, size_t key, size_t value); +_Bool hm_update(struct hashmap *_map_, size_t key, size_t new_value, size_t *old_value); +_Bool hm_remove(struct hashmap *_map_, size_t key, size_t *out_value); +_Bool hm_max(struct hashmap *_map_, size_t *key, size_t *value); +_Bool hm_min(struct hashmap *_map_, size_t *key, size_t *value); +size_t hm_get(struct hashmap *_map_, size_t key); +size_t *hm_get_ref(struct hashmap *_map_, size_t key); +_Bool hm_contains(struct hashmap *_map_, size_t key); +_Bool hm_empty(struct hashmap *_map_); +_Bool hm_full(struct hashmap *_map_); +size_t hm_count(struct hashmap *_map_); +size_t hm_capacity(struct hashmap *_map_); +double hm_load(struct hashmap *_map_); +int hm_flag(struct hashmap *_map_); +_Bool hm_resize(struct hashmap *_map_, size_t capacity); +struct hashmap *hm_copy_of(struct hashmap *_map_); +_Bool hm_equals(struct hashmap *_map1_, struct hashmap *_map2_); +struct hashmap hm_init(size_t capacity, double load, struct hashmap_fkey *f_key, struct hashmap_fval *f_val); +struct hashmap hm_init_custom(size_t capacity, double load, struct hashmap_fkey *f_key, struct hashmap_fval *f_val, + struct cmc_alloc_node *alloc, struct cmc_callbacks *callbacks); +void hm_release(struct hashmap _map_); +struct hashmap_iter +{ + struct hashmap *target; + size_t cursor; + size_t index; + size_t first; + size_t last; + _Bool start; + _Bool end; +}; +struct hashmap_iter hm_iter_start(struct hashmap *target); +struct hashmap_iter hm_iter_end(struct hashmap *target); +_Bool hm_iter_at_start(struct hashmap_iter *iter); +_Bool hm_iter_at_end(struct hashmap_iter *iter); +_Bool hm_iter_to_start(struct hashmap_iter *iter); +_Bool hm_iter_to_end(struct hashmap_iter *iter); +_Bool hm_iter_next(struct hashmap_iter *iter); +_Bool hm_iter_prev(struct hashmap_iter *iter); +_Bool hm_iter_advance(struct hashmap_iter *iter, size_t steps); +_Bool hm_iter_rewind(struct hashmap_iter *iter, size_t steps); +_Bool hm_iter_go_to(struct hashmap_iter *iter, size_t index); +size_t hm_iter_key(struct hashmap_iter *iter); +size_t hm_iter_value(struct hashmap_iter *iter); +size_t *hm_iter_rvalue(struct hashmap_iter *iter); +size_t hm_iter_index(struct hashmap_iter *iter); +_Bool hm_to_string(struct hashmap *_map_, FILE *fptr); +_Bool hm_print(struct hashmap *_map_, FILE *fptr, const char *start, const char *separator, const char *end, + const char *key_val_sep); + +#endif /* CMC_CMC_HASHMAP_TEST_H */ diff --git a/tests/include/cmc/hashmultimap.h b/tests/include/cmc/hashmultimap.h new file mode 100644 index 0000000..7b44266 --- /dev/null +++ b/tests/include/cmc/hashmultimap.h @@ -0,0 +1,102 @@ + +#ifndef CMC_CMC_HASHMULTIMAP_TEST_H +#define CMC_CMC_HASHMULTIMAP_TEST_H + +#include "macro_collections.h" + +struct hashmultimap +{ + struct hashmultimap_entry *(*buffer)[2]; + size_t capacity; + size_t count; + double load; + int flag; + struct hashmultimap_fkey *f_key; + struct hashmultimap_fval *f_val; + struct cmc_alloc_node *alloc; + struct cmc_callbacks *callbacks; +}; +struct hashmultimap_entry +{ + size_t key; + size_t value; + struct hashmultimap_entry *next; + struct hashmultimap_entry *prev; +}; +struct hashmultimap_fkey +{ + int (*cmp)(size_t, size_t); + size_t (*cpy)(size_t); + _Bool (*str)(FILE *, size_t); + void (*free)(size_t); + size_t (*hash)(size_t); + int (*pri)(size_t, size_t); +}; +struct hashmultimap_fval +{ + int (*cmp)(size_t, size_t); + size_t (*cpy)(size_t); + _Bool (*str)(FILE *, size_t); + void (*free)(size_t); + size_t (*hash)(size_t); + int (*pri)(size_t, size_t); +}; +struct hashmultimap *hmm_new(size_t capacity, double load, struct hashmultimap_fkey *f_key, + struct hashmultimap_fval *f_val); +struct hashmultimap *hmm_new_custom(size_t capacity, double load, struct hashmultimap_fkey *f_key, + struct hashmultimap_fval *f_val, struct cmc_alloc_node *alloc, + struct cmc_callbacks *callbacks); +void hmm_clear(struct hashmultimap *_map_); +void hmm_free(struct hashmultimap *_map_); +void hmm_customize(struct hashmultimap *_map_, struct cmc_alloc_node *alloc, struct cmc_callbacks *callbacks); +_Bool hmm_insert(struct hashmultimap *_map_, size_t key, size_t value); +_Bool hmm_update(struct hashmultimap *_map_, size_t key, size_t new_value, size_t *old_value); +size_t hmm_update_all(struct hashmultimap *_map_, size_t key, size_t new_value, size_t **old_values); +_Bool hmm_remove(struct hashmultimap *_map_, size_t key, size_t *out_value); +size_t hmm_remove_all(struct hashmultimap *_map_, size_t key, size_t **out_values); +_Bool hmm_max(struct hashmultimap *_map_, size_t *key, size_t *value); +_Bool hmm_min(struct hashmultimap *_map_, size_t *key, size_t *value); +size_t hmm_get(struct hashmultimap *_map_, size_t key); +size_t *hmm_get_ref(struct hashmultimap *_map_, size_t key); +_Bool hmm_contains(struct hashmultimap *_map_, size_t key); +_Bool hmm_empty(struct hashmultimap *_map_); +_Bool hmm_full(struct hashmultimap *_map_); +size_t hmm_count(struct hashmultimap *_map_); +size_t hmm_key_count(struct hashmultimap *_map_, size_t key); +size_t hmm_capacity(struct hashmultimap *_map_); +double hmm_load(struct hashmultimap *_map_); +int hmm_flag(struct hashmultimap *_map_); +_Bool hmm_resize(struct hashmultimap *_map_, size_t capacity); +struct hashmultimap *hmm_copy_of(struct hashmultimap *_map_); +_Bool hmm_equals(struct hashmultimap *_map1_, struct hashmultimap *_map2_); +struct hashmultimap_iter +{ + struct hashmultimap *target; + struct hashmultimap_entry *curr_entry; + size_t cursor; + size_t index; + size_t first; + size_t last; + _Bool start; + _Bool end; +}; +struct hashmultimap_iter hmm_iter_start(struct hashmultimap *target); +struct hashmultimap_iter hmm_iter_end(struct hashmultimap *target); +_Bool hmm_iter_at_start(struct hashmultimap_iter *iter); +_Bool hmm_iter_at_end(struct hashmultimap_iter *iter); +_Bool hmm_iter_to_start(struct hashmultimap_iter *iter); +_Bool hmm_iter_to_end(struct hashmultimap_iter *iter); +_Bool hmm_iter_next(struct hashmultimap_iter *iter); +_Bool hmm_iter_prev(struct hashmultimap_iter *iter); +_Bool hmm_iter_advance(struct hashmultimap_iter *iter, size_t steps); +_Bool hmm_iter_rewind(struct hashmultimap_iter *iter, size_t steps); +_Bool hmm_iter_go_to(struct hashmultimap_iter *iter, size_t index); +size_t hmm_iter_key(struct hashmultimap_iter *iter); +size_t hmm_iter_value(struct hashmultimap_iter *iter); +size_t *hmm_iter_rvalue(struct hashmultimap_iter *iter); +size_t hmm_iter_index(struct hashmultimap_iter *iter); +_Bool hmm_to_string(struct hashmultimap *_map_, FILE *fptr); +_Bool hmm_print(struct hashmultimap *_map_, FILE *fptr, const char *start, const char *separator, const char *end, + const char *key_val_sep); + +#endif /* CMC_CMC_HASHMULTIMAP_TEST_H */ diff --git a/tests/include/cmc/hashmultiset.h b/tests/include/cmc/hashmultiset.h new file mode 100644 index 0000000..6ab4627 --- /dev/null +++ b/tests/include/cmc/hashmultiset.h @@ -0,0 +1,98 @@ + +#ifndef CMC_CMC_HASHMULTISET_TEST_H +#define CMC_CMC_HASHMULTISET_TEST_H + +#include "macro_collections.h" + +struct hashmultiset +{ + struct hashmultiset_entry *buffer; + size_t capacity; + size_t count; + size_t cardinality; + double load; + int flag; + struct hashmultiset_fval *f_val; + struct cmc_alloc_node *alloc; + struct cmc_callbacks *callbacks; +}; +struct hashmultiset_entry +{ + size_t value; + size_t multiplicity; + size_t dist; + enum cmc_entry_state state; +}; +struct hashmultiset_fval +{ + int (*cmp)(size_t, size_t); + size_t (*cpy)(size_t); + _Bool (*str)(FILE *, size_t); + void (*free)(size_t); + size_t (*hash)(size_t); + int (*pri)(size_t, size_t); +}; +struct hashmultiset *hms_new(size_t capacity, double load, struct hashmultiset_fval *f_val); +struct hashmultiset *hms_new_custom(size_t capacity, double load, struct hashmultiset_fval *f_val, + struct cmc_alloc_node *alloc, struct cmc_callbacks *callbacks); +void hms_clear(struct hashmultiset *_set_); +void hms_free(struct hashmultiset *_set_); +void hms_customize(struct hashmultiset *_set_, struct cmc_alloc_node *alloc, struct cmc_callbacks *callbacks); +_Bool hms_insert(struct hashmultiset *_set_, size_t value); +_Bool hms_insert_many(struct hashmultiset *_set_, size_t value, size_t count); +_Bool hms_update(struct hashmultiset *_set_, size_t value, size_t multiplicity); +_Bool hms_remove(struct hashmultiset *_set_, size_t value); +size_t hms_remove_all(struct hashmultiset *_set_, size_t value); +_Bool hms_max(struct hashmultiset *_set_, size_t *value); +_Bool hms_min(struct hashmultiset *_set_, size_t *value); +size_t hms_multiplicity_of(struct hashmultiset *_set_, size_t value); +_Bool hms_contains(struct hashmultiset *_set_, size_t value); +_Bool hms_empty(struct hashmultiset *_set_); +_Bool hms_full(struct hashmultiset *_set_); +size_t hms_count(struct hashmultiset *_set_); +size_t hms_cardinality(struct hashmultiset *_set_); +size_t hms_capacity(struct hashmultiset *_set_); +double hms_load(struct hashmultiset *_set_); +int hms_flag(struct hashmultiset *_set_); +_Bool hms_resize(struct hashmultiset *_set_, size_t capacity); +struct hashmultiset *hms_copy_of(struct hashmultiset *_set_); +_Bool hms_equals(struct hashmultiset *_set1_, struct hashmultiset *_set2_); +struct hashmultiset_iter +{ + struct hashmultiset *target; + size_t cursor; + size_t index; + size_t first; + size_t last; + _Bool start; + _Bool end; +}; +struct hashmultiset_iter hms_iter_start(struct hashmultiset *target); +struct hashmultiset_iter hms_iter_end(struct hashmultiset *target); +_Bool hms_iter_at_start(struct hashmultiset_iter *iter); +_Bool hms_iter_at_end(struct hashmultiset_iter *iter); +_Bool hms_iter_to_start(struct hashmultiset_iter *iter); +_Bool hms_iter_to_end(struct hashmultiset_iter *iter); +_Bool hms_iter_next(struct hashmultiset_iter *iter); +_Bool hms_iter_prev(struct hashmultiset_iter *iter); +_Bool hms_iter_advance(struct hashmultiset_iter *iter, size_t steps); +_Bool hms_iter_rewind(struct hashmultiset_iter *iter, size_t steps); +_Bool hms_iter_go_to(struct hashmultiset_iter *iter, size_t index); +size_t hms_iter_value(struct hashmultiset_iter *iter); +size_t hms_iter_multiplicity(struct hashmultiset_iter *iter); +size_t hms_iter_index(struct hashmultiset_iter *iter); +struct hashmultiset *hms_union(struct hashmultiset *_set1_, struct hashmultiset *_set2_); +struct hashmultiset *hms_intersection(struct hashmultiset *_set1_, struct hashmultiset *_set2_); +struct hashmultiset *hms_difference(struct hashmultiset *_set1_, struct hashmultiset *_set2_); +struct hashmultiset *hms_summation(struct hashmultiset *_set1_, struct hashmultiset *_set2_); +struct hashmultiset *hms_symmetric_difference(struct hashmultiset *_set1_, struct hashmultiset *_set2_); +_Bool hms_is_subset(struct hashmultiset *_set1_, struct hashmultiset *_set2_); +_Bool hms_is_superset(struct hashmultiset *_set1_, struct hashmultiset *_set2_); +_Bool hms_is_proper_subset(struct hashmultiset *_set1_, struct hashmultiset *_set2_); +_Bool hms_is_proper_superset(struct hashmultiset *_set1_, struct hashmultiset *_set2_); +_Bool hms_is_disjointset(struct hashmultiset *_set1_, struct hashmultiset *_set2_); +_Bool hms_to_string(struct hashmultiset *_set_, FILE *fptr); +_Bool hms_print(struct hashmultiset *_set_, FILE *fptr, const char *start, const char *separator, const char *end, + const char *key_val_sep); + +#endif /* CMC_CMC_HASHMULTISET_TEST_H */ diff --git a/tests/include/cmc/hashset.h b/tests/include/cmc/hashset.h new file mode 100644 index 0000000..a9ab75c --- /dev/null +++ b/tests/include/cmc/hashset.h @@ -0,0 +1,88 @@ + +#ifndef CMC_CMC_HASHSET_TEST_H +#define CMC_CMC_HASHSET_TEST_H + +#include "macro_collections.h" + +struct hashset +{ + struct hashset_entry *buffer; + size_t capacity; + size_t count; + double load; + int flag; + struct hashset_fval *f_val; + struct cmc_alloc_node *alloc; + struct cmc_callbacks *callbacks; +}; +struct hashset_entry +{ + size_t value; + size_t dist; + enum cmc_entry_state state; +}; +struct hashset_fval +{ + int (*cmp)(size_t, size_t); + size_t (*cpy)(size_t); + _Bool (*str)(FILE *, size_t); + void (*free)(size_t); + size_t (*hash)(size_t); + int (*pri)(size_t, size_t); +}; +struct hashset *hs_new(size_t capacity, double load, struct hashset_fval *f_val); +struct hashset *hs_new_custom(size_t capacity, double load, struct hashset_fval *f_val, struct cmc_alloc_node *alloc, + struct cmc_callbacks *callbacks); +void hs_clear(struct hashset *_set_); +void hs_free(struct hashset *_set_); +void hs_customize(struct hashset *_set_, struct cmc_alloc_node *alloc, struct cmc_callbacks *callbacks); +_Bool hs_insert(struct hashset *_set_, size_t value); +_Bool hs_remove(struct hashset *_set_, size_t value); +_Bool hs_max(struct hashset *_set_, size_t *value); +_Bool hs_min(struct hashset *_set_, size_t *value); +_Bool hs_contains(struct hashset *_set_, size_t value); +_Bool hs_empty(struct hashset *_set_); +_Bool hs_full(struct hashset *_set_); +size_t hs_count(struct hashset *_set_); +size_t hs_capacity(struct hashset *_set_); +double hs_load(struct hashset *_set_); +int hs_flag(struct hashset *_set_); +_Bool hs_resize(struct hashset *_set_, size_t capacity); +struct hashset *hs_copy_of(struct hashset *_set_); +_Bool hs_equals(struct hashset *_set1_, struct hashset *_set2_); +struct hashset_iter +{ + struct hashset *target; + size_t cursor; + size_t index; + size_t first; + size_t last; + _Bool start; + _Bool end; +}; +struct hashset_iter hs_iter_start(struct hashset *target); +struct hashset_iter hs_iter_end(struct hashset *target); +_Bool hs_iter_at_start(struct hashset_iter *iter); +_Bool hs_iter_at_end(struct hashset_iter *iter); +_Bool hs_iter_to_start(struct hashset_iter *iter); +_Bool hs_iter_to_end(struct hashset_iter *iter); +_Bool hs_iter_next(struct hashset_iter *iter); +_Bool hs_iter_prev(struct hashset_iter *iter); +_Bool hs_iter_advance(struct hashset_iter *iter, size_t steps); +_Bool hs_iter_rewind(struct hashset_iter *iter, size_t steps); +_Bool hs_iter_go_to(struct hashset_iter *iter, size_t index); +size_t hs_iter_value(struct hashset_iter *iter); +size_t hs_iter_index(struct hashset_iter *iter); +struct hashset *hs_union(struct hashset *_set1_, struct hashset *_set2_); +struct hashset *hs_intersection(struct hashset *_set1_, struct hashset *_set2_); +struct hashset *hs_difference(struct hashset *_set1_, struct hashset *_set2_); +struct hashset *hs_symmetric_difference(struct hashset *_set1_, struct hashset *_set2_); +_Bool hs_is_subset(struct hashset *_set1_, struct hashset *_set2_); +_Bool hs_is_superset(struct hashset *_set1_, struct hashset *_set2_); +_Bool hs_is_proper_subset(struct hashset *_set1_, struct hashset *_set2_); +_Bool hs_is_proper_superset(struct hashset *_set1_, struct hashset *_set2_); +_Bool hs_is_disjointset(struct hashset *_set1_, struct hashset *_set2_); +_Bool hs_to_string(struct hashset *_set_, FILE *fptr); +_Bool hs_print(struct hashset *_set_, FILE *fptr, const char *start, const char *separator, const char *end); + +#endif /* CMC_CMC_HASHSET_TEST_H */ diff --git a/tests/include/cmc/heap.h b/tests/include/cmc/heap.h new file mode 100644 index 0000000..8b062f1 --- /dev/null +++ b/tests/include/cmc/heap.h @@ -0,0 +1,68 @@ + +#ifndef CMC_CMC_HEAP_TEST_H +#define CMC_CMC_HEAP_TEST_H + +#include "macro_collections.h" + +struct heap +{ + size_t *buffer; + size_t capacity; + size_t count; + enum cmc_heap_order HO; + int flag; + struct heap_fval *f_val; + struct cmc_alloc_node *alloc; + struct cmc_callbacks *callbacks; +}; +struct heap_fval +{ + int (*cmp)(size_t, size_t); + size_t (*cpy)(size_t); + _Bool (*str)(FILE *, size_t); + void (*free)(size_t); + size_t (*hash)(size_t); + int (*pri)(size_t, size_t); +}; +struct heap *h_new(size_t capacity, enum cmc_heap_order HO, struct heap_fval *f_val); +struct heap *h_new_custom(size_t capacity, enum cmc_heap_order HO, struct heap_fval *f_val, + struct cmc_alloc_node *alloc, struct cmc_callbacks *callbacks); +void h_clear(struct heap *_heap_); +void h_free(struct heap *_heap_); +void h_customize(struct heap *_heap_, struct cmc_alloc_node *alloc, struct cmc_callbacks *callbacks); +_Bool h_insert(struct heap *_heap_, size_t value); +_Bool h_remove(struct heap *_heap_); +size_t h_peek(struct heap *_heap_); +_Bool h_contains(struct heap *_heap_, size_t value); +_Bool h_empty(struct heap *_heap_); +_Bool h_full(struct heap *_heap_); +size_t h_count(struct heap *_heap_); +size_t h_capacity(struct heap *_heap_); +int h_flag(struct heap *_heap_); +_Bool h_resize(struct heap *_heap_, size_t capacity); +struct heap *h_copy_of(struct heap *_heap_); +_Bool h_equals(struct heap *_heap1_, struct heap *_heap2_); +struct heap_iter +{ + struct heap *target; + size_t cursor; + _Bool start; + _Bool end; +}; +struct heap_iter h_iter_start(struct heap *target); +struct heap_iter h_iter_end(struct heap *target); +_Bool h_iter_at_start(struct heap_iter *iter); +_Bool h_iter_at_end(struct heap_iter *iter); +_Bool h_iter_to_start(struct heap_iter *iter); +_Bool h_iter_to_end(struct heap_iter *iter); +_Bool h_iter_next(struct heap_iter *iter); +_Bool h_iter_prev(struct heap_iter *iter); +_Bool h_iter_advance(struct heap_iter *iter, size_t steps); +_Bool h_iter_rewind(struct heap_iter *iter, size_t steps); +_Bool h_iter_go_to(struct heap_iter *iter, size_t index); +size_t h_iter_value(struct heap_iter *iter); +size_t h_iter_index(struct heap_iter *iter); +_Bool h_to_string(struct heap *_heap_, FILE *fptr); +_Bool h_print(struct heap *_heap_, FILE *fptr, const char *start, const char *separator, const char *end); + +#endif /* CMC_CMC_HEAP_TEST_H */ diff --git a/tests/include/cmc/intervalheap.h b/tests/include/cmc/intervalheap.h new file mode 100644 index 0000000..5bc4fb2 --- /dev/null +++ b/tests/include/cmc/intervalheap.h @@ -0,0 +1,72 @@ + +#ifndef CMC_CMC_INTERVALHEAP_TEST_H +#define CMC_CMC_INTERVALHEAP_TEST_H + +#include "macro_collections.h" + +struct intervalheap +{ + size_t (*buffer)[2]; + size_t capacity; + size_t size; + size_t count; + int flag; + struct intervalheap_fval *f_val; + struct cmc_alloc_node *alloc; + struct cmc_callbacks *callbacks; +}; +struct intervalheap_fval +{ + int (*cmp)(size_t, size_t); + size_t (*cpy)(size_t); + _Bool (*str)(FILE *, size_t); + void (*free)(size_t); + size_t (*hash)(size_t); + int (*pri)(size_t, size_t); +}; +struct intervalheap *ih_new(size_t capacity, struct intervalheap_fval *f_val); +struct intervalheap *ih_new_custom(size_t capacity, struct intervalheap_fval *f_val, struct cmc_alloc_node *alloc, + struct cmc_callbacks *callbacks); +void ih_clear(struct intervalheap *_heap_); +void ih_free(struct intervalheap *_heap_); +void ih_customize(struct intervalheap *_heap_, struct cmc_alloc_node *alloc, struct cmc_callbacks *callbacks); +_Bool ih_insert(struct intervalheap *_heap_, size_t value); +_Bool ih_remove_max(struct intervalheap *_heap_); +_Bool ih_remove_min(struct intervalheap *_heap_); +_Bool ih_update_max(struct intervalheap *_heap_, size_t value); +_Bool ih_update_min(struct intervalheap *_heap_, size_t value); +size_t ih_max(struct intervalheap *_heap_); +size_t ih_min(struct intervalheap *_heap_); +_Bool ih_contains(struct intervalheap *_heap_, size_t value); +_Bool ih_empty(struct intervalheap *_heap_); +_Bool ih_full(struct intervalheap *_heap_); +size_t ih_count(struct intervalheap *_heap_); +size_t ih_capacity(struct intervalheap *_heap_); +int ih_flag(struct intervalheap *_heap_); +_Bool ih_resize(struct intervalheap *_heap_, size_t capacity); +struct intervalheap *ih_copy_of(struct intervalheap *_heap_); +_Bool ih_equals(struct intervalheap *_heap1_, struct intervalheap *_heap2_); +struct intervalheap_iter +{ + struct intervalheap *target; + size_t cursor; + _Bool start; + _Bool end; +}; +struct intervalheap_iter ih_iter_start(struct intervalheap *target); +struct intervalheap_iter ih_iter_end(struct intervalheap *target); +_Bool ih_iter_at_start(struct intervalheap_iter *iter); +_Bool ih_iter_at_end(struct intervalheap_iter *iter); +_Bool ih_iter_to_start(struct intervalheap_iter *iter); +_Bool ih_iter_to_end(struct intervalheap_iter *iter); +_Bool ih_iter_next(struct intervalheap_iter *iter); +_Bool ih_iter_prev(struct intervalheap_iter *iter); +_Bool ih_iter_advance(struct intervalheap_iter *iter, size_t steps); +_Bool ih_iter_rewind(struct intervalheap_iter *iter, size_t steps); +_Bool ih_iter_go_to(struct intervalheap_iter *iter, size_t index); +size_t ih_iter_value(struct intervalheap_iter *iter); +size_t ih_iter_index(struct intervalheap_iter *iter); +_Bool ih_to_string(struct intervalheap *_heap_, FILE *fptr); +_Bool ih_print(struct intervalheap *_heap_, FILE *fptr, const char *start, const char *separator, const char *end); + +#endif /* CMC_CMC_INTERVALHEAP_TEST_H */ diff --git a/tests/include/cmc/linkedlist.h b/tests/include/cmc/linkedlist.h new file mode 100644 index 0000000..c06925d --- /dev/null +++ b/tests/include/cmc/linkedlist.h @@ -0,0 +1,92 @@ + +#ifndef CMC_CMC_LINKEDLIST_TEST_H +#define CMC_CMC_LINKEDLIST_TEST_H + +#include "macro_collections.h" + +struct linkedlist +{ + struct linkedlist_node *head; + struct linkedlist_node *tail; + size_t count; + int flag; + struct linkedlist_fval *f_val; + struct cmc_alloc_node *alloc; + struct cmc_callbacks *callbacks; +}; +struct linkedlist_node +{ + size_t value; + struct linkedlist_node *next; + struct linkedlist_node *prev; +}; +struct linkedlist_fval +{ + int (*cmp)(size_t, size_t); + size_t (*cpy)(size_t); + _Bool (*str)(FILE *, size_t); + void (*free)(size_t); + size_t (*hash)(size_t); + int (*pri)(size_t, size_t); +}; +struct linkedlist *ll_new(struct linkedlist_fval *f_val); +struct linkedlist *ll_new_custom(struct linkedlist_fval *f_val, struct cmc_alloc_node *alloc, + struct cmc_callbacks *callbacks); +void ll_clear(struct linkedlist *_list_); +void ll_free(struct linkedlist *_list_); +void ll_customize(struct linkedlist *_list_, struct cmc_alloc_node *alloc, struct cmc_callbacks *callbacks); +_Bool ll_push_front(struct linkedlist *_list_, size_t value); +_Bool ll_push_at(struct linkedlist *_list_, size_t value, size_t index); +_Bool ll_push_back(struct linkedlist *_list_, size_t value); +_Bool ll_pop_front(struct linkedlist *_list_); +_Bool ll_pop_at(struct linkedlist *_list_, size_t index); +_Bool ll_pop_back(struct linkedlist *_list_); +size_t ll_front(struct linkedlist *_list_); +size_t ll_get(struct linkedlist *_list_, size_t index); +size_t *ll_get_ref(struct linkedlist *_list_, size_t index); +size_t ll_back(struct linkedlist *_list_); +_Bool ll_contains(struct linkedlist *_list_, size_t value); +_Bool ll_empty(struct linkedlist *_list_); +size_t ll_count(struct linkedlist *_list_); +int ll_flag(struct linkedlist *_list_); +struct linkedlist *ll_copy_of(struct linkedlist *_list_); +_Bool ll_equals(struct linkedlist *_list1_, struct linkedlist *_list2_); +struct linkedlist_iter +{ + struct linkedlist *target; + struct linkedlist_node *cursor; + size_t index; + _Bool start; + _Bool end; +}; +struct linkedlist_iter ll_iter_start(struct linkedlist *target); +struct linkedlist_iter ll_iter_end(struct linkedlist *target); +_Bool ll_iter_at_start(struct linkedlist_iter *iter); +_Bool ll_iter_at_end(struct linkedlist_iter *iter); +_Bool ll_iter_to_start(struct linkedlist_iter *iter); +_Bool ll_iter_to_end(struct linkedlist_iter *iter); +_Bool ll_iter_next(struct linkedlist_iter *iter); +_Bool ll_iter_prev(struct linkedlist_iter *iter); +_Bool ll_iter_advance(struct linkedlist_iter *iter, size_t steps); +_Bool ll_iter_rewind(struct linkedlist_iter *iter, size_t steps); +_Bool ll_iter_go_to(struct linkedlist_iter *iter, size_t index); +size_t ll_iter_value(struct linkedlist_iter *iter); +size_t *ll_iter_rvalue(struct linkedlist_iter *iter); +size_t ll_iter_index(struct linkedlist_iter *iter); +struct linkedlist_node *ll_iter_node(struct linkedlist_iter *iter); +struct linkedlist_node *ll_new_node(struct linkedlist *_list_, size_t value); +void ll_free_node(struct linkedlist *_list_, struct linkedlist_node *_node_); +struct linkedlist_node *ll_head(struct linkedlist *_list_); +struct linkedlist_node *ll_get_node(struct linkedlist *_list_, size_t index); +struct linkedlist_node *ll_tail(struct linkedlist *_list_); +_Bool ll_add_next(struct linkedlist *_owner_, struct linkedlist_node *_node_, size_t value); +_Bool ll_add_prev(struct linkedlist *_owner_, struct linkedlist_node *_node_, size_t value); +_Bool ll_del_next(struct linkedlist *_owner_, struct linkedlist_node *_node_); +_Bool ll_del_curr(struct linkedlist *_owner_, struct linkedlist_node *_node_); +_Bool ll_del_prev(struct linkedlist *_owner_, struct linkedlist_node *_node_); +struct linkedlist_node *ll_next_node(struct linkedlist_node *_node_); +struct linkedlist_node *ll_prev_node(struct linkedlist_node *_node_); +_Bool ll_to_string(struct linkedlist *_list_, FILE *fptr); +_Bool ll_print(struct linkedlist *_list_, FILE *fptr, const char *start, const char *separator, const char *end); + +#endif /* CMC_CMC_LINKEDLIST_TEST_H */ diff --git a/tests/include/cmc/list.h b/tests/include/cmc/list.h new file mode 100644 index 0000000..3a1043d --- /dev/null +++ b/tests/include/cmc/list.h @@ -0,0 +1,82 @@ + +#ifndef CMC_CMC_LIST_TEST_H +#define CMC_CMC_LIST_TEST_H + +#include "macro_collections.h" + +struct list +{ + size_t *buffer; + size_t capacity; + size_t count; + int flag; + struct list_fval *f_val; + struct cmc_alloc_node *alloc; + struct cmc_callbacks *callbacks; +}; +struct list_fval +{ + int (*cmp)(size_t, size_t); + size_t (*cpy)(size_t); + _Bool (*str)(FILE *, size_t); + void (*free)(size_t); + size_t (*hash)(size_t); + int (*pri)(size_t, size_t); +}; +struct list *l_new(size_t capacity, struct list_fval *f_val); +struct list *l_new_custom(size_t capacity, struct list_fval *f_val, struct cmc_alloc_node *alloc, + struct cmc_callbacks *callbacks); +void l_clear(struct list *_list_); +void l_free(struct list *_list_); +void l_customize(struct list *_list_, struct cmc_alloc_node *alloc, struct cmc_callbacks *callbacks); +_Bool l_push_front(struct list *_list_, size_t value); +_Bool l_push_at(struct list *_list_, size_t value, size_t index); +_Bool l_push_back(struct list *_list_, size_t value); +_Bool l_pop_front(struct list *_list_); +_Bool l_pop_at(struct list *_list_, size_t index); +_Bool l_pop_back(struct list *_list_); +size_t l_front(struct list *_list_); +size_t l_get(struct list *_list_, size_t index); +size_t *l_get_ref(struct list *_list_, size_t index); +size_t l_back(struct list *_list_); +size_t l_index_of(struct list *_list_, size_t value, _Bool from_start); +_Bool l_contains(struct list *_list_, size_t value); +_Bool l_empty(struct list *_list_); +_Bool l_full(struct list *_list_); +size_t l_count(struct list *_list_); +_Bool l_fits(struct list *_list_, size_t size); +size_t l_capacity(struct list *_list_); +int l_flag(struct list *_list_); +_Bool l_resize(struct list *_list_, size_t capacity); +struct list *l_copy_of(struct list *_list_); +_Bool l_equals(struct list *_list1_, struct list *_list2_); +struct list_iter +{ + struct list *target; + size_t cursor; + _Bool start; + _Bool end; +}; +struct list_iter l_iter_start(struct list *target); +struct list_iter l_iter_end(struct list *target); +_Bool l_iter_at_start(struct list_iter *iter); +_Bool l_iter_at_end(struct list_iter *iter); +_Bool l_iter_to_start(struct list_iter *iter); +_Bool l_iter_to_end(struct list_iter *iter); +_Bool l_iter_next(struct list_iter *iter); +_Bool l_iter_prev(struct list_iter *iter); +_Bool l_iter_advance(struct list_iter *iter, size_t steps); +_Bool l_iter_rewind(struct list_iter *iter, size_t steps); +_Bool l_iter_go_to(struct list_iter *iter, size_t index); +size_t l_iter_value(struct list_iter *iter); +size_t *l_iter_rvalue(struct list_iter *iter); +size_t l_iter_index(struct list_iter *iter); +_Bool l_seq_push_front(struct list *_list_, size_t *values, size_t size); +_Bool l_seq_push_at(struct list *_list_, size_t *values, size_t size, size_t index); +_Bool l_seq_push_back(struct list *_list_, size_t *values, size_t size); +_Bool l_seq_pop_at(struct list *_list_, size_t from, size_t to); +struct list *l_seq_sublist(struct list *_list_, size_t from, size_t to); +_Bool l_to_string(struct list *_list_, FILE *fptr); +_Bool l_print(struct list *_list_, FILE *fptr, const char *start, const char *separator, const char *end); + +#endif /* CMC_CMC_LIST_TEST_H */ diff --git a/tests/include/cmc/queue.h b/tests/include/cmc/queue.h new file mode 100644 index 0000000..33b4904 --- /dev/null +++ b/tests/include/cmc/queue.h @@ -0,0 +1,71 @@ + +#ifndef CMC_CMC_QUEUE_TEST_H +#define CMC_CMC_QUEUE_TEST_H + +#include "macro_collections.h" + +struct queue +{ + size_t *buffer; + size_t capacity; + size_t count; + size_t front; + size_t back; + int flag; + struct queue_fval *f_val; + struct cmc_alloc_node *alloc; + struct cmc_callbacks *callbacks; +}; +struct queue_fval +{ + int (*cmp)(size_t, size_t); + size_t (*cpy)(size_t); + _Bool (*str)(FILE *, size_t); + void (*free)(size_t); + size_t (*hash)(size_t); + int (*pri)(size_t, size_t); +}; +struct queue_iter +{ + struct queue *target; + size_t cursor; + size_t index; + _Bool start; + _Bool end; +}; +struct queue *q_new(size_t capacity, struct queue_fval *f_val); +struct queue *q_new_custom(size_t capacity, struct queue_fval *f_val, struct cmc_alloc_node *alloc, + struct cmc_callbacks *callbacks); +void q_clear(struct queue *_queue_); +void q_free(struct queue *_queue_); +void q_customize(struct queue *_queue_, struct cmc_alloc_node *alloc, struct cmc_callbacks *callbacks); +_Bool q_enqueue(struct queue *_queue_, size_t value); +_Bool q_dequeue(struct queue *_queue_); +size_t q_peek(struct queue *_queue_); +_Bool q_contains(struct queue *_queue_, size_t value); +_Bool q_empty(struct queue *_queue_); +_Bool q_full(struct queue *_queue_); +size_t q_count(struct queue *_queue_); +size_t q_capacity(struct queue *_queue_); +int q_flag(struct queue *_queue_); +_Bool q_resize(struct queue *_queue_, size_t capacity); +struct queue *q_copy_of(struct queue *_queue_); +_Bool q_equals(struct queue *_queue1_, struct queue *_queue2_); +struct queue_iter q_iter_start(struct queue *target); +struct queue_iter q_iter_end(struct queue *target); +_Bool q_iter_at_start(struct queue_iter *iter); +_Bool q_iter_at_end(struct queue_iter *iter); +_Bool q_iter_to_start(struct queue_iter *iter); +_Bool q_iter_to_end(struct queue_iter *iter); +_Bool q_iter_next(struct queue_iter *iter); +_Bool q_iter_prev(struct queue_iter *iter); +_Bool q_iter_advance(struct queue_iter *iter, size_t steps); +_Bool q_iter_rewind(struct queue_iter *iter, size_t steps); +_Bool q_iter_go_to(struct queue_iter *iter, size_t index); +size_t q_iter_value(struct queue_iter *iter); +size_t *q_iter_rvalue(struct queue_iter *iter); +size_t q_iter_index(struct queue_iter *iter); +_Bool q_to_string(struct queue *_queue_, FILE *fptr); +_Bool q_print(struct queue *_queue_, FILE *fptr, const char *start, const char *separator, const char *end); + +#endif /* CMC_CMC_QUEUE_TEST_H */ diff --git a/tests/include/cmc/sortedlist.h b/tests/include/cmc/sortedlist.h new file mode 100644 index 0000000..a34b155 --- /dev/null +++ b/tests/include/cmc/sortedlist.h @@ -0,0 +1,72 @@ + +#ifndef CMC_CMC_SORTEDLIST_TEST_H +#define CMC_CMC_SORTEDLIST_TEST_H + +#include "macro_collections.h" + +struct sortedlist +{ + size_t *buffer; + size_t capacity; + size_t count; + _Bool is_sorted; + int flag; + struct sortedlist_fval *f_val; + struct cmc_alloc_node *alloc; + struct cmc_callbacks *callbacks; +}; +struct sortedlist_fval +{ + int (*cmp)(size_t, size_t); + size_t (*cpy)(size_t); + _Bool (*str)(FILE *, size_t); + void (*free)(size_t); + size_t (*hash)(size_t); + int (*pri)(size_t, size_t); +}; +struct sortedlist *sl_new(size_t capacity, struct sortedlist_fval *f_val); +struct sortedlist *sl_new_custom(size_t capacity, struct sortedlist_fval *f_val, struct cmc_alloc_node *alloc, + struct cmc_callbacks *callbacks); +void sl_clear(struct sortedlist *_list_); +void sl_free(struct sortedlist *_list_); +void sl_customize(struct sortedlist *_list_, struct cmc_alloc_node *alloc, struct cmc_callbacks *callbacks); +_Bool sl_insert(struct sortedlist *_list_, size_t value); +_Bool sl_remove(struct sortedlist *_list_, size_t index); +size_t sl_max(struct sortedlist *_list_); +size_t sl_min(struct sortedlist *_list_); +size_t sl_get(struct sortedlist *_list_, size_t index); +size_t sl_index_of(struct sortedlist *_list_, size_t value, _Bool from_start); +_Bool sl_contains(struct sortedlist *_list_, size_t value); +_Bool sl_empty(struct sortedlist *_list_); +_Bool sl_full(struct sortedlist *_list_); +size_t sl_count(struct sortedlist *_list_); +size_t sl_capacity(struct sortedlist *_list_); +int sl_flag(struct sortedlist *_list_); +_Bool sl_resize(struct sortedlist *_list_, size_t capacity); +void sl_sort(struct sortedlist *_list_); +struct sortedlist *sl_copy_of(struct sortedlist *_list_); +_Bool sl_equals(struct sortedlist *_list1_, struct sortedlist *_list2_); +struct sortedlist_iter +{ + struct sortedlist *target; + size_t cursor; + _Bool start; + _Bool end; +}; +struct sortedlist_iter sl_iter_start(struct sortedlist *target); +struct sortedlist_iter sl_iter_end(struct sortedlist *target); +_Bool sl_iter_at_start(struct sortedlist_iter *iter); +_Bool sl_iter_at_end(struct sortedlist_iter *iter); +_Bool sl_iter_to_start(struct sortedlist_iter *iter); +_Bool sl_iter_to_end(struct sortedlist_iter *iter); +_Bool sl_iter_next(struct sortedlist_iter *iter); +_Bool sl_iter_prev(struct sortedlist_iter *iter); +_Bool sl_iter_advance(struct sortedlist_iter *iter, size_t steps); +_Bool sl_iter_rewind(struct sortedlist_iter *iter, size_t steps); +_Bool sl_iter_go_to(struct sortedlist_iter *iter, size_t index); +size_t sl_iter_value(struct sortedlist_iter *iter); +size_t sl_iter_index(struct sortedlist_iter *iter); +_Bool sl_to_string(struct sortedlist *_list_, FILE *fptr); +_Bool sl_print(struct sortedlist *_list_, FILE *fptr, const char *start, const char *separator, const char *end); + +#endif /* CMC_CMC_SORTEDLIST_TEST_H */ diff --git a/tests/include/cmc/stack.h b/tests/include/cmc/stack.h new file mode 100644 index 0000000..6f510d0 --- /dev/null +++ b/tests/include/cmc/stack.h @@ -0,0 +1,68 @@ + +#ifndef CMC_CMC_STACK_TEST_H +#define CMC_CMC_STACK_TEST_H + +#include "macro_collections.h" + +struct stack +{ + size_t *buffer; + size_t capacity; + size_t count; + int flag; + struct stack_fval *f_val; + struct cmc_alloc_node *alloc; + struct cmc_callbacks *callbacks; +}; +struct stack_fval +{ + int (*cmp)(size_t, size_t); + size_t (*cpy)(size_t); + _Bool (*str)(FILE *, size_t); + void (*free)(size_t); + size_t (*hash)(size_t); + int (*pri)(size_t, size_t); +}; +struct stack *s_new(size_t capacity, struct stack_fval *f_val); +struct stack *s_new_custom(size_t capacity, struct stack_fval *f_val, struct cmc_alloc_node *alloc, + struct cmc_callbacks *callbacks); +void s_clear(struct stack *_stack_); +void s_free(struct stack *_stack_); +void s_customize(struct stack *_stack_, struct cmc_alloc_node *alloc, struct cmc_callbacks *callbacks); +_Bool s_push(struct stack *_stack_, size_t value); +_Bool s_pop(struct stack *_stack_); +size_t s_top(struct stack *_stack_); +_Bool s_contains(struct stack *_stack_, size_t value); +_Bool s_empty(struct stack *_stack_); +_Bool s_full(struct stack *_stack_); +size_t s_count(struct stack *_stack_); +size_t s_capacity(struct stack *_stack_); +int s_flag(struct stack *_stack_); +_Bool s_resize(struct stack *_stack_, size_t capacity); +struct stack *s_copy_of(struct stack *_stack_); +_Bool s_equals(struct stack *_stack1_, struct stack *_stack2_); +struct stack_iter +{ + struct stack *target; + size_t cursor; + _Bool start; + _Bool end; +}; +struct stack_iter s_iter_start(struct stack *target); +struct stack_iter s_iter_end(struct stack *target); +_Bool s_iter_at_start(struct stack_iter *iter); +_Bool s_iter_at_end(struct stack_iter *iter); +_Bool s_iter_to_start(struct stack_iter *iter); +_Bool s_iter_to_end(struct stack_iter *iter); +_Bool s_iter_next(struct stack_iter *iter); +_Bool s_iter_prev(struct stack_iter *iter); +_Bool s_iter_advance(struct stack_iter *iter, size_t steps); +_Bool s_iter_rewind(struct stack_iter *iter, size_t steps); +_Bool s_iter_go_to(struct stack_iter *iter, size_t index); +size_t s_iter_value(struct stack_iter *iter); +size_t *s_iter_rvalue(struct stack_iter *iter); +size_t s_iter_index(struct stack_iter *iter); +_Bool s_to_string(struct stack *_stack_, FILE *fptr); +_Bool s_print(struct stack *_stack_, FILE *fptr, const char *start, const char *separator, const char *end); + +#endif /* CMC_CMC_STACK_TEST_H */ diff --git a/tests/include/cmc/treemap.h b/tests/include/cmc/treemap.h new file mode 100644 index 0000000..005ad91 --- /dev/null +++ b/tests/include/cmc/treemap.h @@ -0,0 +1,92 @@ + +#ifndef CMC_CMC_TREEMAP_TEST_H +#define CMC_CMC_TREEMAP_TEST_H + +#include "macro_collections.h" + +struct treemap +{ + struct treemap_node *root; + size_t count; + int flag; + struct treemap_fkey *f_key; + struct treemap_fval *f_val; + struct cmc_alloc_node *alloc; + struct cmc_callbacks *callbacks; +}; +struct treemap_node +{ + size_t key; + size_t value; + unsigned char height; + struct treemap_node *right; + struct treemap_node *left; + struct treemap_node *parent; +}; +struct treemap_fkey +{ + int (*cmp)(size_t, size_t); + size_t (*cpy)(size_t); + _Bool (*str)(FILE *, size_t); + void (*free)(size_t); + size_t (*hash)(size_t); + int (*pri)(size_t, size_t); +}; +struct treemap_fval +{ + int (*cmp)(size_t, size_t); + size_t (*cpy)(size_t); + _Bool (*str)(FILE *, size_t); + void (*free)(size_t); + size_t (*hash)(size_t); + int (*pri)(size_t, size_t); +}; +struct treemap *tm_new(struct treemap_fkey *f_key, struct treemap_fval *f_val); +struct treemap *tm_new_custom(struct treemap_fkey *f_key, struct treemap_fval *f_val, struct cmc_alloc_node *alloc, + struct cmc_callbacks *callbacks); +void tm_clear(struct treemap *_map_); +void tm_free(struct treemap *_map_); +void tm_customize(struct treemap *_map_, struct cmc_alloc_node *alloc, struct cmc_callbacks *callbacks); +_Bool tm_insert(struct treemap *_map_, size_t key, size_t value); +_Bool tm_update(struct treemap *_map_, size_t key, size_t new_value, size_t *old_value); +_Bool tm_remove(struct treemap *_map_, size_t key, size_t *out_value); +_Bool tm_max(struct treemap *_map_, size_t *key, size_t *value); +_Bool tm_min(struct treemap *_map_, size_t *key, size_t *value); +size_t tm_get(struct treemap *_map_, size_t key); +size_t *tm_get_ref(struct treemap *_map_, size_t key); +_Bool tm_contains(struct treemap *_map_, size_t key); +_Bool tm_empty(struct treemap *_map_); +size_t tm_count(struct treemap *_map_); +int tm_flag(struct treemap *_map_); +struct treemap *tm_copy_of(struct treemap *_map_); +_Bool tm_equals(struct treemap *_map1_, struct treemap *_map2_); +struct treemap_iter +{ + struct treemap *target; + struct treemap_node *cursor; + struct treemap_node *first; + struct treemap_node *last; + size_t index; + _Bool start; + _Bool end; +}; +struct treemap_iter tm_iter_start(struct treemap *target); +struct treemap_iter tm_iter_end(struct treemap *target); +_Bool tm_iter_at_start(struct treemap_iter *iter); +_Bool tm_iter_at_end(struct treemap_iter *iter); +_Bool tm_iter_to_start(struct treemap_iter *iter); +_Bool tm_iter_to_end(struct treemap_iter *iter); +_Bool tm_iter_next(struct treemap_iter *iter); +_Bool tm_iter_prev(struct treemap_iter *iter); +_Bool tm_iter_advance(struct treemap_iter *iter, size_t steps); +_Bool tm_iter_rewind(struct treemap_iter *iter, size_t steps); +_Bool tm_iter_go_to(struct treemap_iter *iter, size_t index); +size_t tm_iter_key(struct treemap_iter *iter); +size_t tm_iter_value(struct treemap_iter *iter); +size_t *tm_iter_rvalue(struct treemap_iter *iter); +size_t tm_iter_index(struct treemap_iter *iter); +_Bool tm_to_string(struct treemap *_map_, FILE *fptr); +_Bool tm_print(struct treemap *_map_, FILE *fptr, const char *start, const char *separator, const char *end, + const char *key_val_sep); + +#endif /* CMC_CMC_TREEMAP_TEST_H */ diff --git a/tests/include/cmc/treeset.h b/tests/include/cmc/treeset.h new file mode 100644 index 0000000..432f272 --- /dev/null +++ b/tests/include/cmc/treeset.h @@ -0,0 +1,84 @@ + +#ifndef CMC_CMC_TREESET_TEST_H +#define CMC_CMC_TREESET_TEST_H + +#include "macro_collections.h" + +struct treeset +{ + struct treeset_node *root; + size_t count; + int flag; + struct treeset_fval *f_val; + struct cmc_alloc_node *alloc; + struct cmc_callbacks *callbacks; +}; +struct treeset_node +{ + size_t value; + unsigned char height; + struct treeset_node *right; + struct treeset_node *left; + struct treeset_node *parent; +}; +struct treeset_fval +{ + int (*cmp)(size_t, size_t); + size_t (*cpy)(size_t); + _Bool (*str)(FILE *, size_t); + void (*free)(size_t); + size_t (*hash)(size_t); + int (*pri)(size_t, size_t); +}; +struct treeset_iter +{ + struct treeset *target; + struct treeset_node *cursor; + struct treeset_node *first; + struct treeset_node *last; + size_t index; + _Bool start; + _Bool end; +}; +struct treeset *ts_new(struct treeset_fval *f_val); +struct treeset *ts_new_custom(struct treeset_fval *f_val, struct cmc_alloc_node *alloc, + struct cmc_callbacks *callbacks); +void ts_clear(struct treeset *_set_); +void ts_free(struct treeset *_set_); +void ts_customize(struct treeset *_set_, struct cmc_alloc_node *alloc, struct cmc_callbacks *callbacks); +_Bool ts_insert(struct treeset *_set_, size_t value); +_Bool ts_remove(struct treeset *_set_, size_t value); +_Bool ts_max(struct treeset *_set_, size_t *value); +_Bool ts_min(struct treeset *_set_, size_t *value); +_Bool ts_contains(struct treeset *_set_, size_t value); +_Bool ts_empty(struct treeset *_set_); +size_t ts_count(struct treeset *_set_); +int ts_flag(struct treeset *_set_); +struct treeset *ts_copy_of(struct treeset *_set_); +_Bool ts_equals(struct treeset *_set1_, struct treeset *_set2_); +struct treeset *ts_union(struct treeset *_set1_, struct treeset *_set2_); +struct treeset *ts_intersection(struct treeset *_set1_, struct treeset *_set2_); +struct treeset *ts_difference(struct treeset *_set1_, struct treeset *_set2_); +struct treeset *ts_symmetric_difference(struct treeset *_set1_, struct treeset *_set2_); +_Bool ts_is_subset(struct treeset *_set1_, struct treeset *_set2_); +_Bool ts_is_superset(struct treeset *_set1_, struct treeset *_set2_); +_Bool ts_is_proper_subset(struct treeset *_set1_, struct treeset *_set2_); +_Bool ts_is_proper_superset(struct treeset *_set1_, struct treeset *_set2_); +_Bool ts_is_disjointset(struct treeset *_set1_, struct treeset *_set2_); +struct treeset_iter ts_iter_start(struct treeset *target); +struct treeset_iter ts_iter_end(struct treeset *target); +_Bool ts_iter_at_start(struct treeset_iter *iter); +_Bool ts_iter_at_end(struct treeset_iter *iter); +_Bool ts_iter_to_start(struct treeset_iter *iter); +_Bool ts_iter_to_end(struct treeset_iter *iter); +_Bool ts_iter_next(struct treeset_iter *iter); +_Bool ts_iter_prev(struct treeset_iter *iter); +_Bool ts_iter_advance(struct treeset_iter *iter, size_t steps); +_Bool ts_iter_rewind(struct treeset_iter *iter, size_t steps); +_Bool ts_iter_go_to(struct treeset_iter *iter, size_t index); +size_t ts_iter_value(struct treeset_iter *iter); +size_t ts_iter_index(struct treeset_iter *iter); +_Bool ts_to_string(struct treeset *_set_, FILE *fptr); +_Bool ts_print(struct treeset *_set_, FILE *fptr, const char *start, const char *separator, const char *end); + +#endif /* CMC_CMC_TREESET_TEST_H */ diff --git a/tests/main.c b/tests/main.c new file mode 100644 index 0000000..51de592 --- /dev/null +++ b/tests/main.c @@ -0,0 +1,102 @@ +#include +#include + +#include "unt/cmc/bitset.h" +#include "unt/cmc/deque.h" +#include "unt/cmc/hashbidimap.h" +#include "unt/cmc/hashmap.h" +#include "unt/cmc/hashmultimap.h" +#include "unt/cmc/hashmultiset.h" +#include "unt/cmc/hashset.h" +#include "unt/cmc/heap.h" +#include "unt/cmc/intervalheap.h" +#include "unt/cmc/linkedlist.h" +#include "unt/cmc/list.h" +#include "unt/cmc/queue.h" +#include "unt/cmc/sortedlist.h" +#include "unt/cmc/stack.h" +#include "unt/cmc/treemap.h" +#include "unt/cmc/treeset.h" + +#include "unt/utl/foreach.h" + +#include "utl/timer.h" +#include "utl/assert.h" + +#include "./unt/utl.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) +{ + // clang-format off + printf(" +---------------------------------------------------------------+\n"); + printf(" | C Macro Collections Library |\n"); + printf(" | |\n"); + printf(" | Test Suite |\n"); + printf(" | |\n"); + printf(" | https://github.com/LeoVen/C-Macro-Collections |\n"); + printf(" | Leonardo Vencovsky (leonardo.vencovsky@gmail.com) |\n"); + printf(" +---------------------------------------------------------------+\n\n"); + // clang-format on + + struct cmc_timer timer; + + cmc_timer_start(timer); + uintmax_t tests = 0, units = 0; + + cmc_run(CMCBitSet, units, tests); + cmc_run(CMCBitSetIter, units, tests); + cmc_run(CMCDeque, units, tests); + cmc_run(CMCDequeIter, units, tests); + cmc_run(CMCHashBidiMap, units, tests); + cmc_run(CMCHashBidiMapIter, units, tests); + cmc_run(CMCHashMap, units, tests); + cmc_run(CMCHashMapIter, units, tests); + cmc_run(CMCHashMultiMap, units, tests); + cmc_run(CMCHashMultiMapIter, units, tests); + cmc_run(CMCHashMultiSet, units, tests); + cmc_run(CMCHashMultiSetIter, units, tests); + cmc_run(CMCHashSet, units, tests); + cmc_run(CMCHashSetIter, units, tests); + cmc_run(CMCHeap, units, tests); + cmc_run(CMCHeapIter, units, tests); + cmc_run(CMCIntervalHeap, units, tests); + cmc_run(CMCIntervalHeapIter, units, tests); + cmc_run(CMCLinkedList, units, tests); + cmc_run(CMCLinkedListIter, units, tests); + cmc_run(CMCList, units, tests); + cmc_run(CMCListIter, units, tests); + cmc_run(CMCQueue, units, tests); + cmc_run(CMCQueueIter, units, tests); + cmc_run(CMCSortedList, units, tests); + cmc_run(CMCSortedListIter, units, tests); + cmc_run(CMCStack, units, tests); + cmc_run(CMCStackIter, units, tests); + cmc_run(CMCTreeMap, units, tests); + cmc_run(CMCTreeMapIter, units, tests); + cmc_run(CMCTreeSet, units, tests); + cmc_run(CMCTreeSetIter, units, tests); + + cmc_run(ForEach, units, tests); + + cmc_timer_stop(timer); + + 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; +} diff --git a/tests/main/Makefile b/tests/main/Makefile deleted file mode 100644 index f207ef3..0000000 --- a/tests/main/Makefile +++ /dev/null @@ -1,107 +0,0 @@ -CC = gcc -CFLAGS = -std=c11 -Wall -Wextra -CFLAGS += -Wno-missing-braces -DBFLAGS = -g3 -CVFLAGS = --coverage -O0 -INCLUDE = ../../src/ -UNIT = ./unt - -main: FORCE - $(CC) main.c -o main.exe $(CFLAGS) $(CVFLAGS) -I $(INCLUDE) -DCMC_TEST_COLOR - ./main.exe - gcov ./main.c - -nocov: FORCE - $(CC) main.c -o main.exe $(CFLAGS) -I $(INCLUDE) -DCMC_TEST_COLOR - ./main.exe - rm *.exe - -bare: FORCE - $(CC) main.c -o main.exe $(CFLAGS) -I $(INCLUDE) - ./main.exe - rm *.exe - -debug: FORCE - $(CC) main.c -o main.exe $(CFLAGS) -I $(INCLUDE) -DCMC_TEST_COLOR $(DBFLAGS) - -valgrind: debug - valgrind --leak-check=full ./main.exe - -all: bitset deque hashbidimap hashmap hashmultimap hashmultiset hashset heap intervalheap linkedlist list queue sortedlist stack treemap treeset foreach - rm ./main.exe - -bitset: $(UNIT)/bitset.c $(INCLUDE)/cmc/bitset.h - $(CC) $^ -o main.exe -I $(INCLUDE) -DCMC_TEST_MAIN -DCMC_TEST_COLOR -DCMC_BITSET_WORD_TYPE=uint8_t - ./main.exe - $(CC) $^ -o main.exe -I $(INCLUDE) -DCMC_TEST_MAIN -DCMC_TEST_COLOR -DCMC_BITSET_WORD_TYPE=uint16_t - ./main.exe - $(CC) $^ -o main.exe -I $(INCLUDE) -DCMC_TEST_MAIN -DCMC_TEST_COLOR -DCMC_BITSET_WORD_TYPE=uint32_t - ./main.exe - $(CC) $^ -o main.exe -I $(INCLUDE) -DCMC_TEST_MAIN -DCMC_TEST_COLOR -DCMC_BITSET_WORD_TYPE=uint64_t - ./main.exe - -deque: $(UNIT)/deque.c $(INCLUDE)/cmc/deque.h - $(CC) $^ -o main.exe -I $(INCLUDE) -DCMC_TEST_MAIN -DCMC_TEST_COLOR - ./main.exe - -hashbidimap: $(UNIT)/hashbidimap.c $(INCLUDE)/cmc/hashbidimap.h - $(CC) $^ -o main.exe -I $(INCLUDE) -DCMC_TEST_MAIN -DCMC_TEST_COLOR - ./main.exe - -hashmap: $(UNIT)/hashmap.c $(INCLUDE)/cmc/hashmap.h - $(CC) $^ -o main.exe -I $(INCLUDE) -DCMC_TEST_MAIN -DCMC_TEST_COLOR - ./main.exe - -hashmultimap: $(UNIT)/hashmultimap.c $(INCLUDE)/cmc/hashmultimap.h - $(CC) $^ -o main.exe -I $(INCLUDE) -DCMC_TEST_MAIN -DCMC_TEST_COLOR - ./main.exe - -hashmultiset: $(UNIT)/hashmultiset.c $(INCLUDE)/cmc/hashmultiset.h - $(CC) $^ -o main.exe -I $(INCLUDE) -DCMC_TEST_MAIN -DCMC_TEST_COLOR - ./main.exe - -hashset: $(UNIT)/hashset.c $(INCLUDE)/cmc/hashset.h - $(CC) $^ -o main.exe -I $(INCLUDE) -DCMC_TEST_MAIN -DCMC_TEST_COLOR - ./main.exe - -heap: $(UNIT)/heap.c $(INCLUDE)/cmc/heap.h - $(CC) $^ -o main.exe -I $(INCLUDE) -DCMC_TEST_MAIN -DCMC_TEST_COLOR - ./main.exe - -intervalheap: $(UNIT)/intervalheap.c $(INCLUDE)/cmc/intervalheap.h - $(CC) $^ -o main.exe -I $(INCLUDE) -DCMC_TEST_MAIN -DCMC_TEST_COLOR - ./main.exe - -linkedlist: $(UNIT)/linkedlist.c $(INCLUDE)/cmc/linkedlist.h - $(CC) $^ -o main.exe -I $(INCLUDE) -DCMC_TEST_MAIN -DCMC_TEST_COLOR - ./main.exe - -list: $(UNIT)/list.c $(INCLUDE)/cmc/list.h - $(CC) $^ -o main.exe -I $(INCLUDE) -DCMC_TEST_MAIN -DCMC_TEST_COLOR - ./main.exe - -queue: $(UNIT)/queue.c $(INCLUDE)/cmc/queue.h - $(CC) $^ -o main.exe -I $(INCLUDE) -DCMC_TEST_MAIN -DCMC_TEST_COLOR - ./main.exe - -sortedlist: $(UNIT)/sortedlist.c $(INCLUDE)/cmc/sortedlist.h - $(CC) $^ -o main.exe -I $(INCLUDE) -DCMC_TEST_MAIN -DCMC_TEST_COLOR - ./main.exe - -stack: $(UNIT)/stack.c $(INCLUDE)/cmc/stack.h - $(CC) $^ -o main.exe -I $(INCLUDE) -DCMC_TEST_MAIN -DCMC_TEST_COLOR - ./main.exe - -treemap: $(UNIT)/treemap.c $(INCLUDE)/cmc/treemap.h - $(CC) $^ -o main.exe -I $(INCLUDE) -DCMC_TEST_MAIN -DCMC_TEST_COLOR - ./main.exe - -treeset: $(UNIT)/treeset.c $(INCLUDE)/cmc/treeset.h - $(CC) $^ -o main.exe -I $(INCLUDE) -DCMC_TEST_MAIN -DCMC_TEST_COLOR - ./main.exe - -foreach: $(UNIT)/foreach.c $(INCLUDE)/utl/foreach.h - $(CC) $^ -o main.exe -I $(INCLUDE) -DCMC_TEST_MAIN -DCMC_TEST_COLOR - ./main.exe - -FORCE: diff --git a/tests/main/README.md b/tests/main/README.md deleted file mode 100644 index 9d14b3e..0000000 --- a/tests/main/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# main - -This folder hosts the main tests for the C Macro Collections Library. diff --git a/tests/main/main.c b/tests/main/main.c deleted file mode 100644 index 0f00641..0000000 --- a/tests/main/main.c +++ /dev/null @@ -1,96 +0,0 @@ -#include "utl/timer.h" - -#include "unt/bitset.c" -#include "unt/deque.c" -#include "unt/hashbidimap.c" -#include "unt/hashmap.c" -#include "unt/hashmultimap.c" -#include "unt/hashmultiset.c" -#include "unt/hashset.c" -#include "unt/heap.c" -#include "unt/intervalheap.c" -#include "unt/linkedlist.c" -#include "unt/list.c" -#include "unt/queue.c" -#include "unt/sortedlist.c" -#include "unt/stack.c" -#include "unt/treemap.c" -#include "unt/treeset.c" - -#include "unt/foreach.c" - -#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) -{ - // clang-format off - printf(" +---------------------------------------------------------------+\n"); - printf(" | C Macro Collections Library |\n"); - printf(" | |\n"); - printf(" | Test Suite |\n"); - printf(" | |\n"); - printf(" | https://github.com/LeoVen/C-Macro-Collections |\n"); - printf(" | Leonardo Vencovsky (leonardo.vencovsky@gmail.com) |\n"); - printf(" +---------------------------------------------------------------+\n\n"); - // clang-format on - - struct cmc_timer timer; - - cmc_timer_start(timer); - uintmax_t tests = 0, units = 0; - - cmc_run(BitSet, units, tests); - cmc_run(BitSetIter, units, tests); - cmc_run(Deque, units, tests); - cmc_run(DequeIter, units, tests); - cmc_run(HashBidiMap, units, tests); - cmc_run(HashBidiMapIter, units, tests); - cmc_run(HashMap, units, tests); - cmc_run(HashMapIter, units, tests); - cmc_run(HashMultiMap, units, tests); - cmc_run(HashMultiMapIter, units, tests); - cmc_run(HashMultiSet, units, tests); - cmc_run(HashMultiSetIter, units, tests); - cmc_run(HashSet, units, tests); - cmc_run(HashSetIter, units, tests); - cmc_run(Heap, units, tests); - cmc_run(HeapIter, units, tests); - cmc_run(IntervalHeap, units, tests); - cmc_run(IntervalHeapIter, units, tests); - cmc_run(LinkedList, units, tests); - cmc_run(LinkedListIter, units, tests); - cmc_run(List, units, tests); - cmc_run(ListIter, units, tests); - cmc_run(Queue, units, tests); - cmc_run(QueueIter, units, tests); - cmc_run(SortedList, units, tests); - cmc_run(SortedListIter, units, tests); - cmc_run(Stack, units, tests); - cmc_run(StackIter, units, tests); - cmc_run(TreeMap, units, tests); - cmc_run(TreeMapIter, units, tests); - cmc_run(TreeSet, units, tests); - cmc_run(TreeSetIter, units, tests); - - cmc_run(ForEach, units, tests); - - cmc_timer_stop(timer); - - 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; -} diff --git a/tests/sep/Makefile b/tests/sep/Makefile deleted file mode 100644 index 089d7b8..0000000 --- a/tests/sep/Makefile +++ /dev/null @@ -1,15 +0,0 @@ -CC = gcc -CFLAGS = -std=c11 -Wall -Wextra -CFLAGS += -Wno-unused -Wno-missing-braces - -main: - $(CC) -c collections.c -o collections.o $(CFLAGS) - $(CC) -c main.c -o main.o $(CFLAGS) - $(CC) collections.o main.o -o sep.exe - ./sep.exe - -clean: - rm *.o - -clear: - rm *.o *.exe diff --git a/tests/sep/collections.c b/tests/sep/collections.c deleted file mode 100644 index 0063216..0000000 --- a/tests/sep/collections.c +++ /dev/null @@ -1,17 +0,0 @@ -#include "collections.h" - -CMC_COLLECTION_GENERATE_SOURCE( BIDIMAP, bm, bmap, int, int) -CMC_COLLECTION_GENERATE_SOURCE( DEQUE, d, deque, /* K */, int) -CMC_COLLECTION_GENERATE_SOURCE( HASHMAP, hm, hmap, int, int) -CMC_COLLECTION_GENERATE_SOURCE( HASHSET, hs, hset, /* K */, int) -CMC_COLLECTION_GENERATE_SOURCE( HEAP, h, heap, /* K */, int) -CMC_COLLECTION_GENERATE_SOURCE(INTERVALHEAP, ih, iheap, /* K */, int) -CMC_COLLECTION_GENERATE_SOURCE( LINKEDLIST, ll, linked, /* K */, int) -CMC_COLLECTION_GENERATE_SOURCE( LIST, l, list, /* K */, int) -CMC_COLLECTION_GENERATE_SOURCE( MULTIMAP, mm, mmap, int, int) -CMC_COLLECTION_GENERATE_SOURCE( MULTISET, ms, mset, /* K */, int) -CMC_COLLECTION_GENERATE_SOURCE( QUEUE, q, queue, /* K */, int) -CMC_COLLECTION_GENERATE_SOURCE( SORTEDLIST, sl, slist, /* K */, int) -CMC_COLLECTION_GENERATE_SOURCE( STACK, s, stack, /* K */, int) -CMC_COLLECTION_GENERATE_SOURCE( TREESET, ts, tset, /* K */, int) -CMC_COLLECTION_GENERATE_SOURCE( TREEMAP, tm, tmap, int, int) diff --git a/tests/sep/collections.h b/tests/sep/collections.h deleted file mode 100644 index 966a307..0000000 --- a/tests/sep/collections.h +++ /dev/null @@ -1,17 +0,0 @@ -#include "../../src/macro_collections.h" - -CMC_COLLECTION_GENERATE_HEADER( BIDIMAP, bm, bmap, int, int) -CMC_COLLECTION_GENERATE_HEADER( DEQUE, d, deque, /* K */, int) -CMC_COLLECTION_GENERATE_HEADER( HASHMAP, hm, hmap, int, int) -CMC_COLLECTION_GENERATE_HEADER( HASHSET, hs, hset, /* K */, int) -CMC_COLLECTION_GENERATE_HEADER( HEAP, h, heap, /* K */, int) -CMC_COLLECTION_GENERATE_HEADER(INTERVALHEAP, ih, iheap, /* K */, int) -CMC_COLLECTION_GENERATE_HEADER( LINKEDLIST, ll, linked, /* K */, int) -CMC_COLLECTION_GENERATE_HEADER( LIST, l, list, /* K */, int) -CMC_COLLECTION_GENERATE_HEADER( MULTIMAP, mm, mmap, int, int) -CMC_COLLECTION_GENERATE_HEADER( MULTISET, ms, mset, /* K */, int) -CMC_COLLECTION_GENERATE_HEADER( QUEUE, q, queue, /* K */, int) -CMC_COLLECTION_GENERATE_HEADER( SORTEDLIST, sl, slist, /* K */, int) -CMC_COLLECTION_GENERATE_HEADER( STACK, s, stack, /* K */, int) -CMC_COLLECTION_GENERATE_HEADER( TREESET, ts, tset, /* K */, int) -CMC_COLLECTION_GENERATE_HEADER( TREEMAP, tm, tmap, int, int) diff --git a/tests/sep/main.c b/tests/sep/main.c deleted file mode 100644 index 350a863..0000000 --- a/tests/sep/main.c +++ /dev/null @@ -1,62 +0,0 @@ -#include "collections.h" -#include - -int intcmp(int a, int b) -{ - return (a > b) - (a < b); -} - -size_t inthash(int t) -{ - size_t a = t; - a += ~(a << 15); - a ^= (a >> 10); - a += (a << 3); - a ^= (a >> 6); - a += ~(a << 11); - a ^= (a >> 16); - return a; -} - -int main(void) -{ - struct bmap *bm = - bm_new_custom(100, 0.7, &(struct bmap_ftab_key){ 0 }, - &(struct bmap_ftab_val){ 0 }, NULL, NULL); - struct deque *d = d_new_custom(100, NULL, NULL); - struct hmap *hm = hm_new_custom(100, 0.6, NULL, NULL, NULL, NULL); - struct hset *hs = hs_new_custom(100, 0.6, NULL, NULL, NULL, NULL); - struct heap *h = h_new_custom(100, cmc_max_heap, NULL, NULL, NULL); - struct iheap *ih = ih_new_custom(100, NULL, NULL, NULL); - struct linked *ll = ll_new_custom(NULL, NULL); - struct list *l = l_new_custom(100, NULL, NULL); - struct mmap *mm = mm_new_custom(100, 0.8, NULL, NULL, NULL, NULL); - struct mset *ms = ms_new_custom(100, 0.6, NULL, NULL, NULL, NULL); - struct queue *q = q_new_custom(100, NULL, NULL); - struct slist *sl = sl_new_custom(100, NULL, NULL, NULL); - struct stack *s = s_new_custom(100, NULL, NULL); - struct tmap *tm = tm_new_custom(NULL, NULL, NULL); - struct tset *ts = ts_new_custom(NULL, NULL, NULL); - - printf("+--------------------------------------------------+\n"); - printf("| Separate Header and Source is Working |\n"); - printf("+--------------------------------------------------+\n"); - - bm_free(bm); - d_free(d, NULL); - hm_free(hm, NULL); - hs_free(hs, NULL); - h_free(h, NULL); - ih_free(ih, NULL); - ll_free(ll, NULL); - l_free(l, NULL); - mm_free(mm, NULL); - ms_free(ms, NULL); - q_free(q, NULL); - sl_free(sl, NULL); - s_free(s, NULL); - tm_free(tm, NULL); - ts_free(ts, NULL); - - return 0; -} diff --git a/tests/main/src/bitset.c b/tests/src/cmc/bitset.c similarity index 83% rename from tests/main/src/bitset.c rename to tests/src/cmc/bitset.c index 6fc38ba..68baf71 100644 --- a/tests/main/src/bitset.c +++ b/tests/src/cmc/bitset.c @@ -1,51 +1,6 @@ -#ifndef CMC_TEST_SRC_BITSET -#define CMC_TEST_SRC_BITSET #include "cmc/bitset.h" -struct bitset -{ - cmc_bitset_word *buffer; - size_t capacity; - int flag; - struct cmc_alloc_node *alloc; - struct cmc_callbacks *callbacks; -}; -struct bitset_iter -{ - struct bitset *target; - size_t cursor; - _Bool start; - _Bool end; -}; -struct bitset *bs_new(size_t n_bits); -struct bitset *bs_new_custom(size_t n_bits, struct cmc_alloc_node *alloc, struct cmc_callbacks *callbacks); -struct bitset bs_init(size_t n_bits); -struct bitset bs_init_custom(size_t n_bits, struct cmc_alloc_node *alloc, struct cmc_callbacks *callbacks); -void bs_free(struct bitset *_bitset_); -void bs_release(struct bitset _bitset_); -void bs_customize(struct bitset *_bitset_, struct cmc_alloc_node *alloc, struct cmc_callbacks *callbacks); -_Bool bs_set(struct bitset *_bitset_, size_t bit_index); -_Bool bs_set_range(struct bitset *_bitset_, size_t from, size_t to); -_Bool bs_clear(struct bitset *_bitset_, size_t bit_index); -_Bool bs_clear_range(struct bitset *_bitset_, size_t from, size_t to); -_Bool bs_flip(struct bitset *_bitset_, size_t bit_index); -_Bool bs_flip_range(struct bitset *_bitset_, size_t from, size_t to); -_Bool bs_put(struct bitset *_bitset_, size_t bit_index, _Bool state); -_Bool bs_put_range(struct bitset *_bitset_, size_t from, size_t to, _Bool state); -_Bool bs_set_all(struct bitset *_bitset_); -_Bool bs_clear_all(struct bitset *_bitset_); -_Bool bs_flip_all(struct bitset *_bitset_); -_Bool bs_get(struct bitset *_bitset_, size_t bit_index); -_Bool bs_resize(struct bitset *_bitset_, size_t n_bits); -static inline size_t bs_bit_to_index(size_t idx) -{ - static const size_t shift = - ((sizeof(cmc_bitset_word) * 8) >> 6) > 0 - ? 6 - : ((sizeof(cmc_bitset_word) * 8) >> 5) > 0 ? 5 : ((sizeof(cmc_bitset_word) * 8) >> 4) > 0 ? 4 : 3; - return idx >> shift; -} _Bool bs_impl_resize(struct bitset *_bitset_, size_t n_bits, _Bool do_resize); struct bitset *bs_new(size_t n_bits) { @@ -53,6 +8,7 @@ struct bitset *bs_new(size_t n_bits) } struct bitset *bs_new_custom(size_t n_bits, struct cmc_alloc_node *alloc, struct cmc_callbacks *callbacks) { + ; if (n_bits < 1) return ((void *)0); if (!alloc) @@ -336,5 +292,3 @@ _Bool bs_impl_resize(struct bitset *_bitset_, size_t n_bits, _Bool do_resize) _bitset_->flag = CMC_FLAG_OK; return 1; } - -#endif /* CMC_TEST_SRC_BITSET */ diff --git a/tests/main/src/deque.c b/tests/src/cmc/deque.c similarity index 83% rename from tests/main/src/deque.c rename to tests/src/cmc/deque.c index dc5f600..ede6e29 100644 --- a/tests/main/src/deque.c +++ b/tests/src/cmc/deque.c @@ -1,78 +1,6 @@ -#ifndef CMC_TEST_SRC_DEQUE -#define CMC_TEST_SRC_DEQUE #include "cmc/deque.h" -struct deque -{ - size_t *buffer; - size_t capacity; - size_t count; - size_t front; - size_t back; - int flag; - struct deque_fval *f_val; - struct cmc_alloc_node *alloc; - struct cmc_callbacks *callbacks; -}; -struct deque_fval -{ - int (*cmp)(size_t, size_t); - size_t (*cpy)(size_t); - _Bool (*str)(FILE *, size_t); - void (*free)(size_t); - size_t (*hash)(size_t); - int (*pri)(size_t, size_t); -}; -struct deque *d_new(size_t capacity, struct deque_fval *f_val); -struct deque *d_new_custom(size_t capacity, struct deque_fval *f_val, struct cmc_alloc_node *alloc, - struct cmc_callbacks *callbacks); -void d_clear(struct deque *_deque_); -void d_free(struct deque *_deque_); -void d_customize(struct deque *_deque_, struct cmc_alloc_node *alloc, struct cmc_callbacks *callbacks); -_Bool d_push_front(struct deque *_deque_, size_t value); -_Bool d_push_back(struct deque *_deque_, size_t value); -_Bool d_pop_front(struct deque *_deque_); -_Bool d_pop_back(struct deque *_deque_); -size_t d_front(struct deque *_deque_); -size_t d_back(struct deque *_deque_); -_Bool d_contains(struct deque *_deque_, size_t value); -_Bool d_empty(struct deque *_deque_); -_Bool d_full(struct deque *_deque_); -size_t d_count(struct deque *_deque_); -size_t d_capacity(struct deque *_deque_); -int d_flag(struct deque *_deque_); -_Bool d_resize(struct deque *_deque_, size_t capacity); -struct deque *d_copy_of(struct deque *_deque_); -_Bool d_equals(struct deque *_deque1_, struct deque *_deque2_); -struct deque d_init(size_t capacity, struct deque_fval *f_val); -struct deque d_init_custom(size_t capacity, struct deque_fval *f_val, struct cmc_alloc_node *alloc, - struct cmc_callbacks *callbacks); -void d_release(struct deque _deque_); -struct deque_iter -{ - struct deque *target; - size_t cursor; - size_t index; - _Bool start; - _Bool end; -}; -struct deque_iter d_iter_start(struct deque *target); -struct deque_iter d_iter_end(struct deque *target); -_Bool d_iter_at_start(struct deque_iter *iter); -_Bool d_iter_at_end(struct deque_iter *iter); -_Bool d_iter_to_start(struct deque_iter *iter); -_Bool d_iter_to_end(struct deque_iter *iter); -_Bool d_iter_next(struct deque_iter *iter); -_Bool d_iter_prev(struct deque_iter *iter); -_Bool d_iter_advance(struct deque_iter *iter, size_t steps); -_Bool d_iter_rewind(struct deque_iter *iter, size_t steps); -_Bool d_iter_go_to(struct deque_iter *iter, size_t index); -size_t d_iter_value(struct deque_iter *iter); -size_t *d_iter_rvalue(struct deque_iter *iter); -size_t d_iter_index(struct deque_iter *iter); -_Bool d_to_string(struct deque *_deque_, FILE *fptr); -_Bool d_print(struct deque *_deque_, FILE *fptr, const char *start, const char *separator, const char *end); struct deque *d_new(size_t capacity, struct deque_fval *f_val) { return d_new_custom(capacity, f_val, ((void *)0), ((void *)0)); @@ -586,5 +514,3 @@ _Bool d_print(struct deque *_deque_, FILE *fptr, const char *start, const char * fprintf(fptr, "%s", end); return 1; } - -#endif /* CMC_TEST_SRC_DEQUE */ diff --git a/tests/main/src/hashbidimap.c b/tests/src/cmc/hashbidimap.c similarity index 86% rename from tests/main/src/hashbidimap.c rename to tests/src/cmc/hashbidimap.c index 42e2c8d..c7a1b70 100644 --- a/tests/main/src/hashbidimap.c +++ b/tests/src/cmc/hashbidimap.c @@ -1,101 +1,6 @@ -#ifndef CMC_TEST_SRC_HASHBIDIMAP -#define CMC_TEST_SRC_HASHBIDIMAP #include "cmc/hashbidimap.h" -struct hashbidimap -{ - struct hashbidimap_entry *(*buffer)[2]; - size_t capacity; - size_t count; - double load; - int flag; - struct hashbidimap_fkey *f_key; - struct hashbidimap_fval *f_val; - struct cmc_alloc_node *alloc; - struct cmc_callbacks *callbacks; - struct hashbidimap_iter (*it_start)(struct hashbidimap *); - struct hashbidimap_iter (*it_end)(struct hashbidimap *); -}; -struct hashbidimap_entry -{ - size_t key; - size_t value; - size_t dist[2]; - struct hashbidimap_entry **ref[2]; -}; -struct hashbidimap_fkey -{ - int (*cmp)(size_t, size_t); - size_t (*cpy)(size_t); - _Bool (*str)(FILE *, size_t); - void (*free)(size_t); - size_t (*hash)(size_t); - int (*pri)(size_t, size_t); -}; -struct hashbidimap_fval -{ - int (*cmp)(size_t, size_t); - size_t (*cpy)(size_t); - _Bool (*str)(FILE *, size_t); - void (*free)(size_t); - size_t (*hash)(size_t); - int (*pri)(size_t, size_t); -}; -struct hashbidimap_iter -{ - struct hashbidimap *target; - size_t cursor; - size_t index; - size_t first; - size_t last; - _Bool start; - _Bool end; -}; -struct hashbidimap *hbm_new(size_t capacity, double load, struct hashbidimap_fkey *f_key, - struct hashbidimap_fval *f_val); -struct hashbidimap *hbm_new_custom(size_t capacity, double load, struct hashbidimap_fkey *f_key, - struct hashbidimap_fval *f_val, struct cmc_alloc_node *alloc, - struct cmc_callbacks *callbacks); -void hbm_clear(struct hashbidimap *_map_); -void hbm_free(struct hashbidimap *_map_); -void hbm_customize(struct hashbidimap *_map_, struct cmc_alloc_node *alloc, struct cmc_callbacks *callbacks); -_Bool hbm_insert(struct hashbidimap *_map_, size_t key, size_t value); -_Bool hbm_update_key(struct hashbidimap *_map_, size_t val, size_t new_key); -_Bool hbm_update_val(struct hashbidimap *_map_, size_t key, size_t new_val); -_Bool hbm_remove_by_key(struct hashbidimap *_map_, size_t key, size_t *out_key, size_t *out_val); -_Bool hbm_remove_by_val(struct hashbidimap *_map_, size_t val, size_t *out_key, size_t *out_val); -size_t hbm_get_key(struct hashbidimap *_map_, size_t val); -size_t hbm_get_val(struct hashbidimap *_map_, size_t key); -_Bool hbm_contains_key(struct hashbidimap *_map_, size_t key); -_Bool hbm_contains_val(struct hashbidimap *_map_, size_t val); -_Bool hbm_empty(struct hashbidimap *_map_); -_Bool hbm_full(struct hashbidimap *_map_); -size_t hbm_count(struct hashbidimap *_map_); -size_t hbm_capacity(struct hashbidimap *_map_); -double hbm_load(struct hashbidimap *_map_); -int hbm_flag(struct hashbidimap *_map_); -_Bool hbm_resize(struct hashbidimap *_map_, size_t capacity); -struct hashbidimap *hbm_copy_of(struct hashbidimap *_map_); -_Bool hbm_equals(struct hashbidimap *_map1_, struct hashbidimap *_map2_); -struct hashbidimap_iter *hbm_iter_new(struct hashbidimap *target); -void hbm_iter_free(struct hashbidimap_iter *iter); -void hbm_iter_init(struct hashbidimap_iter *iter, struct hashbidimap *target); -_Bool hbm_iter_start(struct hashbidimap_iter *iter); -_Bool hbm_iter_end(struct hashbidimap_iter *iter); -void hbm_iter_to_start(struct hashbidimap_iter *iter); -void hbm_iter_to_end(struct hashbidimap_iter *iter); -_Bool hbm_iter_next(struct hashbidimap_iter *iter); -_Bool hbm_iter_prev(struct hashbidimap_iter *iter); -_Bool hbm_iter_advance(struct hashbidimap_iter *iter, size_t steps); -_Bool hbm_iter_rewind(struct hashbidimap_iter *iter, size_t steps); -_Bool hbm_iter_go_to(struct hashbidimap_iter *iter, size_t index); -size_t hbm_iter_key(struct hashbidimap_iter *iter); -size_t hbm_iter_value(struct hashbidimap_iter *iter); -size_t hbm_iter_index(struct hashbidimap_iter *iter); -_Bool hbm_to_string(struct hashbidimap *_map_, FILE *fptr); -_Bool hbm_print(struct hashbidimap *_map_, FILE *fptr, const char *start, const char *separator, const char *end, - const char *key_val_sep); static struct hashbidimap_entry *hbm_impl_new_entry(struct hashbidimap *_map_, size_t key, size_t value); static struct hashbidimap_entry **hbm_impl_get_entry_by_key(struct hashbidimap *_map_, size_t key); static struct hashbidimap_entry **hbm_impl_get_entry_by_val(struct hashbidimap *_map_, size_t val); @@ -949,5 +854,3 @@ _Bool hbm_print(struct hashbidimap *_map_, FILE *fptr, const char *start, const fprintf(fptr, "%s", end); return 1; } - -#endif /* CMC_TEST_SRC_HASHBIDIMAP */ diff --git a/tests/main/src/hashmap.c b/tests/src/cmc/hashmap.c similarity index 85% rename from tests/main/src/hashmap.c rename to tests/src/cmc/hashmap.c index 37980ab..8d49630 100644 --- a/tests/main/src/hashmap.c +++ b/tests/src/cmc/hashmap.c @@ -1,100 +1,6 @@ -#ifndef CMC_TEST_SRC_HASHMAP -#define CMC_TEST_SRC_HASHMAP #include "cmc/hashmap.h" -struct hashmap -{ - struct hashmap_entry *buffer; - size_t capacity; - size_t count; - double load; - int flag; - struct hashmap_fkey *f_key; - struct hashmap_fval *f_val; - struct cmc_alloc_node *alloc; - struct cmc_callbacks *callbacks; -}; -struct hashmap_entry -{ - size_t key; - size_t value; - size_t dist; - enum cmc_entry_state state; -}; -struct hashmap_fkey -{ - int (*cmp)(size_t, size_t); - size_t (*cpy)(size_t); - _Bool (*str)(FILE *, size_t); - void (*free)(size_t); - size_t (*hash)(size_t); - int (*pri)(size_t, size_t); -}; -struct hashmap_fval -{ - int (*cmp)(size_t, size_t); - size_t (*cpy)(size_t); - _Bool (*str)(FILE *, size_t); - void (*free)(size_t); - size_t (*hash)(size_t); - int (*pri)(size_t, size_t); -}; -struct hashmap *hm_new(size_t capacity, double load, struct hashmap_fkey *f_key, struct hashmap_fval *f_val); -struct hashmap *hm_new_custom(size_t capacity, double load, struct hashmap_fkey *f_key, struct hashmap_fval *f_val, - struct cmc_alloc_node *alloc, struct cmc_callbacks *callbacks); -void hm_clear(struct hashmap *_map_); -void hm_free(struct hashmap *_map_); -void hm_customize(struct hashmap *_map_, struct cmc_alloc_node *alloc, struct cmc_callbacks *callbacks); -_Bool hm_insert(struct hashmap *_map_, size_t key, size_t value); -_Bool hm_update(struct hashmap *_map_, size_t key, size_t new_value, size_t *old_value); -_Bool hm_remove(struct hashmap *_map_, size_t key, size_t *out_value); -_Bool hm_max(struct hashmap *_map_, size_t *key, size_t *value); -_Bool hm_min(struct hashmap *_map_, size_t *key, size_t *value); -size_t hm_get(struct hashmap *_map_, size_t key); -size_t *hm_get_ref(struct hashmap *_map_, size_t key); -_Bool hm_contains(struct hashmap *_map_, size_t key); -_Bool hm_empty(struct hashmap *_map_); -_Bool hm_full(struct hashmap *_map_); -size_t hm_count(struct hashmap *_map_); -size_t hm_capacity(struct hashmap *_map_); -double hm_load(struct hashmap *_map_); -int hm_flag(struct hashmap *_map_); -_Bool hm_resize(struct hashmap *_map_, size_t capacity); -struct hashmap *hm_copy_of(struct hashmap *_map_); -_Bool hm_equals(struct hashmap *_map1_, struct hashmap *_map2_); -struct hashmap hm_init(size_t capacity, double load, struct hashmap_fkey *f_key, struct hashmap_fval *f_val); -struct hashmap hm_init_custom(size_t capacity, double load, struct hashmap_fkey *f_key, struct hashmap_fval *f_val, - struct cmc_alloc_node *alloc, struct cmc_callbacks *callbacks); -void hm_release(struct hashmap _map_); -struct hashmap_iter -{ - struct hashmap *target; - size_t cursor; - size_t index; - size_t first; - size_t last; - _Bool start; - _Bool end; -}; -struct hashmap_iter hm_iter_start(struct hashmap *target); -struct hashmap_iter hm_iter_end(struct hashmap *target); -_Bool hm_iter_at_start(struct hashmap_iter *iter); -_Bool hm_iter_at_end(struct hashmap_iter *iter); -_Bool hm_iter_to_start(struct hashmap_iter *iter); -_Bool hm_iter_to_end(struct hashmap_iter *iter); -_Bool hm_iter_next(struct hashmap_iter *iter); -_Bool hm_iter_prev(struct hashmap_iter *iter); -_Bool hm_iter_advance(struct hashmap_iter *iter, size_t steps); -_Bool hm_iter_rewind(struct hashmap_iter *iter, size_t steps); -_Bool hm_iter_go_to(struct hashmap_iter *iter, size_t index); -size_t hm_iter_key(struct hashmap_iter *iter); -size_t hm_iter_value(struct hashmap_iter *iter); -size_t *hm_iter_rvalue(struct hashmap_iter *iter); -size_t hm_iter_index(struct hashmap_iter *iter); -_Bool hm_to_string(struct hashmap *_map_, FILE *fptr); -_Bool hm_print(struct hashmap *_map_, FILE *fptr, const char *start, const char *separator, const char *end, - const char *key_val_sep); static struct hashmap_entry *hm_impl_get_entry(struct hashmap *_map_, size_t key); static size_t hm_impl_calculate_size(size_t required); struct hashmap *hm_new(size_t capacity, double load, struct hashmap_fkey *f_key, struct hashmap_fval *f_val) @@ -884,5 +790,3 @@ _Bool hm_print(struct hashmap *_map_, FILE *fptr, const char *start, const char fprintf(fptr, "%s", end); return 1; } - -#endif /* CMC_TEST_SRC_HASHMAP */ diff --git a/tests/main/src/hashmultimap.c b/tests/src/cmc/hashmultimap.c similarity index 86% rename from tests/main/src/hashmultimap.c rename to tests/src/cmc/hashmultimap.c index 0813264..7450bee 100644 --- a/tests/main/src/hashmultimap.c +++ b/tests/src/cmc/hashmultimap.c @@ -1,102 +1,6 @@ -#ifndef CMC_TEST_SRC_HASHMULTIMAP -#define CMC_TEST_SRC_HASHMULTIMAP #include "cmc/hashmultimap.h" -struct hashmultimap -{ - struct hashmultimap_entry *(*buffer)[2]; - size_t capacity; - size_t count; - double load; - int flag; - struct hashmultimap_fkey *f_key; - struct hashmultimap_fval *f_val; - struct cmc_alloc_node *alloc; - struct cmc_callbacks *callbacks; -}; -struct hashmultimap_entry -{ - size_t key; - size_t value; - struct hashmultimap_entry *next; - struct hashmultimap_entry *prev; -}; -struct hashmultimap_fkey -{ - int (*cmp)(size_t, size_t); - size_t (*cpy)(size_t); - _Bool (*str)(FILE *, size_t); - void (*free)(size_t); - size_t (*hash)(size_t); - int (*pri)(size_t, size_t); -}; -struct hashmultimap_fval -{ - int (*cmp)(size_t, size_t); - size_t (*cpy)(size_t); - _Bool (*str)(FILE *, size_t); - void (*free)(size_t); - size_t (*hash)(size_t); - int (*pri)(size_t, size_t); -}; -struct hashmultimap *hmm_new(size_t capacity, double load, struct hashmultimap_fkey *f_key, - struct hashmultimap_fval *f_val); -struct hashmultimap *hmm_new_custom(size_t capacity, double load, struct hashmultimap_fkey *f_key, - struct hashmultimap_fval *f_val, struct cmc_alloc_node *alloc, - struct cmc_callbacks *callbacks); -void hmm_clear(struct hashmultimap *_map_); -void hmm_free(struct hashmultimap *_map_); -void hmm_customize(struct hashmultimap *_map_, struct cmc_alloc_node *alloc, struct cmc_callbacks *callbacks); -_Bool hmm_insert(struct hashmultimap *_map_, size_t key, size_t value); -_Bool hmm_update(struct hashmultimap *_map_, size_t key, size_t new_value, size_t *old_value); -size_t hmm_update_all(struct hashmultimap *_map_, size_t key, size_t new_value, size_t **old_values); -_Bool hmm_remove(struct hashmultimap *_map_, size_t key, size_t *out_value); -size_t hmm_remove_all(struct hashmultimap *_map_, size_t key, size_t **out_values); -_Bool hmm_max(struct hashmultimap *_map_, size_t *key, size_t *value); -_Bool hmm_min(struct hashmultimap *_map_, size_t *key, size_t *value); -size_t hmm_get(struct hashmultimap *_map_, size_t key); -size_t *hmm_get_ref(struct hashmultimap *_map_, size_t key); -_Bool hmm_contains(struct hashmultimap *_map_, size_t key); -_Bool hmm_empty(struct hashmultimap *_map_); -_Bool hmm_full(struct hashmultimap *_map_); -size_t hmm_count(struct hashmultimap *_map_); -size_t hmm_key_count(struct hashmultimap *_map_, size_t key); -size_t hmm_capacity(struct hashmultimap *_map_); -double hmm_load(struct hashmultimap *_map_); -int hmm_flag(struct hashmultimap *_map_); -_Bool hmm_resize(struct hashmultimap *_map_, size_t capacity); -struct hashmultimap *hmm_copy_of(struct hashmultimap *_map_); -_Bool hmm_equals(struct hashmultimap *_map1_, struct hashmultimap *_map2_); -struct hashmultimap_iter -{ - struct hashmultimap *target; - struct hashmultimap_entry *curr_entry; - size_t cursor; - size_t index; - size_t first; - size_t last; - _Bool start; - _Bool end; -}; -struct hashmultimap_iter hmm_iter_start(struct hashmultimap *target); -struct hashmultimap_iter hmm_iter_end(struct hashmultimap *target); -_Bool hmm_iter_at_start(struct hashmultimap_iter *iter); -_Bool hmm_iter_at_end(struct hashmultimap_iter *iter); -_Bool hmm_iter_to_start(struct hashmultimap_iter *iter); -_Bool hmm_iter_to_end(struct hashmultimap_iter *iter); -_Bool hmm_iter_next(struct hashmultimap_iter *iter); -_Bool hmm_iter_prev(struct hashmultimap_iter *iter); -_Bool hmm_iter_advance(struct hashmultimap_iter *iter, size_t steps); -_Bool hmm_iter_rewind(struct hashmultimap_iter *iter, size_t steps); -_Bool hmm_iter_go_to(struct hashmultimap_iter *iter, size_t index); -size_t hmm_iter_key(struct hashmultimap_iter *iter); -size_t hmm_iter_value(struct hashmultimap_iter *iter); -size_t *hmm_iter_rvalue(struct hashmultimap_iter *iter); -size_t hmm_iter_index(struct hashmultimap_iter *iter); -_Bool hmm_to_string(struct hashmultimap *_map_, FILE *fptr); -_Bool hmm_print(struct hashmultimap *_map_, FILE *fptr, const char *start, const char *separator, const char *end, - const char *key_val_sep); struct hashmultimap_entry *hmm_impl_new_entry(struct hashmultimap *_map_, size_t key, size_t value); struct hashmultimap_entry *hmm_impl_get_entry(struct hashmultimap *_map_, size_t key); size_t hmm_impl_key_count(struct hashmultimap *_map_, size_t key); @@ -1005,5 +909,3 @@ _Bool hmm_print(struct hashmultimap *_map_, FILE *fptr, const char *start, const fprintf(fptr, "%s", end); return 1; } - -#endif /* CMC_TEST_SRC_HASHMULTIMAP */ diff --git a/tests/main/src/hashmultiset.c b/tests/src/cmc/hashmultiset.c similarity index 86% rename from tests/main/src/hashmultiset.c rename to tests/src/cmc/hashmultiset.c index ff0c2a7..e348d67 100644 --- a/tests/main/src/hashmultiset.c +++ b/tests/src/cmc/hashmultiset.c @@ -1,98 +1,6 @@ -#ifndef CMC_TEST_SRC_HASHMULTISET -#define CMC_TEST_SRC_HASHMULTISET #include "cmc/hashmultiset.h" -struct hashmultiset -{ - struct hashmultiset_entry *buffer; - size_t capacity; - size_t count; - size_t cardinality; - double load; - int flag; - struct hashmultiset_fval *f_val; - struct cmc_alloc_node *alloc; - struct cmc_callbacks *callbacks; -}; -struct hashmultiset_entry -{ - size_t value; - size_t multiplicity; - size_t dist; - enum cmc_entry_state state; -}; -struct hashmultiset_fval -{ - int (*cmp)(size_t, size_t); - size_t (*cpy)(size_t); - _Bool (*str)(FILE *, size_t); - void (*free)(size_t); - size_t (*hash)(size_t); - int (*pri)(size_t, size_t); -}; -struct hashmultiset *hms_new(size_t capacity, double load, struct hashmultiset_fval *f_val); -struct hashmultiset *hms_new_custom(size_t capacity, double load, struct hashmultiset_fval *f_val, - struct cmc_alloc_node *alloc, struct cmc_callbacks *callbacks); -void hms_clear(struct hashmultiset *_set_); -void hms_free(struct hashmultiset *_set_); -void hms_customize(struct hashmultiset *_set_, struct cmc_alloc_node *alloc, struct cmc_callbacks *callbacks); -_Bool hms_insert(struct hashmultiset *_set_, size_t value); -_Bool hms_insert_many(struct hashmultiset *_set_, size_t value, size_t count); -_Bool hms_update(struct hashmultiset *_set_, size_t value, size_t multiplicity); -_Bool hms_remove(struct hashmultiset *_set_, size_t value); -size_t hms_remove_all(struct hashmultiset *_set_, size_t value); -_Bool hms_max(struct hashmultiset *_set_, size_t *value); -_Bool hms_min(struct hashmultiset *_set_, size_t *value); -size_t hms_multiplicity_of(struct hashmultiset *_set_, size_t value); -_Bool hms_contains(struct hashmultiset *_set_, size_t value); -_Bool hms_empty(struct hashmultiset *_set_); -_Bool hms_full(struct hashmultiset *_set_); -size_t hms_count(struct hashmultiset *_set_); -size_t hms_cardinality(struct hashmultiset *_set_); -size_t hms_capacity(struct hashmultiset *_set_); -double hms_load(struct hashmultiset *_set_); -int hms_flag(struct hashmultiset *_set_); -_Bool hms_resize(struct hashmultiset *_set_, size_t capacity); -struct hashmultiset *hms_copy_of(struct hashmultiset *_set_); -_Bool hms_equals(struct hashmultiset *_set1_, struct hashmultiset *_set2_); -struct hashmultiset_iter -{ - struct hashmultiset *target; - size_t cursor; - size_t index; - size_t first; - size_t last; - _Bool start; - _Bool end; -}; -struct hashmultiset_iter hms_iter_start(struct hashmultiset *target); -struct hashmultiset_iter hms_iter_end(struct hashmultiset *target); -_Bool hms_iter_at_start(struct hashmultiset_iter *iter); -_Bool hms_iter_at_end(struct hashmultiset_iter *iter); -_Bool hms_iter_to_start(struct hashmultiset_iter *iter); -_Bool hms_iter_to_end(struct hashmultiset_iter *iter); -_Bool hms_iter_next(struct hashmultiset_iter *iter); -_Bool hms_iter_prev(struct hashmultiset_iter *iter); -_Bool hms_iter_advance(struct hashmultiset_iter *iter, size_t steps); -_Bool hms_iter_rewind(struct hashmultiset_iter *iter, size_t steps); -_Bool hms_iter_go_to(struct hashmultiset_iter *iter, size_t index); -size_t hms_iter_value(struct hashmultiset_iter *iter); -size_t hms_iter_multiplicity(struct hashmultiset_iter *iter); -size_t hms_iter_index(struct hashmultiset_iter *iter); -struct hashmultiset *hms_union(struct hashmultiset *_set1_, struct hashmultiset *_set2_); -struct hashmultiset *hms_intersection(struct hashmultiset *_set1_, struct hashmultiset *_set2_); -struct hashmultiset *hms_difference(struct hashmultiset *_set1_, struct hashmultiset *_set2_); -struct hashmultiset *hms_summation(struct hashmultiset *_set1_, struct hashmultiset *_set2_); -struct hashmultiset *hms_symmetric_difference(struct hashmultiset *_set1_, struct hashmultiset *_set2_); -_Bool hms_is_subset(struct hashmultiset *_set1_, struct hashmultiset *_set2_); -_Bool hms_is_superset(struct hashmultiset *_set1_, struct hashmultiset *_set2_); -_Bool hms_is_proper_subset(struct hashmultiset *_set1_, struct hashmultiset *_set2_); -_Bool hms_is_proper_superset(struct hashmultiset *_set1_, struct hashmultiset *_set2_); -_Bool hms_is_disjointset(struct hashmultiset *_set1_, struct hashmultiset *_set2_); -_Bool hms_to_string(struct hashmultiset *_set_, FILE *fptr); -_Bool hms_print(struct hashmultiset *_set_, FILE *fptr, const char *start, const char *separator, const char *end, - const char *key_val_sep); static size_t hms_impl_multiplicity_of(struct hashmultiset *_set_, size_t value); static struct hashmultiset_entry *hms_impl_insert_and_return(struct hashmultiset *_set_, size_t value, _Bool *new_node); static struct hashmultiset_entry *hms_impl_get_entry(struct hashmultiset *_set_, size_t value); @@ -1036,5 +944,3 @@ _Bool hms_print(struct hashmultiset *_set_, FILE *fptr, const char *start, const fprintf(fptr, "%s", end); return 1; } - -#endif /* CMC_TEST_SRC_HASHMULTISET */ diff --git a/tests/main/src/hashset.c b/tests/src/cmc/hashset.c similarity index 86% rename from tests/main/src/hashset.c rename to tests/src/cmc/hashset.c index cf11adb..de158d7 100644 --- a/tests/main/src/hashset.c +++ b/tests/src/cmc/hashset.c @@ -1,88 +1,6 @@ -#ifndef CMC_TEST_SRC_HASHSET -#define CMC_TEST_SRC_HASHSET #include "cmc/hashset.h" -struct hashset -{ - struct hashset_entry *buffer; - size_t capacity; - size_t count; - double load; - int flag; - struct hashset_fval *f_val; - struct cmc_alloc_node *alloc; - struct cmc_callbacks *callbacks; -}; -struct hashset_entry -{ - size_t value; - size_t dist; - enum cmc_entry_state state; -}; -struct hashset_fval -{ - int (*cmp)(size_t, size_t); - size_t (*cpy)(size_t); - _Bool (*str)(FILE *, size_t); - void (*free)(size_t); - size_t (*hash)(size_t); - int (*pri)(size_t, size_t); -}; -struct hashset *hs_new(size_t capacity, double load, struct hashset_fval *f_val); -struct hashset *hs_new_custom(size_t capacity, double load, struct hashset_fval *f_val, struct cmc_alloc_node *alloc, - struct cmc_callbacks *callbacks); -void hs_clear(struct hashset *_set_); -void hs_free(struct hashset *_set_); -void hs_customize(struct hashset *_set_, struct cmc_alloc_node *alloc, struct cmc_callbacks *callbacks); -_Bool hs_insert(struct hashset *_set_, size_t value); -_Bool hs_remove(struct hashset *_set_, size_t value); -_Bool hs_max(struct hashset *_set_, size_t *value); -_Bool hs_min(struct hashset *_set_, size_t *value); -_Bool hs_contains(struct hashset *_set_, size_t value); -_Bool hs_empty(struct hashset *_set_); -_Bool hs_full(struct hashset *_set_); -size_t hs_count(struct hashset *_set_); -size_t hs_capacity(struct hashset *_set_); -double hs_load(struct hashset *_set_); -int hs_flag(struct hashset *_set_); -_Bool hs_resize(struct hashset *_set_, size_t capacity); -struct hashset *hs_copy_of(struct hashset *_set_); -_Bool hs_equals(struct hashset *_set1_, struct hashset *_set2_); -struct hashset_iter -{ - struct hashset *target; - size_t cursor; - size_t index; - size_t first; - size_t last; - _Bool start; - _Bool end; -}; -struct hashset_iter hs_iter_start(struct hashset *target); -struct hashset_iter hs_iter_end(struct hashset *target); -_Bool hs_iter_at_start(struct hashset_iter *iter); -_Bool hs_iter_at_end(struct hashset_iter *iter); -_Bool hs_iter_to_start(struct hashset_iter *iter); -_Bool hs_iter_to_end(struct hashset_iter *iter); -_Bool hs_iter_next(struct hashset_iter *iter); -_Bool hs_iter_prev(struct hashset_iter *iter); -_Bool hs_iter_advance(struct hashset_iter *iter, size_t steps); -_Bool hs_iter_rewind(struct hashset_iter *iter, size_t steps); -_Bool hs_iter_go_to(struct hashset_iter *iter, size_t index); -size_t hs_iter_value(struct hashset_iter *iter); -size_t hs_iter_index(struct hashset_iter *iter); -struct hashset *hs_union(struct hashset *_set1_, struct hashset *_set2_); -struct hashset *hs_intersection(struct hashset *_set1_, struct hashset *_set2_); -struct hashset *hs_difference(struct hashset *_set1_, struct hashset *_set2_); -struct hashset *hs_symmetric_difference(struct hashset *_set1_, struct hashset *_set2_); -_Bool hs_is_subset(struct hashset *_set1_, struct hashset *_set2_); -_Bool hs_is_superset(struct hashset *_set1_, struct hashset *_set2_); -_Bool hs_is_proper_subset(struct hashset *_set1_, struct hashset *_set2_); -_Bool hs_is_proper_superset(struct hashset *_set1_, struct hashset *_set2_); -_Bool hs_is_disjointset(struct hashset *_set1_, struct hashset *_set2_); -_Bool hs_to_string(struct hashset *_set_, FILE *fptr); -_Bool hs_print(struct hashset *_set_, FILE *fptr, const char *start, const char *separator, const char *end); static struct hashset_entry *hs_impl_get_entry(struct hashset *_set_, size_t value); static size_t hs_impl_calculate_size(size_t required); struct hashset *hs_new(size_t capacity, double load, struct hashset_fval *f_val) @@ -835,5 +753,3 @@ _Bool hs_print(struct hashset *_set_, FILE *fptr, const char *start, const char fprintf(fptr, "%s", end); return 1; } - -#endif /* CMC_TEST_SRC_HASHSET */ diff --git a/tests/main/src/heap.c b/tests/src/cmc/heap.c similarity index 82% rename from tests/main/src/heap.c rename to tests/src/cmc/heap.c index 5e435b9..11cd537 100644 --- a/tests/main/src/heap.c +++ b/tests/src/cmc/heap.c @@ -1,68 +1,6 @@ -#ifndef CMC_TEST_SRC_HEAP -#define CMC_TEST_SRC_HEAP #include "cmc/heap.h" -struct heap -{ - size_t *buffer; - size_t capacity; - size_t count; - enum cmc_heap_order HO; - int flag; - struct heap_fval *f_val; - struct cmc_alloc_node *alloc; - struct cmc_callbacks *callbacks; -}; -struct heap_fval -{ - int (*cmp)(size_t, size_t); - size_t (*cpy)(size_t); - _Bool (*str)(FILE *, size_t); - void (*free)(size_t); - size_t (*hash)(size_t); - int (*pri)(size_t, size_t); -}; -struct heap *h_new(size_t capacity, enum cmc_heap_order HO, struct heap_fval *f_val); -struct heap *h_new_custom(size_t capacity, enum cmc_heap_order HO, struct heap_fval *f_val, - struct cmc_alloc_node *alloc, struct cmc_callbacks *callbacks); -void h_clear(struct heap *_heap_); -void h_free(struct heap *_heap_); -void h_customize(struct heap *_heap_, struct cmc_alloc_node *alloc, struct cmc_callbacks *callbacks); -_Bool h_insert(struct heap *_heap_, size_t value); -_Bool h_remove(struct heap *_heap_); -size_t h_peek(struct heap *_heap_); -_Bool h_contains(struct heap *_heap_, size_t value); -_Bool h_empty(struct heap *_heap_); -_Bool h_full(struct heap *_heap_); -size_t h_count(struct heap *_heap_); -size_t h_capacity(struct heap *_heap_); -int h_flag(struct heap *_heap_); -_Bool h_resize(struct heap *_heap_, size_t capacity); -struct heap *h_copy_of(struct heap *_heap_); -_Bool h_equals(struct heap *_heap1_, struct heap *_heap2_); -struct heap_iter -{ - struct heap *target; - size_t cursor; - _Bool start; - _Bool end; -}; -struct heap_iter h_iter_start(struct heap *target); -struct heap_iter h_iter_end(struct heap *target); -_Bool h_iter_at_start(struct heap_iter *iter); -_Bool h_iter_at_end(struct heap_iter *iter); -_Bool h_iter_to_start(struct heap_iter *iter); -_Bool h_iter_to_end(struct heap_iter *iter); -_Bool h_iter_next(struct heap_iter *iter); -_Bool h_iter_prev(struct heap_iter *iter); -_Bool h_iter_advance(struct heap_iter *iter, size_t steps); -_Bool h_iter_rewind(struct heap_iter *iter, size_t steps); -_Bool h_iter_go_to(struct heap_iter *iter, size_t index); -size_t h_iter_value(struct heap_iter *iter); -size_t h_iter_index(struct heap_iter *iter); -_Bool h_to_string(struct heap *_heap_, FILE *fptr); -_Bool h_print(struct heap *_heap_, FILE *fptr, const char *start, const char *separator, const char *end); static void h_impl_float_up(struct heap *_heap_, size_t index); static void h_impl_float_down(struct heap *_heap_, size_t index); struct heap *h_new(size_t capacity, enum cmc_heap_order HO, struct heap_fval *f_val) @@ -484,5 +422,3 @@ _Bool h_print(struct heap *_heap_, FILE *fptr, const char *start, const char *se fprintf(fptr, "%s", end); return 1; } - -#endif /* CMC_TEST_SRC_HEAP */ diff --git a/tests/main/src/intervalheap.c b/tests/src/cmc/intervalheap.c similarity index 86% rename from tests/main/src/intervalheap.c rename to tests/src/cmc/intervalheap.c index b609bfb..56ac313 100644 --- a/tests/main/src/intervalheap.c +++ b/tests/src/cmc/intervalheap.c @@ -1,72 +1,6 @@ -#ifndef CMC_TEST_SRC_INTERVALHEAP -#define CMC_TEST_SRC_INTERVALHEAP #include "cmc/intervalheap.h" -struct intervalheap -{ - size_t (*buffer)[2]; - size_t capacity; - size_t size; - size_t count; - int flag; - struct intervalheap_fval *f_val; - struct cmc_alloc_node *alloc; - struct cmc_callbacks *callbacks; -}; -struct intervalheap_fval -{ - int (*cmp)(size_t, size_t); - size_t (*cpy)(size_t); - _Bool (*str)(FILE *, size_t); - void (*free)(size_t); - size_t (*hash)(size_t); - int (*pri)(size_t, size_t); -}; -struct intervalheap *ih_new(size_t capacity, struct intervalheap_fval *f_val); -struct intervalheap *ih_new_custom(size_t capacity, struct intervalheap_fval *f_val, struct cmc_alloc_node *alloc, - struct cmc_callbacks *callbacks); -void ih_clear(struct intervalheap *_heap_); -void ih_free(struct intervalheap *_heap_); -void ih_customize(struct intervalheap *_heap_, struct cmc_alloc_node *alloc, struct cmc_callbacks *callbacks); -_Bool ih_insert(struct intervalheap *_heap_, size_t value); -_Bool ih_remove_max(struct intervalheap *_heap_); -_Bool ih_remove_min(struct intervalheap *_heap_); -_Bool ih_update_max(struct intervalheap *_heap_, size_t value); -_Bool ih_update_min(struct intervalheap *_heap_, size_t value); -size_t ih_max(struct intervalheap *_heap_); -size_t ih_min(struct intervalheap *_heap_); -_Bool ih_contains(struct intervalheap *_heap_, size_t value); -_Bool ih_empty(struct intervalheap *_heap_); -_Bool ih_full(struct intervalheap *_heap_); -size_t ih_count(struct intervalheap *_heap_); -size_t ih_capacity(struct intervalheap *_heap_); -int ih_flag(struct intervalheap *_heap_); -_Bool ih_resize(struct intervalheap *_heap_, size_t capacity); -struct intervalheap *ih_copy_of(struct intervalheap *_heap_); -_Bool ih_equals(struct intervalheap *_heap1_, struct intervalheap *_heap2_); -struct intervalheap_iter -{ - struct intervalheap *target; - size_t cursor; - _Bool start; - _Bool end; -}; -struct intervalheap_iter ih_iter_start(struct intervalheap *target); -struct intervalheap_iter ih_iter_end(struct intervalheap *target); -_Bool ih_iter_at_start(struct intervalheap_iter *iter); -_Bool ih_iter_at_end(struct intervalheap_iter *iter); -_Bool ih_iter_to_start(struct intervalheap_iter *iter); -_Bool ih_iter_to_end(struct intervalheap_iter *iter); -_Bool ih_iter_next(struct intervalheap_iter *iter); -_Bool ih_iter_prev(struct intervalheap_iter *iter); -_Bool ih_iter_advance(struct intervalheap_iter *iter, size_t steps); -_Bool ih_iter_rewind(struct intervalheap_iter *iter, size_t steps); -_Bool ih_iter_go_to(struct intervalheap_iter *iter, size_t index); -size_t ih_iter_value(struct intervalheap_iter *iter); -size_t ih_iter_index(struct intervalheap_iter *iter); -_Bool ih_to_string(struct intervalheap *_heap_, FILE *fptr); -_Bool ih_print(struct intervalheap *_heap_, FILE *fptr, const char *start, const char *separator, const char *end); static void ih_impl_float_up_max(struct intervalheap *_heap_); static void ih_impl_float_up_min(struct intervalheap *_heap_); static void ih_impl_float_down_max(struct intervalheap *_heap_); @@ -750,5 +684,3 @@ _Bool ih_print(struct intervalheap *_heap_, FILE *fptr, const char *start, const fprintf(fptr, "%s", end); return 1; } - -#endif /* CMC_TEST_SRC_INTERVALHEAP */ diff --git a/tests/main/src/linkedlist.c b/tests/src/cmc/linkedlist.c similarity index 81% rename from tests/main/src/linkedlist.c rename to tests/src/cmc/linkedlist.c index 3030f9b..32dbae8 100644 --- a/tests/main/src/linkedlist.c +++ b/tests/src/cmc/linkedlist.c @@ -1,92 +1,6 @@ -#ifndef CMC_TEST_SRC_LINKEDLIST -#define CMC_TEST_SRC_LINKEDLIST #include "cmc/linkedlist.h" -struct linkedlist -{ - struct linkedlist_node *head; - struct linkedlist_node *tail; - size_t count; - int flag; - struct linkedlist_fval *f_val; - struct cmc_alloc_node *alloc; - struct cmc_callbacks *callbacks; -}; -struct linkedlist_node -{ - size_t value; - struct linkedlist_node *next; - struct linkedlist_node *prev; -}; -struct linkedlist_fval -{ - int (*cmp)(size_t, size_t); - size_t (*cpy)(size_t); - _Bool (*str)(FILE *, size_t); - void (*free)(size_t); - size_t (*hash)(size_t); - int (*pri)(size_t, size_t); -}; -struct linkedlist *ll_new(struct linkedlist_fval *f_val); -struct linkedlist *ll_new_custom(struct linkedlist_fval *f_val, struct cmc_alloc_node *alloc, - struct cmc_callbacks *callbacks); -void ll_clear(struct linkedlist *_list_); -void ll_free(struct linkedlist *_list_); -void ll_customize(struct linkedlist *_list_, struct cmc_alloc_node *alloc, struct cmc_callbacks *callbacks); -_Bool ll_push_front(struct linkedlist *_list_, size_t value); -_Bool ll_push_at(struct linkedlist *_list_, size_t value, size_t index); -_Bool ll_push_back(struct linkedlist *_list_, size_t value); -_Bool ll_pop_front(struct linkedlist *_list_); -_Bool ll_pop_at(struct linkedlist *_list_, size_t index); -_Bool ll_pop_back(struct linkedlist *_list_); -size_t ll_front(struct linkedlist *_list_); -size_t ll_get(struct linkedlist *_list_, size_t index); -size_t *ll_get_ref(struct linkedlist *_list_, size_t index); -size_t ll_back(struct linkedlist *_list_); -_Bool ll_contains(struct linkedlist *_list_, size_t value); -_Bool ll_empty(struct linkedlist *_list_); -size_t ll_count(struct linkedlist *_list_); -int ll_flag(struct linkedlist *_list_); -struct linkedlist *ll_copy_of(struct linkedlist *_list_); -_Bool ll_equals(struct linkedlist *_list1_, struct linkedlist *_list2_); -struct linkedlist_iter -{ - struct linkedlist *target; - struct linkedlist_node *cursor; - size_t index; - _Bool start; - _Bool end; -}; -struct linkedlist_iter ll_iter_start(struct linkedlist *target); -struct linkedlist_iter ll_iter_end(struct linkedlist *target); -_Bool ll_iter_at_start(struct linkedlist_iter *iter); -_Bool ll_iter_at_end(struct linkedlist_iter *iter); -_Bool ll_iter_to_start(struct linkedlist_iter *iter); -_Bool ll_iter_to_end(struct linkedlist_iter *iter); -_Bool ll_iter_next(struct linkedlist_iter *iter); -_Bool ll_iter_prev(struct linkedlist_iter *iter); -_Bool ll_iter_advance(struct linkedlist_iter *iter, size_t steps); -_Bool ll_iter_rewind(struct linkedlist_iter *iter, size_t steps); -_Bool ll_iter_go_to(struct linkedlist_iter *iter, size_t index); -size_t ll_iter_value(struct linkedlist_iter *iter); -size_t *ll_iter_rvalue(struct linkedlist_iter *iter); -size_t ll_iter_index(struct linkedlist_iter *iter); -struct linkedlist_node *ll_iter_node(struct linkedlist_iter *iter); -struct linkedlist_node *ll_new_node(struct linkedlist *_list_, size_t value); -void ll_free_node(struct linkedlist *_list_, struct linkedlist_node *_node_); -struct linkedlist_node *ll_head(struct linkedlist *_list_); -struct linkedlist_node *ll_get_node(struct linkedlist *_list_, size_t index); -struct linkedlist_node *ll_tail(struct linkedlist *_list_); -_Bool ll_add_next(struct linkedlist *_owner_, struct linkedlist_node *_node_, size_t value); -_Bool ll_add_prev(struct linkedlist *_owner_, struct linkedlist_node *_node_, size_t value); -_Bool ll_del_next(struct linkedlist *_owner_, struct linkedlist_node *_node_); -_Bool ll_del_curr(struct linkedlist *_owner_, struct linkedlist_node *_node_); -_Bool ll_del_prev(struct linkedlist *_owner_, struct linkedlist_node *_node_); -struct linkedlist_node *ll_next_node(struct linkedlist_node *_node_); -struct linkedlist_node *ll_prev_node(struct linkedlist_node *_node_); -_Bool ll_to_string(struct linkedlist *_list_, FILE *fptr); -_Bool ll_print(struct linkedlist *_list_, FILE *fptr, const char *start, const char *separator, const char *end); struct linkedlist *ll_new(struct linkedlist_fval *f_val) { return ll_new_custom(f_val, ((void *)0), ((void *)0)); @@ -767,5 +681,3 @@ _Bool ll_print(struct linkedlist *_list_, FILE *fptr, const char *start, const c fprintf(fptr, "%s", end); return 1; } - -#endif /* CMC_TEST_SRC_LINKEDLIST */ diff --git a/tests/main/src/list.c b/tests/src/cmc/list.c similarity index 84% rename from tests/main/src/list.c rename to tests/src/cmc/list.c index 5c5ffbf..6d65763 100644 --- a/tests/main/src/list.c +++ b/tests/src/cmc/list.c @@ -1,82 +1,6 @@ -#ifndef CMC_TEST_SRC_LIST -#define CMC_TEST_SRC_LIST #include "cmc/list.h" -struct list -{ - size_t *buffer; - size_t capacity; - size_t count; - int flag; - struct list_fval *f_val; - struct cmc_alloc_node *alloc; - struct cmc_callbacks *callbacks; -}; -struct list_fval -{ - int (*cmp)(size_t, size_t); - size_t (*cpy)(size_t); - _Bool (*str)(FILE *, size_t); - void (*free)(size_t); - size_t (*hash)(size_t); - int (*pri)(size_t, size_t); -}; -struct list *l_new(size_t capacity, struct list_fval *f_val); -struct list *l_new_custom(size_t capacity, struct list_fval *f_val, struct cmc_alloc_node *alloc, - struct cmc_callbacks *callbacks); -void l_clear(struct list *_list_); -void l_free(struct list *_list_); -void l_customize(struct list *_list_, struct cmc_alloc_node *alloc, struct cmc_callbacks *callbacks); -_Bool l_push_front(struct list *_list_, size_t value); -_Bool l_push_at(struct list *_list_, size_t value, size_t index); -_Bool l_push_back(struct list *_list_, size_t value); -_Bool l_pop_front(struct list *_list_); -_Bool l_pop_at(struct list *_list_, size_t index); -_Bool l_pop_back(struct list *_list_); -size_t l_front(struct list *_list_); -size_t l_get(struct list *_list_, size_t index); -size_t *l_get_ref(struct list *_list_, size_t index); -size_t l_back(struct list *_list_); -size_t l_index_of(struct list *_list_, size_t value, _Bool from_start); -_Bool l_contains(struct list *_list_, size_t value); -_Bool l_empty(struct list *_list_); -_Bool l_full(struct list *_list_); -size_t l_count(struct list *_list_); -_Bool l_fits(struct list *_list_, size_t size); -size_t l_capacity(struct list *_list_); -int l_flag(struct list *_list_); -_Bool l_resize(struct list *_list_, size_t capacity); -struct list *l_copy_of(struct list *_list_); -_Bool l_equals(struct list *_list1_, struct list *_list2_); -struct list_iter -{ - struct list *target; - size_t cursor; - _Bool start; - _Bool end; -}; -struct list_iter l_iter_start(struct list *target); -struct list_iter l_iter_end(struct list *target); -_Bool l_iter_at_start(struct list_iter *iter); -_Bool l_iter_at_end(struct list_iter *iter); -_Bool l_iter_to_start(struct list_iter *iter); -_Bool l_iter_to_end(struct list_iter *iter); -_Bool l_iter_next(struct list_iter *iter); -_Bool l_iter_prev(struct list_iter *iter); -_Bool l_iter_advance(struct list_iter *iter, size_t steps); -_Bool l_iter_rewind(struct list_iter *iter, size_t steps); -_Bool l_iter_go_to(struct list_iter *iter, size_t index); -size_t l_iter_value(struct list_iter *iter); -size_t *l_iter_rvalue(struct list_iter *iter); -size_t l_iter_index(struct list_iter *iter); -_Bool l_seq_push_front(struct list *_list_, size_t *values, size_t size); -_Bool l_seq_push_at(struct list *_list_, size_t *values, size_t size, size_t index); -_Bool l_seq_push_back(struct list *_list_, size_t *values, size_t size); -_Bool l_seq_pop_at(struct list *_list_, size_t from, size_t to); -struct list *l_seq_sublist(struct list *_list_, size_t from, size_t to); -_Bool l_to_string(struct list *_list_, FILE *fptr); -_Bool l_print(struct list *_list_, FILE *fptr, const char *start, const char *separator, const char *end); struct list *l_new(size_t capacity, struct list_fval *f_val) { return l_new_custom(capacity, f_val, ((void *)0), ((void *)0)); @@ -717,5 +641,3 @@ _Bool l_print(struct list *_list_, FILE *fptr, const char *start, const char *se fprintf(fptr, "%s", end); return 1; } - -#endif /* CMC_TEST_SRC_LIST */ diff --git a/tests/main/src/queue.c b/tests/src/cmc/queue.c similarity index 82% rename from tests/main/src/queue.c rename to tests/src/cmc/queue.c index e5e6d85..de55581 100644 --- a/tests/main/src/queue.c +++ b/tests/src/cmc/queue.c @@ -1,71 +1,6 @@ -#ifndef CMC_TEST_SRC_QUEUE -#define CMC_TEST_SRC_QUEUE #include "cmc/queue.h" -struct queue -{ - size_t *buffer; - size_t capacity; - size_t count; - size_t front; - size_t back; - int flag; - struct queue_fval *f_val; - struct cmc_alloc_node *alloc; - struct cmc_callbacks *callbacks; -}; -struct queue_fval -{ - int (*cmp)(size_t, size_t); - size_t (*cpy)(size_t); - _Bool (*str)(FILE *, size_t); - void (*free)(size_t); - size_t (*hash)(size_t); - int (*pri)(size_t, size_t); -}; -struct queue_iter -{ - struct queue *target; - size_t cursor; - size_t index; - _Bool start; - _Bool end; -}; -struct queue *q_new(size_t capacity, struct queue_fval *f_val); -struct queue *q_new_custom(size_t capacity, struct queue_fval *f_val, struct cmc_alloc_node *alloc, - struct cmc_callbacks *callbacks); -void q_clear(struct queue *_queue_); -void q_free(struct queue *_queue_); -void q_customize(struct queue *_queue_, struct cmc_alloc_node *alloc, struct cmc_callbacks *callbacks); -_Bool q_enqueue(struct queue *_queue_, size_t value); -_Bool q_dequeue(struct queue *_queue_); -size_t q_peek(struct queue *_queue_); -_Bool q_contains(struct queue *_queue_, size_t value); -_Bool q_empty(struct queue *_queue_); -_Bool q_full(struct queue *_queue_); -size_t q_count(struct queue *_queue_); -size_t q_capacity(struct queue *_queue_); -int q_flag(struct queue *_queue_); -_Bool q_resize(struct queue *_queue_, size_t capacity); -struct queue *q_copy_of(struct queue *_queue_); -_Bool q_equals(struct queue *_queue1_, struct queue *_queue2_); -struct queue_iter q_iter_start(struct queue *target); -struct queue_iter q_iter_end(struct queue *target); -_Bool q_iter_at_start(struct queue_iter *iter); -_Bool q_iter_at_end(struct queue_iter *iter); -_Bool q_iter_to_start(struct queue_iter *iter); -_Bool q_iter_to_end(struct queue_iter *iter); -_Bool q_iter_next(struct queue_iter *iter); -_Bool q_iter_prev(struct queue_iter *iter); -_Bool q_iter_advance(struct queue_iter *iter, size_t steps); -_Bool q_iter_rewind(struct queue_iter *iter, size_t steps); -_Bool q_iter_go_to(struct queue_iter *iter, size_t index); -size_t q_iter_value(struct queue_iter *iter); -size_t *q_iter_rvalue(struct queue_iter *iter); -size_t q_iter_index(struct queue_iter *iter); -_Bool q_to_string(struct queue *_queue_, FILE *fptr); -_Bool q_print(struct queue *_queue_, FILE *fptr, const char *start, const char *separator, const char *end); struct queue *q_new(size_t capacity, struct queue_fval *f_val) { return q_new_custom(capacity, f_val, ((void *)0), ((void *)0)); @@ -494,5 +429,3 @@ _Bool q_print(struct queue *_queue_, FILE *fptr, const char *start, const char * fprintf(fptr, "%s", end); return 1; } - -#endif /* CMC_TEST_SRC_QUEUE */ diff --git a/tests/main/src/sortedlist.c b/tests/src/cmc/sortedlist.c similarity index 83% rename from tests/main/src/sortedlist.c rename to tests/src/cmc/sortedlist.c index 480a08c..d130322 100644 --- a/tests/main/src/sortedlist.c +++ b/tests/src/cmc/sortedlist.c @@ -1,72 +1,6 @@ -#ifndef CMC_TEST_SRC_SORTEDLIST -#define CMC_TEST_SRC_SORTEDLIST #include "cmc/sortedlist.h" -struct sortedlist -{ - size_t *buffer; - size_t capacity; - size_t count; - _Bool is_sorted; - int flag; - struct sortedlist_fval *f_val; - struct cmc_alloc_node *alloc; - struct cmc_callbacks *callbacks; -}; -struct sortedlist_fval -{ - int (*cmp)(size_t, size_t); - size_t (*cpy)(size_t); - _Bool (*str)(FILE *, size_t); - void (*free)(size_t); - size_t (*hash)(size_t); - int (*pri)(size_t, size_t); -}; -struct sortedlist *sl_new(size_t capacity, struct sortedlist_fval *f_val); -struct sortedlist *sl_new_custom(size_t capacity, struct sortedlist_fval *f_val, struct cmc_alloc_node *alloc, - struct cmc_callbacks *callbacks); -void sl_clear(struct sortedlist *_list_); -void sl_free(struct sortedlist *_list_); -void sl_customize(struct sortedlist *_list_, struct cmc_alloc_node *alloc, struct cmc_callbacks *callbacks); -_Bool sl_insert(struct sortedlist *_list_, size_t value); -_Bool sl_remove(struct sortedlist *_list_, size_t index); -size_t sl_max(struct sortedlist *_list_); -size_t sl_min(struct sortedlist *_list_); -size_t sl_get(struct sortedlist *_list_, size_t index); -size_t sl_index_of(struct sortedlist *_list_, size_t value, _Bool from_start); -_Bool sl_contains(struct sortedlist *_list_, size_t value); -_Bool sl_empty(struct sortedlist *_list_); -_Bool sl_full(struct sortedlist *_list_); -size_t sl_count(struct sortedlist *_list_); -size_t sl_capacity(struct sortedlist *_list_); -int sl_flag(struct sortedlist *_list_); -_Bool sl_resize(struct sortedlist *_list_, size_t capacity); -void sl_sort(struct sortedlist *_list_); -struct sortedlist *sl_copy_of(struct sortedlist *_list_); -_Bool sl_equals(struct sortedlist *_list1_, struct sortedlist *_list2_); -struct sortedlist_iter -{ - struct sortedlist *target; - size_t cursor; - _Bool start; - _Bool end; -}; -struct sortedlist_iter sl_iter_start(struct sortedlist *target); -struct sortedlist_iter sl_iter_end(struct sortedlist *target); -_Bool sl_iter_at_start(struct sortedlist_iter *iter); -_Bool sl_iter_at_end(struct sortedlist_iter *iter); -_Bool sl_iter_to_start(struct sortedlist_iter *iter); -_Bool sl_iter_to_end(struct sortedlist_iter *iter); -_Bool sl_iter_next(struct sortedlist_iter *iter); -_Bool sl_iter_prev(struct sortedlist_iter *iter); -_Bool sl_iter_advance(struct sortedlist_iter *iter, size_t steps); -_Bool sl_iter_rewind(struct sortedlist_iter *iter, size_t steps); -_Bool sl_iter_go_to(struct sortedlist_iter *iter, size_t index); -size_t sl_iter_value(struct sortedlist_iter *iter); -size_t sl_iter_index(struct sortedlist_iter *iter); -_Bool sl_to_string(struct sortedlist *_list_, FILE *fptr); -_Bool sl_print(struct sortedlist *_list_, FILE *fptr, const char *start, const char *separator, const char *end); static size_t sl_impl_binary_search_first(struct sortedlist *_list_, size_t value); static size_t sl_impl_binary_search_last(struct sortedlist *_list_, size_t value); void sl_impl_sort_quicksort(size_t *array, int (*cmp)(size_t, size_t), size_t low, size_t high); @@ -576,5 +510,3 @@ _Bool sl_print(struct sortedlist *_list_, FILE *fptr, const char *start, const c fprintf(fptr, "%s", end); return 1; } - -#endif /* CMC_TEST_SRC_SORTEDLIST */ diff --git a/tests/main/src/stack.c b/tests/src/cmc/stack.c similarity index 79% rename from tests/main/src/stack.c rename to tests/src/cmc/stack.c index 1be2b1a..46cf798 100644 --- a/tests/main/src/stack.c +++ b/tests/src/cmc/stack.c @@ -1,68 +1,6 @@ -#ifndef CMC_TEST_SRC_STACK -#define CMC_TEST_SRC_STACK #include "cmc/stack.h" -struct stack -{ - size_t *buffer; - size_t capacity; - size_t count; - int flag; - struct stack_fval *f_val; - struct cmc_alloc_node *alloc; - struct cmc_callbacks *callbacks; -}; -struct stack_fval -{ - int (*cmp)(size_t, size_t); - size_t (*cpy)(size_t); - _Bool (*str)(FILE *, size_t); - void (*free)(size_t); - size_t (*hash)(size_t); - int (*pri)(size_t, size_t); -}; -struct stack *s_new(size_t capacity, struct stack_fval *f_val); -struct stack *s_new_custom(size_t capacity, struct stack_fval *f_val, struct cmc_alloc_node *alloc, - struct cmc_callbacks *callbacks); -void s_clear(struct stack *_stack_); -void s_free(struct stack *_stack_); -void s_customize(struct stack *_stack_, struct cmc_alloc_node *alloc, struct cmc_callbacks *callbacks); -_Bool s_push(struct stack *_stack_, size_t value); -_Bool s_pop(struct stack *_stack_); -size_t s_top(struct stack *_stack_); -_Bool s_contains(struct stack *_stack_, size_t value); -_Bool s_empty(struct stack *_stack_); -_Bool s_full(struct stack *_stack_); -size_t s_count(struct stack *_stack_); -size_t s_capacity(struct stack *_stack_); -int s_flag(struct stack *_stack_); -_Bool s_resize(struct stack *_stack_, size_t capacity); -struct stack *s_copy_of(struct stack *_stack_); -_Bool s_equals(struct stack *_stack1_, struct stack *_stack2_); -struct stack_iter -{ - struct stack *target; - size_t cursor; - _Bool start; - _Bool end; -}; -struct stack_iter s_iter_start(struct stack *target); -struct stack_iter s_iter_end(struct stack *target); -_Bool s_iter_at_start(struct stack_iter *iter); -_Bool s_iter_at_end(struct stack_iter *iter); -_Bool s_iter_to_start(struct stack_iter *iter); -_Bool s_iter_to_end(struct stack_iter *iter); -_Bool s_iter_next(struct stack_iter *iter); -_Bool s_iter_prev(struct stack_iter *iter); -_Bool s_iter_advance(struct stack_iter *iter, size_t steps); -_Bool s_iter_rewind(struct stack_iter *iter, size_t steps); -_Bool s_iter_go_to(struct stack_iter *iter, size_t index); -size_t s_iter_value(struct stack_iter *iter); -size_t *s_iter_rvalue(struct stack_iter *iter); -size_t s_iter_index(struct stack_iter *iter); -_Bool s_to_string(struct stack *_stack_, FILE *fptr); -_Bool s_print(struct stack *_stack_, FILE *fptr, const char *start, const char *separator, const char *end); struct stack *s_new(size_t capacity, struct stack_fval *f_val) { return s_new_custom(capacity, f_val, ((void *)0), ((void *)0)); @@ -235,7 +173,7 @@ struct stack *s_copy_of(struct stack *_stack_) _stack_->flag = CMC_FLAG_ERROR; return ((void *)0); } - (_stack_)->callbacks = callbacks; + (result)->callbacks = _stack_->callbacks; if (_stack_->f_val->cpy) { for (size_t i = 0; i < _stack_->count; i++) @@ -427,5 +365,3 @@ _Bool s_print(struct stack *_stack_, FILE *fptr, const char *start, const char * fprintf(fptr, "%s", end); return 1; } - -#endif /* CMC_TEST_SRC_STACK */ diff --git a/tests/main/src/treemap.c b/tests/src/cmc/treemap.c similarity index 87% rename from tests/main/src/treemap.c rename to tests/src/cmc/treemap.c index fa081be..39ceb86 100644 --- a/tests/main/src/treemap.c +++ b/tests/src/cmc/treemap.c @@ -1,92 +1,6 @@ -#ifndef CMC_TEST_SRC_TREEMAP -#define CMC_TEST_SRC_TREEMAP #include "cmc/treemap.h" -struct treemap -{ - struct treemap_node *root; - size_t count; - int flag; - struct treemap_fkey *f_key; - struct treemap_fval *f_val; - struct cmc_alloc_node *alloc; - struct cmc_callbacks *callbacks; -}; -struct treemap_node -{ - size_t key; - size_t value; - unsigned char height; - struct treemap_node *right; - struct treemap_node *left; - struct treemap_node *parent; -}; -struct treemap_fkey -{ - int (*cmp)(size_t, size_t); - size_t (*cpy)(size_t); - _Bool (*str)(FILE *, size_t); - void (*free)(size_t); - size_t (*hash)(size_t); - int (*pri)(size_t, size_t); -}; -struct treemap_fval -{ - int (*cmp)(size_t, size_t); - size_t (*cpy)(size_t); - _Bool (*str)(FILE *, size_t); - void (*free)(size_t); - size_t (*hash)(size_t); - int (*pri)(size_t, size_t); -}; -struct treemap *tm_new(struct treemap_fkey *f_key, struct treemap_fval *f_val); -struct treemap *tm_new_custom(struct treemap_fkey *f_key, struct treemap_fval *f_val, struct cmc_alloc_node *alloc, - struct cmc_callbacks *callbacks); -void tm_clear(struct treemap *_map_); -void tm_free(struct treemap *_map_); -void tm_customize(struct treemap *_map_, struct cmc_alloc_node *alloc, struct cmc_callbacks *callbacks); -_Bool tm_insert(struct treemap *_map_, size_t key, size_t value); -_Bool tm_update(struct treemap *_map_, size_t key, size_t new_value, size_t *old_value); -_Bool tm_remove(struct treemap *_map_, size_t key, size_t *out_value); -_Bool tm_max(struct treemap *_map_, size_t *key, size_t *value); -_Bool tm_min(struct treemap *_map_, size_t *key, size_t *value); -size_t tm_get(struct treemap *_map_, size_t key); -size_t *tm_get_ref(struct treemap *_map_, size_t key); -_Bool tm_contains(struct treemap *_map_, size_t key); -_Bool tm_empty(struct treemap *_map_); -size_t tm_count(struct treemap *_map_); -int tm_flag(struct treemap *_map_); -struct treemap *tm_copy_of(struct treemap *_map_); -_Bool tm_equals(struct treemap *_map1_, struct treemap *_map2_); -struct treemap_iter -{ - struct treemap *target; - struct treemap_node *cursor; - struct treemap_node *first; - struct treemap_node *last; - size_t index; - _Bool start; - _Bool end; -}; -struct treemap_iter tm_iter_start(struct treemap *target); -struct treemap_iter tm_iter_end(struct treemap *target); -_Bool tm_iter_at_start(struct treemap_iter *iter); -_Bool tm_iter_at_end(struct treemap_iter *iter); -_Bool tm_iter_to_start(struct treemap_iter *iter); -_Bool tm_iter_to_end(struct treemap_iter *iter); -_Bool tm_iter_next(struct treemap_iter *iter); -_Bool tm_iter_prev(struct treemap_iter *iter); -_Bool tm_iter_advance(struct treemap_iter *iter, size_t steps); -_Bool tm_iter_rewind(struct treemap_iter *iter, size_t steps); -_Bool tm_iter_go_to(struct treemap_iter *iter, size_t index); -size_t tm_iter_key(struct treemap_iter *iter); -size_t tm_iter_value(struct treemap_iter *iter); -size_t *tm_iter_rvalue(struct treemap_iter *iter); -size_t tm_iter_index(struct treemap_iter *iter); -_Bool tm_to_string(struct treemap *_map_, FILE *fptr); -_Bool tm_print(struct treemap *_map_, FILE *fptr, const char *start, const char *separator, const char *end, - const char *key_val_sep); static struct treemap_node *tm_impl_new_node(struct treemap *_map_, size_t key, size_t value); static struct treemap_node *tm_impl_get_node(struct treemap *_map_, size_t key); static unsigned char tm_impl_h(struct treemap_node *node); @@ -888,5 +802,3 @@ _Bool tm_print(struct treemap *_map_, FILE *fptr, const char *start, const char fprintf(fptr, "%s", end); return 1; } - -#endif /* CMC_TEST_SRC_TREEMAP */ diff --git a/tests/main/src/treeset.c b/tests/src/cmc/treeset.c similarity index 88% rename from tests/main/src/treeset.c rename to tests/src/cmc/treeset.c index 1bf5884..795a020 100644 --- a/tests/main/src/treeset.c +++ b/tests/src/cmc/treeset.c @@ -1,84 +1,6 @@ -#ifndef CMC_TEST_SRC_TREESET -#define CMC_TEST_SRC_TREESET #include "cmc/treeset.h" -struct treeset -{ - struct treeset_node *root; - size_t count; - int flag; - struct treeset_fval *f_val; - struct cmc_alloc_node *alloc; - struct cmc_callbacks *callbacks; -}; -struct treeset_node -{ - size_t value; - unsigned char height; - struct treeset_node *right; - struct treeset_node *left; - struct treeset_node *parent; -}; -struct treeset_fval -{ - int (*cmp)(size_t, size_t); - size_t (*cpy)(size_t); - _Bool (*str)(FILE *, size_t); - void (*free)(size_t); - size_t (*hash)(size_t); - int (*pri)(size_t, size_t); -}; -struct treeset_iter -{ - struct treeset *target; - struct treeset_node *cursor; - struct treeset_node *first; - struct treeset_node *last; - size_t index; - _Bool start; - _Bool end; -}; -struct treeset *ts_new(struct treeset_fval *f_val); -struct treeset *ts_new_custom(struct treeset_fval *f_val, struct cmc_alloc_node *alloc, - struct cmc_callbacks *callbacks); -void ts_clear(struct treeset *_set_); -void ts_free(struct treeset *_set_); -void ts_customize(struct treeset *_set_, struct cmc_alloc_node *alloc, struct cmc_callbacks *callbacks); -_Bool ts_insert(struct treeset *_set_, size_t value); -_Bool ts_remove(struct treeset *_set_, size_t value); -_Bool ts_max(struct treeset *_set_, size_t *value); -_Bool ts_min(struct treeset *_set_, size_t *value); -_Bool ts_contains(struct treeset *_set_, size_t value); -_Bool ts_empty(struct treeset *_set_); -size_t ts_count(struct treeset *_set_); -int ts_flag(struct treeset *_set_); -struct treeset *ts_copy_of(struct treeset *_set_); -_Bool ts_equals(struct treeset *_set1_, struct treeset *_set2_); -struct treeset *ts_union(struct treeset *_set1_, struct treeset *_set2_); -struct treeset *ts_intersection(struct treeset *_set1_, struct treeset *_set2_); -struct treeset *ts_difference(struct treeset *_set1_, struct treeset *_set2_); -struct treeset *ts_symmetric_difference(struct treeset *_set1_, struct treeset *_set2_); -_Bool ts_is_subset(struct treeset *_set1_, struct treeset *_set2_); -_Bool ts_is_superset(struct treeset *_set1_, struct treeset *_set2_); -_Bool ts_is_proper_subset(struct treeset *_set1_, struct treeset *_set2_); -_Bool ts_is_proper_superset(struct treeset *_set1_, struct treeset *_set2_); -_Bool ts_is_disjointset(struct treeset *_set1_, struct treeset *_set2_); -struct treeset_iter ts_iter_start(struct treeset *target); -struct treeset_iter ts_iter_end(struct treeset *target); -_Bool ts_iter_at_start(struct treeset_iter *iter); -_Bool ts_iter_at_end(struct treeset_iter *iter); -_Bool ts_iter_to_start(struct treeset_iter *iter); -_Bool ts_iter_to_end(struct treeset_iter *iter); -_Bool ts_iter_next(struct treeset_iter *iter); -_Bool ts_iter_prev(struct treeset_iter *iter); -_Bool ts_iter_advance(struct treeset_iter *iter, size_t steps); -_Bool ts_iter_rewind(struct treeset_iter *iter, size_t steps); -_Bool ts_iter_go_to(struct treeset_iter *iter, size_t index); -size_t ts_iter_value(struct treeset_iter *iter); -size_t ts_iter_index(struct treeset_iter *iter); -_Bool ts_to_string(struct treeset *_set_, FILE *fptr); -_Bool ts_print(struct treeset *_set_, FILE *fptr, const char *start, const char *separator, const char *end); static struct treeset_node *ts_impl_new_node(struct treeset *_set_, size_t value); static struct treeset_node *ts_impl_get_node(struct treeset *_set_, size_t value); static unsigned char ts_impl_h(struct treeset_node *node); @@ -917,5 +839,3 @@ _Bool ts_print(struct treeset *_set_, FILE *fptr, const char *start, const char fprintf(fptr, "%s", end); return 1; } - -#endif /* CMC_TEST_SRC_TREESET */ diff --git a/tests/main/unt/bitset.c b/tests/unt/cmc/bitset.h similarity index 91% rename from tests/main/unt/bitset.c rename to tests/unt/cmc/bitset.h index 3e6053f..41f490e 100644 --- a/tests/main/unt/bitset.c +++ b/tests/unt/cmc/bitset.h @@ -1,13 +1,14 @@ -#include "utl.c" -#include "utl/assert.h" -#include "utl/test.h" +#ifndef CMC_TESTS_UNT_CMC_ITSET_H +#define CMC_TESTS_UNT_CMC_ITSET_H -#include "../src/bitset.c" +#include "../utl.h" + +#include "cmc/bitset.h" struct cmc_alloc_node *bs_alloc_node = &(struct cmc_alloc_node){ .malloc = malloc, .calloc = calloc, .realloc = realloc, .free = free }; -CMC_CREATE_UNIT(BitSet, true, { +CMC_CREATE_UNIT(CMCBitSet, true, { const size_t word_bits = sizeof(cmc_bitset_word) * CHAR_BIT; printf("%s", cmc_test_color(5)); @@ -20,7 +21,10 @@ CMC_CREATE_UNIT(BitSet, true, { cmc_assert_not_equals(ptr, NULL, bs); cmc_assert_not_equals(ptr, NULL, bs->buffer); cmc_assert_equals(size_t, bs_bit_to_index(63) + 1, bs->capacity); - cmc_assert_equals(ptr, &cmc_alloc_node_default, bs->alloc); + cmc_assert_equals(ptr, cmc_alloc_node_default.malloc, bs->alloc->malloc); + cmc_assert_equals(ptr, cmc_alloc_node_default.calloc, bs->alloc->calloc); + cmc_assert_equals(ptr, cmc_alloc_node_default.realloc, bs->alloc->realloc); + cmc_assert_equals(ptr, cmc_alloc_node_default.free, bs->alloc->free); cmc_assert_equals(ptr, NULL, bs->callbacks); bs_free(bs); @@ -62,7 +66,10 @@ CMC_CREATE_UNIT(BitSet, true, { cmc_assert_not_equals(ptr, NULL, bs.buffer); cmc_assert_equals(size_t, bs_bit_to_index(63) + 1, bs.capacity); - cmc_assert_equals(ptr, &cmc_alloc_node_default, bs.alloc); + cmc_assert_equals(ptr, cmc_alloc_node_default.malloc, bs.alloc->malloc); + cmc_assert_equals(ptr, cmc_alloc_node_default.calloc, bs.alloc->calloc); + cmc_assert_equals(ptr, cmc_alloc_node_default.realloc, bs.alloc->realloc); + cmc_assert_equals(ptr, cmc_alloc_node_default.free, bs.alloc->free); cmc_assert_equals(ptr, NULL, bs.callbacks); bs_release(bs); @@ -114,7 +121,10 @@ CMC_CREATE_UNIT(BitSet, true, { bs->flag = CMC_FLAG_ERROR; bs_customize(bs, NULL, NULL); - cmc_assert_equals(ptr, &cmc_alloc_node_default, bs->alloc); + cmc_assert_equals(ptr, cmc_alloc_node_default.malloc, bs->alloc->malloc); + cmc_assert_equals(ptr, cmc_alloc_node_default.calloc, bs->alloc->calloc); + cmc_assert_equals(ptr, cmc_alloc_node_default.realloc, bs->alloc->realloc); + cmc_assert_equals(ptr, cmc_alloc_node_default.free, bs->alloc->free); cmc_assert_equals(ptr, NULL, bs->callbacks); cmc_assert_equals(int32_t, CMC_FLAG_OK, bs->flag); @@ -419,7 +429,7 @@ CMC_CREATE_UNIT(BitSet, true, { }); }); -CMC_CREATE_UNIT(BitSetIter, true, { +CMC_CREATE_UNIT(CMCBitSetIter, true, { // const size_t word_bytes = sizeof(cmc_bitset_word); // const size_t word_bits = sizeof(cmc_bitset_word) * CHAR_BIT; @@ -439,14 +449,16 @@ CMC_CREATE_UNIT(BitSetIter, true, { #ifdef CMC_TEST_MAIN int main(void) { - int result = BitSet() + BitSetIter(); + int result = CMCBitSet() + CMCBitSetIter(); printf(" +---------------------------------------------------------------+"); printf("\n"); - printf(" | BitSet Suit : %-47s |\n", result == 0 ? "PASSED" : "FAILED"); + printf(" | CMCBitSet Suit : %-47s |\n", result == 0 ? "PASSED" : "FAILED"); printf(" +---------------------------------------------------------------+"); printf("\n\n\n"); return result; } #endif + +#endif /* CMC_TESTS_UNT_CMC_ITSET_H */ diff --git a/tests/main/unt/deque.c b/tests/unt/cmc/deque.h similarity index 90% rename from tests/main/unt/deque.c rename to tests/unt/cmc/deque.h index 0bdb052..af4fb8e 100644 --- a/tests/main/unt/deque.c +++ b/tests/unt/cmc/deque.h @@ -1,8 +1,9 @@ -#include "utl.c" -#include "utl/assert.h" -#include "utl/test.h" +#ifndef CMC_TESTS_UNT_CMC_EQUE_H +#define CMC_TESTS_UNT_CMC_EQUE_H -#include "../src/deque.c" +#include "../utl.h" + +#include "cmc/deque.h" struct deque_fval *d_fval = &(struct deque_fval){ .cmp = cmc_size_cmp, .cpy = NULL, .str = cmc_size_str, .free = NULL, .hash = cmc_size_hash, .pri = cmc_size_cmp @@ -15,7 +16,7 @@ struct deque_fval *d_fval_counter = &(struct deque_fval){ struct cmc_alloc_node *d_alloc_node = &(struct cmc_alloc_node){ .malloc = malloc, .calloc = calloc, .realloc = realloc, .free = free }; -CMC_CREATE_UNIT(Deque, true, { +CMC_CREATE_UNIT(CMCDeque, true, { CMC_CREATE_TEST(PFX##_new(), { struct deque *d = d_new(1000000, d_fval); @@ -27,7 +28,10 @@ CMC_CREATE_UNIT(Deque, true, { cmc_assert_equals(size_t, 0, d->back); cmc_assert_equals(int32_t, CMC_FLAG_OK, d->flag); cmc_assert_equals(ptr, d_fval, d->f_val); - cmc_assert_equals(ptr, &cmc_alloc_node_default, d->alloc); + cmc_assert_equals(ptr, cmc_alloc_node_default.malloc, d->alloc->malloc); + cmc_assert_equals(ptr, cmc_alloc_node_default.calloc, d->alloc->calloc); + cmc_assert_equals(ptr, cmc_alloc_node_default.realloc, d->alloc->realloc); + cmc_assert_equals(ptr, cmc_alloc_node_default.free, d->alloc->free); cmc_assert_equals(ptr, NULL, d->callbacks); d_free(d); @@ -68,74 +72,77 @@ CMC_CREATE_UNIT(Deque, true, { cmc_assert_equals(ptr, NULL, d); }); - // CMC_CREATE_TEST(PFX##_init(), { - // struct deque d = d_init(1000000, d_fval); + CMC_CREATE_TEST(PFX##_init(), { + struct deque d = d_init(1000000, d_fval); - // cmc_assert_not_equals(ptr, NULL, d.buffer); - // cmc_assert_equals(size_t, 1000000, d.capacity); - // cmc_assert_equals(size_t, 0, d.count); - // cmc_assert_equals(size_t, 0, d.front); - // cmc_assert_equals(size_t, 0, d.back); - // cmc_assert_equals(int32_t, CMC_FLAG_OK, d.flag); - // cmc_assert_equals(ptr, d_fval, d.f_val); - // cmc_assert_equals(ptr, &cmc_alloc_node_default, d.alloc); - // cmc_assert_equals(ptr, NULL, d.callbacks); + cmc_assert_not_equals(ptr, NULL, d.buffer); + cmc_assert_equals(size_t, 1000000, d.capacity); + cmc_assert_equals(size_t, 0, d.count); + cmc_assert_equals(size_t, 0, d.front); + cmc_assert_equals(size_t, 0, d.back); + cmc_assert_equals(int32_t, CMC_FLAG_OK, d.flag); + cmc_assert_equals(ptr, d_fval, d.f_val); + cmc_assert_equals(ptr, cmc_alloc_node_default.malloc, d.alloc->malloc); + cmc_assert_equals(ptr, cmc_alloc_node_default.calloc, d.alloc->calloc); + cmc_assert_equals(ptr, cmc_alloc_node_default.realloc, d.alloc->realloc); + cmc_assert_equals(ptr, cmc_alloc_node_default.free, d.alloc->free); + cmc_assert_equals(ptr, NULL, d.callbacks); - // d_release(d); + d_release(d); - // d = d_init(0, d_fval); + d = d_init(0, d_fval); - // cmc_assert_equals(size_t, 0, d.capacity); - // cmc_assert_equals(ptr, NULL, d.buffer); + cmc_assert_equals(size_t, 0, d.capacity); + cmc_assert_equals(ptr, NULL, d.buffer); - // d = d_init(1000, NULL); + d = d_init(1000, NULL); - // cmc_assert_equals(size_t, 0, d.capacity); - // cmc_assert_equals(ptr, NULL, d.buffer); + cmc_assert_equals(size_t, 0, d.capacity); + cmc_assert_equals(ptr, NULL, d.buffer); - // d = d_init(UINT64_MAX, d_fval); + d = d_init(UINT64_MAX, d_fval); - // cmc_assert_equals(size_t, 0, d.capacity); - // cmc_assert_equals(ptr, NULL, d.buffer); + cmc_assert_equals(size_t, 0, d.capacity); + cmc_assert_equals(ptr, NULL, d.buffer); - // if (d.buffer) - // d_release(d); - // }); + if (d.buffer) + d_release(d); + }); - // CMC_CREATE_TEST(PFX##_init_custom(), { - // struct deque d = - // d_init_custom(1000000, d_fval, d_alloc_node, callbacks); + CMC_CREATE_TEST(PFX##_init_custom(), { + struct deque d = + d_init_custom(1000000, d_fval, d_alloc_node, callbacks); - // cmc_assert_not_equals(ptr, NULL, d.buffer); - // cmc_assert_equals(size_t, 1000000, d.capacity); - // cmc_assert_equals(size_t, 0, d.count); - // cmc_assert_equals(size_t, 0, d.front); - // cmc_assert_equals(size_t, 0, d.back); - // cmc_assert_equals(int32_t, CMC_FLAG_OK, d.flag); - // cmc_assert_equals(ptr, d_fval, d.f_val); - // cmc_assert_equals(ptr, d_alloc_node, d.alloc); - // cmc_assert_equals(ptr, callbacks, d.callbacks); + cmc_assert_not_equals(ptr, NULL, d.buffer); + cmc_assert_equals(size_t, 1000000, d.capacity); + cmc_assert_equals(size_t, 0, d.count); + cmc_assert_equals(size_t, 0, d.front); + cmc_assert_equals(size_t, 0, d.back); + cmc_assert_equals(int32_t, CMC_FLAG_OK, d.flag); + cmc_assert_equals(ptr, d_fval, d.f_val); + cmc_assert_equals(ptr, d_alloc_node, d.alloc); + cmc_assert_equals(ptr, callbacks, d.callbacks); - // d_release(d); + d_release(d); - // d = d_init_custom(0, d_fval, d_alloc_node, callbacks); + d = d_init_custom(0, d_fval, d_alloc_node, callbacks); - // cmc_assert_equals(size_t, 0, d.capacity); - // cmc_assert_equals(ptr, NULL, d.buffer); + cmc_assert_equals(size_t, 0, d.capacity); + cmc_assert_equals(ptr, NULL, d.buffer); - // d = d_init_custom(1000, NULL, d_alloc_node, callbacks); + d = d_init_custom(1000, NULL, d_alloc_node, callbacks); - // cmc_assert_equals(size_t, 0, d.capacity); - // cmc_assert_equals(ptr, NULL, d.buffer); + cmc_assert_equals(size_t, 0, d.capacity); + cmc_assert_equals(ptr, NULL, d.buffer); - // d = d_init_custom(UINT64_MAX, d_fval, d_alloc_node, callbacks); + d = d_init_custom(UINT64_MAX, d_fval, d_alloc_node, callbacks); - // cmc_assert_equals(size_t, 0, d.capacity); - // cmc_assert_equals(ptr, NULL, d.buffer); + cmc_assert_equals(size_t, 0, d.capacity); + cmc_assert_equals(ptr, NULL, d.buffer); - // if (d.buffer) - // d_release(d); - // }); + if (d.buffer) + d_release(d); + }); CMC_CREATE_TEST(PFX##_clear(), { v_total_free = 0; @@ -222,36 +229,36 @@ CMC_CREATE_UNIT(Deque, true, { v_total_free = 0; }); - // CMC_CREATE_TEST(PFX##_release(), { - // v_total_free = 0; + CMC_CREATE_TEST(PFX##_release(), { + v_total_free = 0; - // struct deque d = d_init(100, d_fval_counter); + struct deque d = d_init(100, d_fval_counter); - // cmc_assert_not_equals(ptr, NULL, d.buffer); + cmc_assert_not_equals(ptr, NULL, d.buffer); - // for (size_t i = 1; i <= 1000; i++) - // { - // if (i % 2 == 0) - // d_push_front(&d, i); - // else - // d_push_back(&d, i); - // } + for (size_t i = 1; i <= 1000; i++) + { + if (i % 2 == 0) + d_push_front(&d, i); + else + d_push_back(&d, i); + } - // cmc_assert_equals(size_t, 1000, d_count(&d)); + cmc_assert_equals(size_t, 1000, d_count(&d)); - // size_t sum = 0; - // for (size_t i = d.front, j = 0; j < d.count; - // i = (i + 1) % d.capacity, j++) - // sum += d.buffer[i]; + size_t sum = 0; + for (size_t i = d.front, j = 0; j < d.count; + i = (i + 1) % d.capacity, j++) + sum += d.buffer[i]; - // cmc_assert_equals(size_t, 500500, sum); + cmc_assert_equals(size_t, 500500, sum); - // d_release(d); + d_release(d); - // cmc_assert_equals(size_t, 1000, v_total_free); + cmc_assert_equals(size_t, 1000, v_total_free); - // v_total_free = 0; - // }); + v_total_free = 0; + }); CMC_CREATE_TEST(PFX##_customize(), { struct deque *d = d_new(100, d_fval); @@ -268,7 +275,10 @@ CMC_CREATE_UNIT(Deque, true, { d->flag = CMC_FLAG_ERROR; d_customize(d, NULL, NULL); - cmc_assert_equals(ptr, &cmc_alloc_node_default, d->alloc); + cmc_assert_equals(ptr, cmc_alloc_node_default.malloc, d->alloc->malloc); + cmc_assert_equals(ptr, cmc_alloc_node_default.calloc, d->alloc->calloc); + cmc_assert_equals(ptr, cmc_alloc_node_default.realloc, d->alloc->realloc); + cmc_assert_equals(ptr, cmc_alloc_node_default.free, d->alloc->free); cmc_assert_equals(ptr, NULL, d->callbacks); cmc_assert_equals(int32_t, CMC_FLAG_OK, d_flag(d)); @@ -1253,7 +1263,7 @@ CMC_CREATE_UNIT(Deque, true, { }); }); -CMC_CREATE_UNIT(DequeIter, true, { +CMC_CREATE_UNIT(CMCDequeIter, true, { CMC_CREATE_TEST(PFX##_iter_start(), { struct deque *d = d_new(100, d_fval); @@ -1712,14 +1722,16 @@ CMC_CREATE_UNIT(DequeIter, true, { #ifdef CMC_TEST_MAIN int main(void) { - int result = Deque() + DequeIter(); + int result = CMCDeque() + CMCDequeIter(); printf(" +---------------------------------------------------------------+"); printf("\n"); - printf(" | Deque Suit : %-48s |\n", result == 0 ? "PASSED" : "FAILED"); + printf(" | CMCDeque Suit : %-48s |\n", result == 0 ? "PASSED" : "FAILED"); printf(" +---------------------------------------------------------------+"); printf("\n\n\n"); return result; } #endif + +#endif /* CMC_TESTS_UNT_CMC_EQUE_H */ diff --git a/tests/main/unt/hashbidimap.c b/tests/unt/cmc/hashbidimap.h similarity index 96% rename from tests/main/unt/hashbidimap.c rename to tests/unt/cmc/hashbidimap.h index 1d8bd1e..9c6c411 100644 --- a/tests/main/unt/hashbidimap.c +++ b/tests/unt/cmc/hashbidimap.h @@ -1,8 +1,9 @@ -#include "utl.c" -#include "utl/assert.h" -#include "utl/test.h" +#ifndef CMC_TESTS_UNT_CMC_ASHBIDIMAP_H +#define CMC_TESTS_UNT_CMC_ASHBIDIMAP_H -#include "../src/hashbidimap.c" +#include "../utl.h" + +#include "cmc/hashbidimap.h" struct hashbidimap_fkey *hbm_fkey = &(struct hashbidimap_fkey){ .cmp = cmc_size_cmp, .cpy = NULL, .str = cmc_size_str, .free = NULL, .hash = cmc_size_hash, .pri = cmc_size_cmp @@ -23,7 +24,7 @@ struct hashbidimap_fval *hbm_fval_counter = &(struct hashbidimap_fval){ struct cmc_alloc_node *hbm_alloc_node = &(struct cmc_alloc_node){ .malloc = malloc, .calloc = calloc, .realloc = realloc, .free = free }; -CMC_CREATE_UNIT(HashBidiMap, true, { +CMC_CREATE_UNIT(CMCHashBidiMap, true, { CMC_CREATE_TEST(PFX##_new(), { struct hashbidimap *map = hbm_new(943722, 0.6, hbm_fkey, hbm_fval); @@ -34,7 +35,10 @@ CMC_CREATE_UNIT(HashBidiMap, true, { cmc_assert_equals(int32_t, CMC_FLAG_OK, map->flag); cmc_assert_equals(ptr, hbm_fkey, map->f_key); cmc_assert_equals(ptr, hbm_fval, map->f_val); - cmc_assert_equals(ptr, &cmc_alloc_node_default, map->alloc); + cmc_assert_equals(ptr, cmc_alloc_node_default.malloc, map->alloc->malloc); + cmc_assert_equals(ptr, cmc_alloc_node_default.calloc, map->alloc->calloc); + cmc_assert_equals(ptr, cmc_alloc_node_default.realloc, map->alloc->realloc); + cmc_assert_equals(ptr, cmc_alloc_node_default.free, map->alloc->free); cmc_assert_equals(ptr, NULL, map->callbacks); cmc_assert_greater_equals(size_t, (943722 / 0.6), hbm_capacity(map)); @@ -162,7 +166,10 @@ CMC_CREATE_UNIT(HashBidiMap, true, { cmc_assert_not_equals(ptr, NULL, map); - cmc_assert_equals(ptr, &cmc_alloc_node_default, map->alloc); + cmc_assert_equals(ptr, cmc_alloc_node_default.malloc, map->alloc->malloc); + cmc_assert_equals(ptr, cmc_alloc_node_default.calloc, map->alloc->calloc); + cmc_assert_equals(ptr, cmc_alloc_node_default.realloc, map->alloc->realloc); + cmc_assert_equals(ptr, cmc_alloc_node_default.free, map->alloc->free); cmc_assert_equals(ptr, NULL, map->callbacks); hbm_free(map); @@ -793,7 +800,7 @@ CMC_CREATE_UNIT(HashBidiMap, true, { }); }); -CMC_CREATE_UNIT(HashBidiMapIter, true, { +CMC_CREATE_UNIT(CMCHashBidiMapIter, true, { CMC_CREATE_TEST(PFX##_iter_start, { // WIP cmc_assert(true); @@ -804,14 +811,16 @@ CMC_CREATE_UNIT(HashBidiMapIter, true, { #ifdef CMC_TEST_MAIN int main(void) { - int result = HashBidiMap() + HashBidiMapIter(); + int result = CMCHashBidiMap() + CMCHashBidiMapIter(); printf(" +---------------------------------------------------------------+"); printf("\n"); - printf(" | HashBidiMap Suit : %-42s |\n", result == 0 ? "PASSED" : "FAILED"); + printf(" | CMCHashBidiMap Suit : %-42s |\n", result == 0 ? "PASSED" : "FAILED"); printf(" +---------------------------------------------------------------+"); printf("\n\n\n"); return result; } #endif + +#endif /* CMC_TESTS_UNT_CMC_ASHBIDIMAP_H */ diff --git a/tests/main/unt/hashmap.c b/tests/unt/cmc/hashmap.h similarity index 87% rename from tests/main/unt/hashmap.c rename to tests/unt/cmc/hashmap.h index 868da06..a0710a2 100644 --- a/tests/main/unt/hashmap.c +++ b/tests/unt/cmc/hashmap.h @@ -1,8 +1,9 @@ -#include "utl.c" -#include "utl/assert.h" -#include "utl/test.h" +#ifndef CMC_TESTS_UNT_CMC_ASHMAP_H +#define CMC_TESTS_UNT_CMC_ASHMAP_H -#include "../src/hashmap.c" +#include "../utl.h" + +#include "cmc/hashmap.h" struct hashmap_fkey *hm_fkey = &(struct hashmap_fkey){ .cmp = cmc_size_cmp, .cpy = NULL, .str = cmc_size_str, .free = NULL, .hash = cmc_size_hash, .pri = cmc_size_cmp @@ -23,7 +24,7 @@ struct hashmap_fval *hm_fval_counter = &(struct hashmap_fval){ struct cmc_alloc_node *hm_alloc_node = &(struct cmc_alloc_node){ .malloc = malloc, .calloc = calloc, .realloc = realloc, .free = free }; -CMC_CREATE_UNIT(HashMap, true, { +CMC_CREATE_UNIT(CMCHashMap, true, { CMC_CREATE_TEST(PFX##_new(), { struct hashmap *map = hm_new(943722, 0.6, hm_fkey, hm_fval); @@ -34,7 +35,10 @@ CMC_CREATE_UNIT(HashMap, true, { cmc_assert_equals(int32_t, CMC_FLAG_OK, map->flag); cmc_assert_equals(ptr, hm_fkey, map->f_key); cmc_assert_equals(ptr, hm_fval, map->f_val); - cmc_assert_equals(ptr, &cmc_alloc_node_default, map->alloc); + cmc_assert_equals(ptr, cmc_alloc_node_default.malloc, map->alloc->malloc); + cmc_assert_equals(ptr, cmc_alloc_node_default.calloc, map->alloc->calloc); + cmc_assert_equals(ptr, cmc_alloc_node_default.realloc, map->alloc->realloc); + cmc_assert_equals(ptr, cmc_alloc_node_default.free, map->alloc->free); cmc_assert_equals(ptr, NULL, map->callbacks); cmc_assert_greater_equals(size_t, (943722 / 0.6), hm_capacity(map)); @@ -90,70 +94,73 @@ CMC_CREATE_UNIT(HashMap, true, { cmc_assert_equals(ptr, NULL, map); }); - // CMC_CREATE_TEST(PFX##_init(), { - // struct hashmap map = hm_init(943722, 0.6, hm_fkey, hm_fval); + CMC_CREATE_TEST(PFX##_init(), { + struct hashmap map = hm_init(943722, 0.6, hm_fkey, hm_fval); - // cmc_assert_not_equals(ptr, NULL, map.buffer); - // cmc_assert_equals(size_t, 0, map.count); - // cmc_assert_equals(double, 0.6, map.load); - // cmc_assert_equals(int32_t, CMC_FLAG_OK, map.flag); - // cmc_assert_equals(ptr, hm_fkey, map.f_key); - // cmc_assert_equals(ptr, hm_fval, map.f_val); - // cmc_assert_equals(ptr, &cmc_alloc_node_default, map.alloc); - // cmc_assert_equals(ptr, NULL, map.callbacks); + cmc_assert_not_equals(ptr, NULL, map.buffer); + cmc_assert_equals(size_t, 0, map.count); + cmc_assert_equals(double, 0.6, map.load); + cmc_assert_equals(int32_t, CMC_FLAG_OK, map.flag); + cmc_assert_equals(ptr, hm_fkey, map.f_key); + cmc_assert_equals(ptr, hm_fval, map.f_val); + cmc_assert_equals(ptr, cmc_alloc_node_default.malloc, map.alloc->malloc); + cmc_assert_equals(ptr, cmc_alloc_node_default.calloc, map.alloc->calloc); + cmc_assert_equals(ptr, cmc_alloc_node_default.realloc, map.alloc->realloc); + cmc_assert_equals(ptr, cmc_alloc_node_default.free, map.alloc->free); + cmc_assert_equals(ptr, NULL, map.callbacks); - // cmc_assert_greater_equals(size_t, (943722 / 0.6), hm_capacity(&map)); + cmc_assert_greater_equals(size_t, (943722 / 0.6), hm_capacity(&map)); - // hm_release(map); + hm_release(map); - // map = hm_init(0, 0.6, hm_fkey, hm_fval); - // cmc_assert_equals(ptr, NULL, map.buffer); + map = hm_init(0, 0.6, hm_fkey, hm_fval); + cmc_assert_equals(ptr, NULL, map.buffer); - // map = hm_init(UINT64_MAX, 0.99, hm_fkey, hm_fval); - // cmc_assert_equals(ptr, NULL, map.buffer); + map = hm_init(UINT64_MAX, 0.99, hm_fkey, hm_fval); + cmc_assert_equals(ptr, NULL, map.buffer); - // map = hm_init(1000, 0.6, hm_fkey, NULL); - // cmc_assert_equals(ptr, NULL, map.buffer); + map = hm_init(1000, 0.6, hm_fkey, NULL); + cmc_assert_equals(ptr, NULL, map.buffer); - // map = hm_init(1000, 0.6, NULL, hm_fval); - // cmc_assert_equals(ptr, NULL, map.buffer); + map = hm_init(1000, 0.6, NULL, hm_fval); + cmc_assert_equals(ptr, NULL, map.buffer); - // map = hm_init(1000, 0.6, NULL, NULL); - // cmc_assert_equals(ptr, NULL, map.buffer); - // }); + map = hm_init(1000, 0.6, NULL, NULL); + cmc_assert_equals(ptr, NULL, map.buffer); + }); - // CMC_CREATE_TEST(PFX##_init_custom(), { - // struct hashmap map = hm_init_custom(943722, 0.6, hm_fkey, hm_fval, - // hm_alloc_node, callbacks); + CMC_CREATE_TEST(PFX##_init_custom(), { + struct hashmap map = hm_init_custom(943722, 0.6, hm_fkey, hm_fval, + hm_alloc_node, callbacks); - // cmc_assert_not_equals(ptr, NULL, map.buffer); - // cmc_assert_equals(size_t, 0, map.count); - // cmc_assert_equals(double, 0.6, map.load); - // cmc_assert_equals(int32_t, CMC_FLAG_OK, map.flag); - // cmc_assert_equals(ptr, hm_fkey, map.f_key); - // cmc_assert_equals(ptr, hm_fval, map.f_val); - // cmc_assert_equals(ptr, hm_alloc_node, map.alloc); - // cmc_assert_equals(ptr, callbacks, map.callbacks); + cmc_assert_not_equals(ptr, NULL, map.buffer); + cmc_assert_equals(size_t, 0, map.count); + cmc_assert_equals(double, 0.6, map.load); + cmc_assert_equals(int32_t, CMC_FLAG_OK, map.flag); + cmc_assert_equals(ptr, hm_fkey, map.f_key); + cmc_assert_equals(ptr, hm_fval, map.f_val); + cmc_assert_equals(ptr, hm_alloc_node, map.alloc); + cmc_assert_equals(ptr, callbacks, map.callbacks); - // cmc_assert_greater_equals(size_t, (943722 / 0.6), hm_capacity(&map)); + cmc_assert_greater_equals(size_t, (943722 / 0.6), hm_capacity(&map)); - // hm_release(map); + hm_release(map); - // map = hm_init_custom(0, 0.6, hm_fkey, hm_fval, NULL, NULL); - // cmc_assert_equals(ptr, NULL, map.buffer); + map = hm_init_custom(0, 0.6, hm_fkey, hm_fval, NULL, NULL); + cmc_assert_equals(ptr, NULL, map.buffer); - // map = hm_init_custom(UINT64_MAX, 0.99, hm_fkey, hm_fval, NULL, NULL); - // cmc_assert_equals(ptr, NULL, map.buffer); + map = hm_init_custom(UINT64_MAX, 0.99, hm_fkey, hm_fval, NULL, NULL); + cmc_assert_equals(ptr, NULL, map.buffer); - // map = hm_init_custom(1000, 0.6, hm_fkey, NULL, NULL, NULL); - // cmc_assert_equals(ptr, NULL, map.buffer); + map = hm_init_custom(1000, 0.6, hm_fkey, NULL, NULL, NULL); + cmc_assert_equals(ptr, NULL, map.buffer); - // map = hm_init_custom(1000, 0.6, NULL, hm_fval, NULL, NULL); - // cmc_assert_equals(ptr, NULL, map.buffer); + map = hm_init_custom(1000, 0.6, NULL, hm_fval, NULL, NULL); + cmc_assert_equals(ptr, NULL, map.buffer); - // map = hm_init_custom(1000, 0.6, NULL, NULL, NULL, NULL); - // cmc_assert_equals(ptr, NULL, map.buffer); - // }); + map = hm_init_custom(1000, 0.6, NULL, NULL, NULL, NULL); + cmc_assert_equals(ptr, NULL, map.buffer); + }); CMC_CREATE_TEST(PFX##_clear(), { k_total_free = 0; @@ -217,35 +224,35 @@ CMC_CREATE_UNIT(HashMap, true, { v_total_free = 0; }); - // CMC_CREATE_TEST(PFX##_release(), { - // k_total_free = 0; - // v_total_free = 0; - // struct hashmap map = - // hm_init(100, 0.6, hm_fkey_counter, hm_fval_counter); + CMC_CREATE_TEST(PFX##_release(), { + k_total_free = 0; + v_total_free = 0; + struct hashmap map = + hm_init(100, 0.6, hm_fkey_counter, hm_fval_counter); - // cmc_assert_not_equals(ptr, NULL, map.buffer); + cmc_assert_not_equals(ptr, NULL, map.buffer); - // for (size_t i = 1; i <= 1000; i++) - // hm_insert(&map, i, i); + for (size_t i = 1; i <= 1000; i++) + hm_insert(&map, i, i); - // cmc_assert_equals(size_t, 1000, map.count); + cmc_assert_equals(size_t, 1000, map.count); - // hm_release(map); + hm_release(map); - // cmc_assert_equals(int32_t, 1000, k_total_free); - // cmc_assert_equals(int32_t, 1000, v_total_free); + cmc_assert_equals(int32_t, 1000, k_total_free); + cmc_assert_equals(int32_t, 1000, v_total_free); - // map = hm_init(1000, 0.6, hm_fkey_counter, hm_fval_counter); + map = hm_init(1000, 0.6, hm_fkey_counter, hm_fval_counter); - // cmc_assert_not_equals(ptr, NULL, map.buffer); + cmc_assert_not_equals(ptr, NULL, map.buffer); - // hm_release(map); + hm_release(map); - // cmc_assert_equals(int32_t, 1000, k_total_free); - // cmc_assert_equals(int32_t, 1000, v_total_free); - // k_total_free = 0; - // v_total_free = 0; - // }); + cmc_assert_equals(int32_t, 1000, k_total_free); + cmc_assert_equals(int32_t, 1000, v_total_free); + k_total_free = 0; + v_total_free = 0; + }); CMC_CREATE_TEST(PFX##_customize(), { struct hashmap *map = hm_new(100, 0.6, hm_fkey, hm_fval); @@ -262,7 +269,10 @@ CMC_CREATE_UNIT(HashMap, true, { map->flag = CMC_FLAG_ERROR; hm_customize(map, NULL, NULL); - cmc_assert_equals(ptr, &cmc_alloc_node_default, map->alloc); + cmc_assert_equals(ptr, cmc_alloc_node_default.malloc, map->alloc->malloc); + cmc_assert_equals(ptr, cmc_alloc_node_default.calloc, map->alloc->calloc); + cmc_assert_equals(ptr, cmc_alloc_node_default.realloc, map->alloc->realloc); + cmc_assert_equals(ptr, cmc_alloc_node_default.free, map->alloc->free); cmc_assert_equals(ptr, NULL, map->callbacks); cmc_assert_equals(int32_t, CMC_FLAG_OK, map->flag); @@ -370,8 +380,8 @@ CMC_CREATE_UNIT(HashMap, true, { for (size_t i = 0; i < 6; i++) cmc_assert(hm_insert(map, i, i)); - for (size_t i = 0; i < 6; i++) - cmc_assert_equals(size_t, i, hm_impl_get_entry(map, i)->dist); + // for (size_t i = 0; i < 6; i++) + // cmc_assert_equals(size_t, i, hm_impl_get_entry(map, i)->dist); hm_fkey->hash = cmc_size_hash; @@ -874,7 +884,7 @@ struct hashmap_fkey *hm_fkey_numhash = &(struct hashmap_fkey){ .cmp = cmc_size_cmp, .cpy = NULL, .str = cmc_size_str, .free = NULL, .hash = numhash, .pri = cmc_size_cmp }; -CMC_CREATE_UNIT(HashMapIter, true, { +CMC_CREATE_UNIT(CMCHashMapIter, true, { CMC_CREATE_TEST(PFX##_iter_start(), { struct hashmap *map = hm_new(100, 0.6, hm_fkey_numhash, hm_fval); @@ -1318,14 +1328,16 @@ CMC_CREATE_UNIT(HashMapIter, true, { #ifdef CMC_TEST_MAIN int main(void) { - int result = HashMap() + HashMapIter(); + int result = CMCHashMap() + CMCHashMapIter(); printf(" +---------------------------------------------------------------+"); printf("\n"); - printf(" | HashMap Suit : %-46s |\n", result == 0 ? "PASSED" : "FAILED"); + printf(" | CMCHashMap Suit : %-46s |\n", result == 0 ? "PASSED" : "FAILED"); printf(" +---------------------------------------------------------------+"); printf("\n\n\n"); return result; } #endif + +#endif /* CMC_TESTS_UNT_CMC_ASHMAP_H */ diff --git a/tests/main/unt/hashmultimap.c b/tests/unt/cmc/hashmultimap.h similarity index 97% rename from tests/main/unt/hashmultimap.c rename to tests/unt/cmc/hashmultimap.h index 15df5e2..343ff93 100644 --- a/tests/main/unt/hashmultimap.c +++ b/tests/unt/cmc/hashmultimap.h @@ -1,8 +1,9 @@ -#include "utl.c" -#include "utl/assert.h" -#include "utl/test.h" +#ifndef CMC_TESTS_UNT_CMC_ASHMULTIMAP_H +#define CMC_TESTS_UNT_CMC_ASHMULTIMAP_H -#include "../src/hashmultimap.c" +#include "../utl.h" + +#include "cmc/hashmultimap.h" struct hashmultimap_fkey *hmm_fkey = &(struct hashmultimap_fkey){ .cmp = cmc_size_cmp, .cpy = NULL, .str = cmc_size_str, .free = NULL, .hash = cmc_size_hash, .pri = cmc_size_cmp @@ -23,7 +24,7 @@ struct hashmultimap_fval *hmm_fval_counter = &(struct hashmultimap_fval){ struct cmc_alloc_node *hmm_alloc_node = &(struct cmc_alloc_node){ .malloc = malloc, .calloc = calloc, .realloc = realloc, .free = free }; -CMC_CREATE_UNIT(HashMultiMap, true, { +CMC_CREATE_UNIT(CMCHashMultiMap, true, { CMC_CREATE_TEST(PFX##_new(), { struct hashmultimap *map = hmm_new(943722, 0.6, hmm_fkey, hmm_fval); @@ -34,7 +35,10 @@ CMC_CREATE_UNIT(HashMultiMap, true, { cmc_assert_equals(int32_t, CMC_FLAG_OK, map->flag); cmc_assert_equals(ptr, hmm_fkey, map->f_key); cmc_assert_equals(ptr, hmm_fval, map->f_val); - cmc_assert_equals(ptr, &cmc_alloc_node_default, map->alloc); + cmc_assert_equals(ptr, cmc_alloc_node_default.malloc, map->alloc->malloc); + cmc_assert_equals(ptr, cmc_alloc_node_default.calloc, map->alloc->calloc); + cmc_assert_equals(ptr, cmc_alloc_node_default.realloc, map->alloc->realloc); + cmc_assert_equals(ptr, cmc_alloc_node_default.free, map->alloc->free); cmc_assert_equals(ptr, NULL, map->callbacks); cmc_assert_greater_equals(size_t, (943722 / 0.6), hmm_capacity(map)); @@ -464,7 +468,7 @@ struct hashmultimap_fkey *hmm_fkey_numhash = &(struct hashmultimap_fkey){ .cmp = cmc_size_cmp, .cpy = NULL, .str = cmc_size_str, .free = NULL, .hash = numhash, .pri = cmc_size_cmp }; -CMC_CREATE_UNIT(HashMultiMapIter, true, { +CMC_CREATE_UNIT(CMCHashMultiMapIter, true, { CMC_CREATE_TEST(PFX##_iter_start(), { struct hashmultimap *map = hmm_new(100, 0.6, hmm_fkey_numhash, hmm_fval); @@ -908,14 +912,16 @@ CMC_CREATE_UNIT(HashMultiMapIter, true, { #ifdef CMC_TEST_MAIN int main(void) { - int result = HashMultiMap() + HashMultiMapIter(); + int result = CMCHashMultiMap() + CMCHashMultiMapIter(); printf(" +---------------------------------------------------------------+"); printf("\n"); - printf(" | HashMultiMap Suit : %-41s |\n", result == 0 ? "PASSED" : "FAILED"); + printf(" | CMCHashMultiMap Suit : %-41s |\n", result == 0 ? "PASSED" : "FAILED"); printf(" +---------------------------------------------------------------+"); printf("\n\n\n"); return result; } #endif + +#endif /* CMC_TESTS_UNT_CMC_ASHMULTIMAP_H */ diff --git a/tests/main/unt/hashmultiset.c b/tests/unt/cmc/hashmultiset.h similarity index 97% rename from tests/main/unt/hashmultiset.c rename to tests/unt/cmc/hashmultiset.h index 0992033..bb70897 100644 --- a/tests/main/unt/hashmultiset.c +++ b/tests/unt/cmc/hashmultiset.h @@ -1,8 +1,9 @@ -#include "utl.c" -#include "utl/assert.h" -#include "utl/test.h" +#ifndef CMC_TESTS_UNT_CMC_ASHMULTISET_H +#define CMC_TESTS_UNT_CMC_ASHMULTISET_H -#include "../src/hashmultiset.c" +#include "../utl.h" + +#include "cmc/hashmultiset.h" struct hashmultiset_fval *hms_fval = &(struct hashmultiset_fval){ .cmp = cmc_size_cmp, .cpy = NULL, .str = cmc_size_str, .free = NULL, .hash = cmc_size_hash, .pri = cmc_size_cmp @@ -15,7 +16,7 @@ struct hashmultiset_fval *hms_fval_counter = &(struct hashmultiset_fval){ struct cmc_alloc_node *hms_alloc_node = &(struct cmc_alloc_node){ .malloc = malloc, .calloc = calloc, .realloc = realloc, .free = free }; -CMC_CREATE_UNIT(HashMultiSet, true, { +CMC_CREATE_UNIT(CMCHashMultiSet, true, { CMC_CREATE_TEST(PFX##_new(), { struct hashmultiset *set = hms_new(943722, 0.6, hms_fval); @@ -25,7 +26,10 @@ CMC_CREATE_UNIT(HashMultiSet, true, { cmc_assert_equals(double, 0.6, set->load); cmc_assert_equals(int32_t, CMC_FLAG_OK, set->flag); cmc_assert_equals(ptr, hms_fval, set->f_val); - cmc_assert_equals(ptr, &cmc_alloc_node_default, set->alloc); + cmc_assert_equals(ptr, cmc_alloc_node_default.malloc, set->alloc->malloc); + cmc_assert_equals(ptr, cmc_alloc_node_default.calloc, set->alloc->calloc); + cmc_assert_equals(ptr, cmc_alloc_node_default.realloc, set->alloc->realloc); + cmc_assert_equals(ptr, cmc_alloc_node_default.free, set->alloc->free); cmc_assert_equals(ptr, NULL, set->callbacks); cmc_assert_greater_equals(size_t, (943722 / 0.6), hms_capacity(set)); @@ -418,7 +422,7 @@ struct hashmultiset_fval *hms_fval_numhash = &(struct hashmultiset_fval){ .cmp = cmc_size_cmp, .cpy = NULL, .str = cmc_size_str, .free = NULL, .hash = numhash, .pri = cmc_size_cmp }; -CMC_CREATE_UNIT(HashMultiSetIter, true, { +CMC_CREATE_UNIT(CMCHashMultiSetIter, true, { CMC_CREATE_TEST(PFX##_iter_start(), { struct hashmultiset *set = hms_new(100, 0.6, hms_fval_numhash); @@ -845,14 +849,16 @@ CMC_CREATE_UNIT(HashMultiSetIter, true, { #ifdef CMC_TEST_MAIN int main(void) { - int result = HashMultiSet() + HashMultiSetIter(); + int result = CMCHashMultiSet() + CMCHashMultiSetIter(); printf(" +---------------------------------------------------------------+"); printf("\n"); - printf(" | HashMultiSet Suit : %-41s |\n", result == 0 ? "PASSED" : "FAILED"); + printf(" | CMCHashMultiSet Suit : %-41s |\n", result == 0 ? "PASSED" : "FAILED"); printf(" +---------------------------------------------------------------+"); printf("\n\n\n"); return result; } #endif + +#endif /* CMC_TESTS_UNT_CMC_ASHMULTISET_H */ diff --git a/tests/main/unt/hashset.c b/tests/unt/cmc/hashset.h similarity index 97% rename from tests/main/unt/hashset.c rename to tests/unt/cmc/hashset.h index 78e79a2..38e2933 100644 --- a/tests/main/unt/hashset.c +++ b/tests/unt/cmc/hashset.h @@ -1,8 +1,9 @@ -#include "utl.c" -#include "utl/assert.h" -#include "utl/test.h" +#ifndef CMC_TESTS_UNT_CMC_ASHSET_H +#define CMC_TESTS_UNT_CMC_ASHSET_H -#include "../src/hashset.c" +#include "../utl.h" + +#include "cmc/hashset.h" struct hashset_fval *hs_fval = &(struct hashset_fval){ .cmp = cmc_size_cmp, .cpy = NULL, .str = cmc_size_str, .free = NULL, .hash = cmc_size_hash, .pri = cmc_size_cmp @@ -15,7 +16,7 @@ struct hashset_fval *hs_fval_counter = &(struct hashset_fval){ struct cmc_alloc_node *hs_alloc_node = &(struct cmc_alloc_node){ .malloc = malloc, .calloc = calloc, .realloc = realloc, .free = free }; -CMC_CREATE_UNIT(HashSet, true, { +CMC_CREATE_UNIT(CMCHashSet, true, { CMC_CREATE_TEST(PFX##_new(), { struct hashset *set = hs_new(943722, 0.6, hs_fval); @@ -25,7 +26,10 @@ CMC_CREATE_UNIT(HashSet, true, { cmc_assert_equals(double, 0.6, set->load); cmc_assert_equals(int32_t, CMC_FLAG_OK, set->flag); cmc_assert_equals(ptr, hs_fval, set->f_val); - cmc_assert_equals(ptr, &cmc_alloc_node_default, set->alloc); + cmc_assert_equals(ptr, cmc_alloc_node_default.malloc, set->alloc->malloc); + cmc_assert_equals(ptr, cmc_alloc_node_default.calloc, set->alloc->calloc); + cmc_assert_equals(ptr, cmc_alloc_node_default.realloc, set->alloc->realloc); + cmc_assert_equals(ptr, cmc_alloc_node_default.free, set->alloc->free); cmc_assert_equals(ptr, NULL, set->callbacks); cmc_assert_greater_equals(size_t, (943722 / 0.6), hs_capacity(set)); @@ -224,8 +228,8 @@ CMC_CREATE_UNIT(HashSet, true, { for (size_t i = 0; i < 6; i++) cmc_assert(hs_insert(set, i)); - for (size_t i = 0; i < 6; i++) - cmc_assert_equals(size_t, i, hs_impl_get_entry(set, i)->dist); + // for (size_t i = 0; i < 6; i++) + // cmc_assert_equals(size_t, i, hs_impl_get_entry(set, i)->dist); hs_fval->hash = cmc_size_hash; @@ -618,7 +622,7 @@ struct hashset_fval *hs_fval_numhash = &(struct hashset_fval){ .cmp = cmc_size_cmp, .cpy = NULL, .str = cmc_size_str, .free = NULL, .hash = numhash, .pri = cmc_size_cmp }; -CMC_CREATE_UNIT(HashSetIter, true, { +CMC_CREATE_UNIT(CMCHashSetIter, true, { CMC_CREATE_TEST(PFX##_iter_start(), { struct hashset *set = hs_new(100, 0.6, hs_fval_numhash); @@ -1025,14 +1029,16 @@ CMC_CREATE_UNIT(HashSetIter, true, { #ifdef CMC_TEST_MAIN int main(void) { - int result = HashSet() + HashSetIter(); + int result = CMCHashSet() + CMCHashSetIter(); printf(" +---------------------------------------------------------------+"); printf("\n"); - printf(" | HashSet Suit : %-46s |\n", result == 0 ? "PASSED" : "FAILED"); + printf(" | CMCHashSet Suit : %-46s |\n", result == 0 ? "PASSED" : "FAILED"); printf(" +---------------------------------------------------------------+"); printf("\n\n\n"); return result; } #endif + +#endif /* CMC_TESTS_UNT_CMC_ASHSET_H */ diff --git a/tests/main/unt/heap.c b/tests/unt/cmc/heap.h similarity index 98% rename from tests/main/unt/heap.c rename to tests/unt/cmc/heap.h index 94f2fa8..ca320ef 100644 --- a/tests/main/unt/heap.c +++ b/tests/unt/cmc/heap.h @@ -1,14 +1,15 @@ -#include "utl.c" -#include "utl/assert.h" -#include "utl/test.h" +#ifndef CMC_TESTS_UNT_CMC_EAP_H +#define CMC_TESTS_UNT_CMC_EAP_H -#include "../src/heap.c" +#include "../utl.h" + +#include "cmc/heap.h" struct heap_fval *h_fval = &(struct heap_fval){ .cmp = cmc_size_cmp, .cpy = NULL, .str = cmc_size_str, .free = NULL, .hash = cmc_size_hash, .pri = cmc_size_cmp }; -CMC_CREATE_UNIT(Heap, true, { +CMC_CREATE_UNIT(CMCHeap, true, { CMC_CREATE_TEST(new, { struct heap *h = h_new(1000000, CMC_MAX_HEAP, h_fval); @@ -286,7 +287,7 @@ CMC_CREATE_UNIT(Heap, true, { }); }); -CMC_CREATE_UNIT(HeapIter, true, { +CMC_CREATE_UNIT(CMCHeapIter, true, { CMC_CREATE_TEST(PFX##_iter_start(), { struct heap *h = h_new(100, CMC_MAX_HEAP, h_fval); @@ -713,14 +714,16 @@ CMC_CREATE_UNIT(HeapIter, true, { #ifdef CMC_TEST_MAIN int main(void) { - int result = Heap() + HeapIter(); + int result = CMCHeap() + CMCHeapIter(); printf(" +---------------------------------------------------------------+"); printf("\n"); - printf(" | Heap Suit : %-49s |\n", result == 0 ? "PASSED" : "FAILED"); + printf(" | CMCHeap Suit : %-49s |\n", result == 0 ? "PASSED" : "FAILED"); printf(" +---------------------------------------------------------------+"); printf("\n\n\n"); return result; } #endif + +#endif /* CMC_TESTS_UNT_CMC_EAP_H */ diff --git a/tests/main/unt/intervalheap.c b/tests/unt/cmc/intervalheap.h similarity index 96% rename from tests/main/unt/intervalheap.c rename to tests/unt/cmc/intervalheap.h index 9d3d06c..6b28430 100644 --- a/tests/main/unt/intervalheap.c +++ b/tests/unt/cmc/intervalheap.h @@ -1,8 +1,9 @@ -#include "utl.c" -#include "utl/assert.h" -#include "utl/test.h" +#ifndef CMC_TESTS_UNT_CMC_NTERVALHEAP_H +#define CMC_TESTS_UNT_CMC_NTERVALHEAP_H -#include "../src/intervalheap.c" +#include "../utl.h" + +#include "cmc/intervalheap.h" struct intervalheap_fval *ih_fval = &(struct intervalheap_fval){ .cmp = cmc_size_cmp, .cpy = NULL, .str = cmc_size_str, .free = NULL, .hash = cmc_size_hash, .pri = cmc_size_cmp @@ -15,7 +16,7 @@ struct intervalheap_fval *ih_fval_counter = &(struct intervalheap_fval){ struct cmc_alloc_node *ih_alloc_node = &(struct cmc_alloc_node){ .malloc = malloc, .calloc = calloc, .realloc = realloc, .free = free }; -CMC_CREATE_UNIT(IntervalHeap, true, { +CMC_CREATE_UNIT(CMCIntervalHeap, true, { CMC_CREATE_TEST(PFX##_new(), { struct intervalheap *ih = ih_new(1000000, ih_fval); @@ -86,7 +87,10 @@ CMC_CREATE_UNIT(IntervalHeap, true, { cmc_assert_not_equals(ptr, NULL, ih); cmc_assert_equals(size_t, 1, ih_capacity(ih)); - cmc_assert_equals(ptr, &cmc_alloc_node_default, ih->alloc); + cmc_assert_equals(ptr, cmc_alloc_node_default.malloc, ih->alloc->malloc); + cmc_assert_equals(ptr, cmc_alloc_node_default.calloc, ih->alloc->calloc); + cmc_assert_equals(ptr, cmc_alloc_node_default.realloc, ih->alloc->realloc); + cmc_assert_equals(ptr, cmc_alloc_node_default.free, ih->alloc->free); cmc_assert_equals(ptr, NULL, ih->callbacks); ih_free(ih); @@ -196,7 +200,10 @@ CMC_CREATE_UNIT(IntervalHeap, true, { ih->flag = CMC_FLAG_ERROR; ih_customize(ih, NULL, NULL); - cmc_assert_equals(ptr, &cmc_alloc_node_default, ih->alloc); + cmc_assert_equals(ptr, cmc_alloc_node_default.malloc, ih->alloc->malloc); + cmc_assert_equals(ptr, cmc_alloc_node_default.calloc, ih->alloc->calloc); + cmc_assert_equals(ptr, cmc_alloc_node_default.realloc, ih->alloc->realloc); + cmc_assert_equals(ptr, cmc_alloc_node_default.free, ih->alloc->free); cmc_assert_equals(ptr, NULL, ih->callbacks); cmc_assert_equals(int32_t, CMC_FLAG_OK, ih->flag); @@ -603,7 +610,7 @@ CMC_CREATE_UNIT(IntervalHeap, true, { }); }); -CMC_CREATE_UNIT(IntervalHeapIter, true, { +CMC_CREATE_UNIT(CMCIntervalHeapIter, true, { CMC_CREATE_TEST(PFX##_iter_start(), { struct intervalheap *ih = ih_new(100, ih_fval); @@ -1032,14 +1039,16 @@ CMC_CREATE_UNIT(IntervalHeapIter, true, { #ifdef CMC_TEST_MAIN int main(void) { - int result = IntervalHeap() + IntervalHeapIter(); + int result = CMCIntervalHeap() + CMCIntervalHeapIter(); printf(" +---------------------------------------------------------------+"); printf("\n"); - printf(" | IntervalHeap Suit : %-41s |\n", result == 0 ? "PASSED" : "FAILED"); + printf(" | CMCIntervalHeap Suit : %-41s |\n", result == 0 ? "PASSED" : "FAILED"); printf(" +---------------------------------------------------------------+"); printf("\n\n\n"); return result; } #endif + +#endif /* CMC_TESTS_UNT_CMC_NTERVALHEAP_H */ diff --git a/tests/main/unt/linkedlist.c b/tests/unt/cmc/linkedlist.h similarity index 98% rename from tests/main/unt/linkedlist.c rename to tests/unt/cmc/linkedlist.h index cc4989e..cb78499 100644 --- a/tests/main/unt/linkedlist.c +++ b/tests/unt/cmc/linkedlist.h @@ -1,14 +1,15 @@ -#include "utl.c" -#include "utl/assert.h" -#include "utl/test.h" +#ifndef CMC_TESTS_UNT_CMC_INKEDLIST_H +#define CMC_TESTS_UNT_CMC_INKEDLIST_H -#include "../src/linkedlist.c" +#include "../utl.h" + +#include "cmc/linkedlist.h" struct linkedlist_fval *ll_fval = &(struct linkedlist_fval){ .cmp = cmc_size_cmp, .cpy = NULL, .str = cmc_size_str, .free = NULL, .hash = cmc_size_hash, .pri = cmc_size_cmp }; -CMC_CREATE_UNIT(LinkedList, true, { +CMC_CREATE_UNIT(CMCLinkedList, true, { CMC_CREATE_TEST(new, { struct linkedlist *ll = ll_new(ll_fval); @@ -339,7 +340,7 @@ CMC_CREATE_UNIT(LinkedList, true, { }); }); -CMC_CREATE_UNIT(LinkedListIter, true, { +CMC_CREATE_UNIT(CMCLinkedListIter, true, { CMC_CREATE_TEST(PFX##_iter_start(), { struct linkedlist *ll = ll_new(ll_fval); @@ -798,14 +799,16 @@ CMC_CREATE_UNIT(LinkedListIter, true, { #ifdef CMC_TEST_MAIN int main(void) { - int result = LinkedList() + LinkedListIter(); + int result = CMCLinkedList() + CMCLinkedListIter(); printf(" +---------------------------------------------------------------+"); printf("\n"); - printf(" | LinkedList Suit : %-43s |\n", result == 0 ? "PASSED" : "FAILED"); + printf(" | CMCLinkedList Suit : %-43s |\n", result == 0 ? "PASSED" : "FAILED"); printf(" +---------------------------------------------------------------+"); printf("\n\n\n"); return result; } #endif + +#endif /* CMC_TESTS_UNT_CMC_INKEDLIST_H */ diff --git a/tests/main/unt/list.c b/tests/unt/cmc/list.h similarity index 98% rename from tests/main/unt/list.c rename to tests/unt/cmc/list.h index 2369b57..8bda4ac 100644 --- a/tests/main/unt/list.c +++ b/tests/unt/cmc/list.h @@ -1,14 +1,15 @@ -#include "utl.c" -#include "utl/assert.h" -#include "utl/test.h" +#ifndef CMC_TESTS_UNT_CMC_LIST_H +#define CMC_TESTS_UNT_CMC_LIST_H -#include "../src/list.c" +#include "../utl.h" + +#include "cmc/list.h" struct list_fval *l_fval = &(struct list_fval){ .cmp = cmc_size_cmp, .cpy = NULL, .str = cmc_size_str, .free = NULL, .hash = cmc_size_hash, .pri = cmc_size_cmp }; -CMC_CREATE_UNIT(List, true, { +CMC_CREATE_UNIT(CMCList, true, { CMC_CREATE_TEST(new, { struct list *l = l_new(1000000, l_fval); @@ -610,7 +611,7 @@ CMC_CREATE_UNIT(List, true, { }); }) -CMC_CREATE_UNIT(ListIter, true, { +CMC_CREATE_UNIT(CMCListIter, true, { CMC_CREATE_TEST(PFX##_iter_start(), { struct list *l = l_new(100, l_fval); @@ -1065,14 +1066,16 @@ CMC_CREATE_UNIT(ListIter, true, { #ifdef CMC_TEST_MAIN int main(void) { - int result = List() + ListIter(); + int result = CMCList() + CMCListIter(); printf(" +---------------------------------------------------------------+"); printf("\n"); - printf(" | List Suit : %-49s |\n", result == 0 ? "PASSED" : "FAILED"); + printf(" | CMCList Suit : %-49s |\n", result == 0 ? "PASSED" : "FAILED"); printf(" +---------------------------------------------------------------+"); printf("\n\n\n"); return result; } #endif + +#endif /* CMC_TESTS_UNT_CMC_LIST_H */ diff --git a/tests/main/unt/queue.c b/tests/unt/cmc/queue.h similarity index 98% rename from tests/main/unt/queue.c rename to tests/unt/cmc/queue.h index 990b386..b9a67b3 100644 --- a/tests/main/unt/queue.c +++ b/tests/unt/cmc/queue.h @@ -1,14 +1,15 @@ -#include "utl.c" -#include "utl/assert.h" -#include "utl/test.h" +#ifndef CMC_TESTS_UNT_CMC_QUEUE_H +#define CMC_TESTS_UNT_CMC_QUEUE_H -#include "../src/queue.c" +#include "../utl.h" + +#include "cmc/queue.h" struct queue_fval *q_fval = &(struct queue_fval){ .cmp = cmc_size_cmp, .cpy = NULL, .str = cmc_size_str, .free = NULL, .hash = cmc_size_hash, .pri = cmc_size_cmp }; -CMC_CREATE_UNIT(Queue, true, { +CMC_CREATE_UNIT(CMCQueue, true, { CMC_CREATE_TEST(new, { struct queue *q = q_new(1000000, q_fval); @@ -538,7 +539,7 @@ CMC_CREATE_UNIT(Queue, true, { }); }); -CMC_CREATE_UNIT(QueueIter, true, { +CMC_CREATE_UNIT(CMCQueueIter, true, { CMC_CREATE_TEST(PFX##_iter_start(), { struct queue *q = q_new(100, q_fval); @@ -951,14 +952,16 @@ CMC_CREATE_UNIT(QueueIter, true, { #ifdef CMC_TEST_MAIN int main(void) { - int result = Queue() + QueueIter(); + int result = CMCQueue() + CMCQueueIter(); printf(" +---------------------------------------------------------------+"); printf("\n"); - printf(" | Queue Suit : %-48s |\n", result == 0 ? "PASSED" : "FAILED"); + printf(" | CMCQueue Suit : %-48s |\n", result == 0 ? "PASSED" : "FAILED"); printf(" +---------------------------------------------------------------+"); printf("\n\n\n"); return result; } #endif + +#endif /* CMC_TESTS_UNT_CMC_QUEUE_H */ diff --git a/tests/main/unt/sortedlist.c b/tests/unt/cmc/sortedlist.h similarity index 97% rename from tests/main/unt/sortedlist.c rename to tests/unt/cmc/sortedlist.h index d21cca6..edb1b8c 100644 --- a/tests/main/unt/sortedlist.c +++ b/tests/unt/cmc/sortedlist.h @@ -1,14 +1,15 @@ -#include "utl.c" -#include "utl/assert.h" -#include "utl/test.h" +#ifndef CMC_TESTS_UNT_CMC_SORTEDLIST_H +#define CMC_TESTS_UNT_CMC_SORTEDLIST_H -#include "../src/sortedlist.c" +#include "../utl.h" + +#include "cmc/sortedlist.h" struct sortedlist_fval *sl_fval = &(struct sortedlist_fval){ .cmp = cmc_size_cmp, .cpy = NULL, .str = cmc_size_str, .free = NULL, .hash = cmc_size_hash, .pri = cmc_size_cmp }; -CMC_CREATE_UNIT(SortedList, true, { +CMC_CREATE_UNIT(CMCSortedList, true, { CMC_CREATE_TEST(new, { struct sortedlist *sl = sl_new(1000000, sl_fval); @@ -308,7 +309,7 @@ CMC_CREATE_UNIT(SortedList, true, { }); }); -CMC_CREATE_UNIT(SortedListIter, true, { +CMC_CREATE_UNIT(CMCSortedListIter, true, { CMC_CREATE_TEST(PFX##_iter_start(), { struct sortedlist *sl = sl_new(100, sl_fval); @@ -698,14 +699,16 @@ CMC_CREATE_UNIT(SortedListIter, true, { #ifdef CMC_TEST_MAIN int main(void) { - int result = SortedList() + SortedListIter(); + int result = CMCSortedList() + CMCSortedListIter(); printf(" +---------------------------------------------------------------+"); printf("\n"); - printf(" | SortedList Suit : %-43s |\n", result == 0 ? "PASSED" : "FAILED"); + printf(" | CMCSortedList Suit : %-43s |\n", result == 0 ? "PASSED" : "FAILED"); printf(" +---------------------------------------------------------------+"); printf("\n\n\n"); return result; } #endif + +#endif /* CMC_TESTS_UNT_CMC_SORTEDLIST_H */ diff --git a/tests/main/unt/stack.c b/tests/unt/cmc/stack.h similarity index 98% rename from tests/main/unt/stack.c rename to tests/unt/cmc/stack.h index 17f78e9..4efb1f4 100644 --- a/tests/main/unt/stack.c +++ b/tests/unt/cmc/stack.h @@ -1,14 +1,15 @@ -#include "utl.c" -#include "utl/assert.h" -#include "utl/test.h" +#ifndef CMC_TESTS_UNT_CMC_STACK_H +#define CMC_TESTS_UNT_CMC_STACK_H -#include "../src/stack.c" +#include "../utl.h" + +#include "cmc/stack.h" struct stack_fval *s_fval = &(struct stack_fval){ .cmp = cmc_size_cmp, .cpy = NULL, .str = cmc_size_str, .free = NULL, .hash = cmc_size_hash, .pri = cmc_size_cmp }; -CMC_CREATE_UNIT(Stack, true, { +CMC_CREATE_UNIT(CMCStack, true, { CMC_CREATE_TEST(new, { struct stack *s = s_new(1000000, s_fval); @@ -402,7 +403,7 @@ CMC_CREATE_UNIT(Stack, true, { }); }); -CMC_CREATE_UNIT(StackIter, true, { +CMC_CREATE_UNIT(CMCStackIter, true, { CMC_CREATE_TEST(PFX##_iter_start(), { struct stack *s = s_new(100, s_fval); @@ -833,14 +834,16 @@ CMC_CREATE_UNIT(StackIter, true, { #ifdef CMC_TEST_MAIN int main(void) { - int result = Stack() + StackIter(); + int result = CMCStack() + CMCStackIter(); printf(" +---------------------------------------------------------------+"); printf("\n"); - printf(" | Stack Suit : %-48s |\n", result == 0 ? "PASSED" : "FAILED"); + printf(" | CMCStack Suit : %-48s |\n", result == 0 ? "PASSED" : "FAILED"); printf(" +---------------------------------------------------------------+"); printf("\n\n\n"); return result; } #endif + +#endif /* CMC_TESTS_UNT_CMC_STACK_H */ diff --git a/tests/main/unt/treemap.c b/tests/unt/cmc/treemap.h similarity index 98% rename from tests/main/unt/treemap.c rename to tests/unt/cmc/treemap.h index 379407c..014ac02 100644 --- a/tests/main/unt/treemap.c +++ b/tests/unt/cmc/treemap.h @@ -1,8 +1,9 @@ -#include "utl.c" -#include "utl/assert.h" -#include "utl/test.h" +#ifndef CMC_TESTS_UNT_CMC_TREEMAP_H +#define CMC_TESTS_UNT_CMC_TREEMAP_H -#include "../src/treemap.c" +#include "../utl.h" + +#include "cmc/treemap.h" struct treemap_fkey *tm_fkey = &(struct treemap_fkey){ .cmp = cmc_size_cmp, .cpy = NULL, .str = cmc_size_str, .free = NULL, .hash = cmc_size_hash, .pri = cmc_size_cmp @@ -12,7 +13,7 @@ struct treemap_fval *tm_fval = &(struct treemap_fval){ .cmp = cmc_size_cmp, .cpy = NULL, .str = cmc_size_str, .free = NULL, .hash = cmc_size_hash, .pri = cmc_size_cmp }; -CMC_CREATE_UNIT(TreeMap, true, { +CMC_CREATE_UNIT(CMCTreeMap, true, { CMC_CREATE_TEST(new, { struct treemap *map = tm_new(tm_fkey, tm_fval); @@ -207,7 +208,7 @@ CMC_CREATE_UNIT(TreeMap, true, { }); }); -CMC_CREATE_UNIT(TreeMapIter, true, { +CMC_CREATE_UNIT(CMCTreeMapIter, true, { CMC_CREATE_TEST(PFX##_iter_start(), { struct treemap *map = tm_new(tm_fkey, tm_fval); @@ -651,14 +652,16 @@ CMC_CREATE_UNIT(TreeMapIter, true, { #ifdef CMC_TEST_MAIN int main(void) { - int result = TreeMap() + TreeMapIter(); + int result = CMCTreeMap() + CMCTreeMapIter(); printf(" +---------------------------------------------------------------+"); printf("\n"); - printf(" | TreeMap Suit : %-46s |\n", result == 0 ? "PASSED" : "FAILED"); + printf(" | CMCTreeMap Suit : %-46s |\n", result == 0 ? "PASSED" : "FAILED"); printf(" +---------------------------------------------------------------+"); printf("\n\n\n"); return result; } #endif + +#endif /* CMC_TESTS_UNT_CMC_TREEMAP_H */ diff --git a/tests/main/unt/treeset.c b/tests/unt/cmc/treeset.h similarity index 97% rename from tests/main/unt/treeset.c rename to tests/unt/cmc/treeset.h index cce4a14..46dddf6 100644 --- a/tests/main/unt/treeset.c +++ b/tests/unt/cmc/treeset.h @@ -1,14 +1,15 @@ -#include "utl.c" -#include "utl/assert.h" -#include "utl/test.h" +#ifndef CMC_TESTS_UNT_CMC_TREESET_H +#define CMC_TESTS_UNT_CMC_TREESET_H -#include "../src/treeset.c" +#include "../utl.h" + +#include "cmc/treeset.h" struct treeset_fval *ts_fval = &(struct treeset_fval){ .cmp = cmc_size_cmp, .cpy = NULL, .str = cmc_size_str, .free = NULL, .hash = cmc_size_hash, .pri = cmc_size_cmp }; -CMC_CREATE_UNIT(TreeSet, true, { +CMC_CREATE_UNIT(CMCTreeSet, true, { CMC_CREATE_TEST(new, { struct treeset *set = ts_new(ts_fval); @@ -162,7 +163,7 @@ CMC_CREATE_UNIT(TreeSet, true, { }); }); -CMC_CREATE_UNIT(TreeSetIter, true, { +CMC_CREATE_UNIT(CMCTreeSetIter, true, { CMC_CREATE_TEST(PFX##_iter_start(), { struct treeset *set = ts_new(ts_fval); @@ -569,14 +570,16 @@ CMC_CREATE_UNIT(TreeSetIter, true, { #ifdef CMC_TEST_MAIN int main(void) { - int result = TreeSet() + TreeSetIter(); + int result = CMCTreeSet() + CMCTreeSetIter(); printf(" +---------------------------------------------------------------+"); printf("\n"); - printf(" | TreeSet Suit : %-46s |\n", result == 0 ? "PASSED" : "FAILED"); + printf(" | CMCTreeSet Suit : %-46s |\n", result == 0 ? "PASSED" : "FAILED"); printf(" +---------------------------------------------------------------+"); printf("\n\n\n"); return result; } #endif + +#endif /* CMC_TESTS_UNT_CMC_TREESET_H */ diff --git a/tests/main/unt/utl.c b/tests/unt/utl.h similarity index 95% rename from tests/main/unt/utl.c rename to tests/unt/utl.h index 391e3b4..9835ae9 100644 --- a/tests/main/unt/utl.c +++ b/tests/unt/utl.h @@ -1,13 +1,16 @@ /* Utility file to be included in the unit tests */ -#ifndef CMC_UNIT_TEST_UTL__ -#define CMC_UNIT_TEST_UTL__ +#ifndef CMC_TESTS_UTL +#define CMC_TESTS_UTL #include #include #include #include "cor/hashtable.h" +#include "utl/assert.h" +#include "utl/foreach.h" #include "utl/futils.h" +#include "utl/test.h" size_t numhash(size_t a) { @@ -165,4 +168,4 @@ struct cmc_callbacks *callbacks = &(struct cmc_callbacks){ .create = callback_cr .delete = callback_delete, .resize = callback_resize }; -#endif /* CMC_UNIT_TEST_UTL__ */ +#endif /* CMC_TESTS_UTL */ diff --git a/tests/main/unt/foreach.c b/tests/unt/utl/foreach.h similarity index 97% rename from tests/main/unt/foreach.c rename to tests/unt/utl/foreach.h index a37bca4..2336f99 100644 --- a/tests/main/unt/foreach.c +++ b/tests/unt/utl/foreach.h @@ -1,25 +1,24 @@ -#include "utl.c" -#include "utl/assert.h" -#include "utl/test.h" +#ifndef CMC_TESTS_UNT_UTL_FOREACH_H +#define CMC_TESTS_UNT_UTL_FOREACH_H -#include "utl/foreach.h" +#include "../utl.h" -#include "../src/bitset.c" -#include "../src/deque.c" -#include "../src/hashbidimap.c" -#include "../src/hashmap.c" -#include "../src/hashmultimap.c" -#include "../src/hashmultiset.c" -#include "../src/hashset.c" -#include "../src/heap.c" -#include "../src/intervalheap.c" -#include "../src/linkedlist.c" -#include "../src/list.c" -#include "../src/queue.c" -#include "../src/sortedlist.c" -#include "../src/stack.c" -#include "../src/treemap.c" -#include "../src/treeset.c" +#include "cmc/bitset.h" +#include "cmc/deque.h" +#include "cmc/hashbidimap.h" +#include "cmc/hashmap.h" +#include "cmc/hashmultimap.h" +#include "cmc/hashmultiset.h" +#include "cmc/hashset.h" +#include "cmc/heap.h" +#include "cmc/intervalheap.h" +#include "cmc/linkedlist.h" +#include "cmc/list.h" +#include "cmc/queue.h" +#include "cmc/sortedlist.h" +#include "cmc/stack.h" +#include "cmc/treemap.h" +#include "cmc/treeset.h" CMC_CREATE_UNIT(ForEach, true, { // CMC_CREATE_TEST(CMC, { @@ -505,3 +504,5 @@ int main(void) return result; } #endif + +#endif /* CMC_TESTS_UNT_UTL_FOREACH_H */