1 #include <ccan/eratosthenes/eratosthenes.h>
2 #include <ccan/tap/tap.h>
4 #include <ccan/eratosthenes/eratosthenes.c>
9 ok((a) == (b), "%s [%u] == %s [%u]", \
10 #a, (unsigned)(a), #b, (unsigned)(b))
12 static bool test_isprime(unsigned long n)
19 for (i = 2; i < n; i++)
26 static unsigned long test_nextprime(struct eratosthenes *s, unsigned long n)
28 unsigned long i = n + 1;
30 while ((i < LIMIT) && !eratosthenes_isprime(s, i))
33 return (i >= LIMIT) ? 0 : i;
38 struct eratosthenes s;
41 /* This is how many tests you plan to run */
42 plan_tests(2 * LIMIT);
44 eratosthenes_init(&s);
46 eratosthenes_sieve(&s, LIMIT);
48 for (n = 0; n < LIMIT; n++) {
49 ok_eq(eratosthenes_isprime(&s, n), test_isprime(n));
50 ok_eq(eratosthenes_nextprime(&s, n), test_nextprime(&s, n));
53 eratosthenes_reset(&s);
55 /* This exits depending on whether all tests passed */