diff options
author | David Robillard <d@drobilla.net> | 2021-07-02 13:54:45 -0400 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2021-07-17 19:58:17 -0400 |
commit | 5942e985c6ac9b18090ec92b11aa8a586b6365c5 (patch) | |
tree | ce66d68e863df9ecba01c16dfe1a5bc7100068f0 /test/sorted_array_test.c | |
parent | bc264ab6f58177124d49a72b4a808eb97fa2cb25 (diff) | |
download | zix-5942e985c6ac9b18090ec92b11aa8a586b6365c5.tar.gz zix-5942e985c6ac9b18090ec92b11aa8a586b6365c5.tar.bz2 zix-5942e985c6ac9b18090ec92b11aa8a586b6365c5.zip |
Avoid use of rand()
Diffstat (limited to 'test/sorted_array_test.c')
-rw-r--r-- | test/sorted_array_test.c | 17 |
1 files changed, 5 insertions, 12 deletions
diff --git a/test/sorted_array_test.c b/test/sorted_array_test.c index 9256118..cc87619 100644 --- a/test/sorted_array_test.c +++ b/test/sorted_array_test.c @@ -14,6 +14,8 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#include "test_data.h" + #include "zix/common.h" #include "zix/sorted_array.h" @@ -45,7 +47,7 @@ ith_elem(unsigned test_num, unsigned n_elems, unsigned i) return n_elems - i; // Decreasing (worse case) case 2: default: - return rand() % 100; // Random + return lcg64(seed + i) % 100u; // Pseudo-random } } @@ -64,8 +66,6 @@ stress(unsigned test_num, unsigned n_elems) ZixSortedArray* t = zix_sorted_array_new(true, int_cmp, NULL, sizeof(intptr_t)); - srand(seed); - // Insert n_elems elements for (unsigned i = 0; i < n_elems; ++i) { r = ith_elem(test_num, n_elems, i); @@ -84,8 +84,6 @@ stress(unsigned test_num, unsigned n_elems) } } - srand(seed); - // Search for all elements for (unsigned i = 0; i < n_elems; ++i) { r = ith_elem(test_num, n_elems, i); @@ -103,8 +101,6 @@ stress(unsigned test_num, unsigned n_elems) } } - srand(seed); - // Iterate over all elements unsigned i = 0; intptr_t last = -1; @@ -137,8 +133,6 @@ stress(unsigned test_num, unsigned n_elems) return test_fail(); } - srand(seed); - // Iterate over all elements by index last = -1; for (i = 0; i < zix_sorted_array_size(t); ++i) { @@ -156,8 +150,6 @@ stress(unsigned test_num, unsigned n_elems) last = iter_data; } - srand(seed); - // Delete all elements for (unsigned e = 0; e < n_elems; e++) { r = ith_elem(test_num, n_elems, e); @@ -205,7 +197,8 @@ main(int argc, char** argv) return 1; } - printf("Running %u tests with %u elements (seed %u)\n", n_tests, n_elems, seed); + printf( + "Running %u tests with %u elements (seed %u)\n", n_tests, n_elems, seed); for (unsigned i = 0; i < n_tests; ++i) { printf("."); |