summaryrefslogtreecommitdiffstats
path: root/test/sorted_array_test.c
diff options
context:
space:
mode:
Diffstat (limited to 'test/sorted_array_test.c')
-rw-r--r--test/sorted_array_test.c17
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(".");