]> git.ozlabs.org Git - ccan/blobdiff - ccan/eratosthenes/test/run-incremental.c
eratosthenes: Implementation of the Sieve of Eratosthenes
[ccan] / ccan / eratosthenes / test / run-incremental.c
diff --git a/ccan/eratosthenes/test/run-incremental.c b/ccan/eratosthenes/test/run-incremental.c
new file mode 100644 (file)
index 0000000..ea6b2b9
--- /dev/null
@@ -0,0 +1,36 @@
+#include <ccan/eratosthenes/eratosthenes.h>
+#include <ccan/tap/tap.h>
+
+#include <ccan/eratosthenes/eratosthenes.c>
+
+#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();
+}