X-Git-Url: http://git.draconx.ca/gitweb/rrace.git/blobdiff_plain/46cf1b673efc9fb9cb84c70a86024d76762c3444..bbc28a6dec903c362ed1249ca3b31b26e0d44c15:/t/rng-test.c diff --git a/t/rng-test.c b/t/rng-test.c index 9d27f38..e141c0d 100644 --- a/t/rng-test.c +++ b/t/rng-test.c @@ -1,6 +1,6 @@ /* * Test case for xoshiro256** implementation. - * Copyright © 2022-2023 Nick Bowler + * Copyright © 2022-2024 Nick Bowler * * Directly compare the game RNG against the reference implementation. * @@ -19,9 +19,14 @@ */ #include -#include -#include +#include "tap.h" +#if !HAVE_FOR_DECLS +int main(void) +{ + tap_skip_all("cannot compile reference xoshiro256**"); +} +#else #include "game-notime.h" #include "game.c" #include "xos256ss.c" @@ -33,7 +38,7 @@ int main(void) unsigned long long ref_state[4], test_state[4]; int i, ret = 0; - printf("1..200\n"); + tap_plan(200); for (i = 0; i < 100; i++) { s[0] = ref_state[0] = test_state[0] = splitmix64(&seed_state); s[1] = ref_state[1] = test_state[1] = splitmix64(&seed_state); @@ -43,40 +48,34 @@ int main(void) ref_result = next(); test_result = xoshiro256ss(test_state); - if (ref_result != test_result) { - printf("not ok %d rng output\n", 2*i+1); - printf("# Failed, unexpected result\n"); - printf("# with initial state %llx %llx %llx %llx\n", - ref_state[0], ref_state[1], - ref_state[2], ref_state[3]); - printf("# received: %llx\n", test_result); - printf("# expected: %llx\n", ref_result); - ret = EXIT_FAILURE; - } else { - printf("ok %d rng output\n", 2*i+1); + if (!tap_result(ref_result == test_result, "rng output")) { + tap_diag("Failed, unexpected result"); + tap_diag(" with initial state %llx %llx %llx %llx", + ref_state[0], ref_state[1], + ref_state[2], ref_state[3]); + tap_diag(" received: %llx", test_result); + tap_diag(" expected: %llx", ref_result); } - if (s[0] != test_state[0] || s[1] != test_state[1] - || s[2] != test_state[2] || s[3] != test_state[3]) + if (!tap_result(s[0] == test_state[0] && s[1] == test_state[1] + && s[2] == test_state[2] && s[3] == test_state[3], + "rng state update")) { - printf("not ok %d rng state update\n", 2*i+2); - printf("# Failed, state update differed\n"); - printf("# with initial state %llx %llx %llx %llx\n", - ref_state[0], ref_state[1], - ref_state[2], ref_state[3]); - printf("# received: %llx %llx %llx %llx\n", - test_state[0], test_state[1], - test_state[2], test_state[3]); - printf("# expected: %llx %llx %llx %llx\n", - (unsigned long long)s[0], - (unsigned long long)s[1], - (unsigned long long)s[2], - (unsigned long long)s[3]); - ret = EXIT_FAILURE; - } else { - printf("ok %d rng state update\n", 2*i+2); - } + tap_diag("Failed, state update differed"); + tap_diag(" with initial state %llx %llx %llx %llx", + ref_state[0], ref_state[1], + ref_state[2], ref_state[3]); + tap_diag(" received: %llx %llx %llx %llx", + test_state[0], test_state[1], + test_state[2], test_state[3]); + tap_diag(" expected: %llx %llx %llx %llx", + (unsigned long long)s[0], + (unsigned long long)s[1], + (unsigned long long)s[2], + (unsigned long long)s[3]); + } } - return ret; + tap_done(); } +#endif