diff --git a/Makefile b/Makefile index b9482e4..eb3f4d6 100644 --- a/Makefile +++ b/Makefile @@ -5,14 +5,15 @@ LDLIBS = -lm Sources = src/sieve_of_eratosthenes.c src/sieve_of_atkin.c Objects = $(Sources:.c=.o) -.PHONY: sieve bench +.PHONY: all -sieve: target/sieve +all: target/sieve target/bench target/tests target/sieve: $(Objects) src/main.c $(LINK.c) $^ -o $@ $(LDLIBS) -bench: target/bench - target/bench: $(Objects) bench/bench.cc $(LINK.cc) $^ -o $@ $(LDLIBS) + +target/tests: $(Objects) tests/tests.c + $(LINK.c) $^ -o $@ $(LDLIBS) diff --git a/autoformat.bash b/autoformat.bash index 0a22123..7fffd44 100755 --- a/autoformat.bash +++ b/autoformat.bash @@ -1,6 +1,6 @@ #! /usr/bin/env bash -files=(src/*.c*) +files=(*/*.c*) if [ "$1" = check ] then clang-format --dry-run -Werror ${files[@]} diff --git a/tests/tests.c b/tests/tests.c new file mode 100644 index 0000000..d81094e --- /dev/null +++ b/tests/tests.c @@ -0,0 +1,26 @@ +#include +#include + +struct SieveOfEratosthenes; +struct SieveOfEratosthenes *sieve_of_eratosthenes_new(size_t limit); +size_t sieve_of_eratosthenes_count(struct SieveOfEratosthenes *erato); +void sieve_of_eratosthenes_delete(struct SieveOfEratosthenes *erato); + +struct SieveOfAtkin; +struct SieveOfAtkin *sieve_of_atkin_new(size_t limit); +size_t sieve_of_atkin_count(struct SieveOfAtkin *atkin); +void sieve_of_atkin_delete(struct SieveOfAtkin *atkin); + +int +main(void) +{ + struct SieveOfEratosthenes *erato = sieve_of_eratosthenes_new(1000000000); + size_t erato_count = sieve_of_eratosthenes_count(erato); + sieve_of_eratosthenes_delete(erato); + assert(erato_count == 50847531); + + struct SieveOfAtkin *atkin = sieve_of_atkin_new(1000000000); + size_t atkin_count = sieve_of_atkin_count(atkin); + sieve_of_eratosthenes_delete(erato); + assert(atkin_count == 50847531); +}