Skip to content

Commit

Permalink
Added tests in separate directory.
Browse files Browse the repository at this point in the history
  • Loading branch information
tfpf committed Mar 1, 2024
1 parent 5fb28ff commit cdf7dc6
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
9 changes: 5 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 1 addition & 1 deletion autoformat.bash
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#! /usr/bin/env bash

files=(src/*.c*)
files=(*/*.c*)
if [ "$1" = check ]
then
clang-format --dry-run -Werror ${files[@]}
Expand Down
26 changes: 26 additions & 0 deletions tests/tests.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include <assert.h>
#include <stddef.h>

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);
}

0 comments on commit cdf7dc6

Please sign in to comment.