]> git.ozlabs.org Git - ccan/blob - ccan/eratosthenes/test/run-incremental.c
a_star: new module added to hacky Makefile-ccan list.
[ccan] / ccan / eratosthenes / test / run-incremental.c
1 #include <ccan/eratosthenes/eratosthenes.h>
2 #include <ccan/tap/tap.h>
3
4 #include <ccan/eratosthenes/eratosthenes.c>
5
6 #define LIMIT   500
7
8 #define ok_eq(a, b) \
9         ok((a) == (b), "%s [%u] == %s [%u]", \
10            #a, (unsigned)(a), #b, (unsigned)(b))
11
12 int main(void)
13 {
14         struct eratosthenes s1, s2;
15         unsigned long n;
16
17         /* This is how many tests you plan to run */
18         plan_tests(LIMIT);
19
20         eratosthenes_init(&s1);
21         eratosthenes_sieve(&s1, LIMIT);
22
23         eratosthenes_init(&s2);
24         for (n = 1; n <= LIMIT; n++)
25                 eratosthenes_sieve(&s2, n);
26
27         for (n = 0; n < LIMIT; n++)
28                 ok1(eratosthenes_isprime(&s1, n)
29                     == eratosthenes_isprime(&s2, n));
30
31         eratosthenes_reset(&s1);
32         eratosthenes_reset(&s2);
33
34         /* This exits depending on whether all tests passed */
35         return exit_status();
36 }