X-Git-Url: https://git.ozlabs.org/?a=blobdiff_plain;f=ccan%2Feratosthenes%2Ftest%2Frun-incremental.c;fp=ccan%2Feratosthenes%2Ftest%2Frun-incremental.c;h=ea6b2b9c1c53a391f78988e55988be4eb5064c28;hb=c5e84ef2b5687fc35cdffa4768da13674afb8977;hp=0000000000000000000000000000000000000000;hpb=f591ef48f887f6c1608cdd89d78eebacd27e8552;p=ccan diff --git a/ccan/eratosthenes/test/run-incremental.c b/ccan/eratosthenes/test/run-incremental.c new file mode 100644 index 00000000..ea6b2b9c --- /dev/null +++ b/ccan/eratosthenes/test/run-incremental.c @@ -0,0 +1,36 @@ +#include +#include + +#include + +#define LIMIT 500 + +#define ok_eq(a, b) \ + ok((a) == (b), "%s [%u] == %s [%u]", \ + #a, (unsigned)(a), #b, (unsigned)(b)) + +int main(void) +{ + struct eratosthenes s1, s2; + unsigned long n; + + /* This is how many tests you plan to run */ + plan_tests(LIMIT); + + eratosthenes_init(&s1); + eratosthenes_sieve(&s1, LIMIT); + + eratosthenes_init(&s2); + for (n = 1; n <= LIMIT; n++) + eratosthenes_sieve(&s2, n); + + for (n = 0; n < LIMIT; n++) + ok1(eratosthenes_isprime(&s1, n) + == eratosthenes_isprime(&s2, n)); + + eratosthenes_reset(&s1); + eratosthenes_reset(&s2); + + /* This exits depending on whether all tests passed */ + return exit_status(); +}