From 1a52cf1f1c4becff3f107111038e50b0a0c74594 Mon Sep 17 00:00:00 2001 From: Feoramund <161657516+Feoramund@users.noreply.github.com> Date: Sat, 15 Jun 2024 13:37:04 -0400 Subject: [PATCH] Use test's random generator This removes the `create` calls when a test was only setting up a generator, and it replaces them with `reset` when run in a loop. --- tests/core/container/test_core_avl.odin | 3 -- tests/core/container/test_core_rbtree.odin | 3 -- tests/core/hash/test_core_hash.odin | 3 +- tests/core/slice/test_core_slice.odin | 6 ++-- tests/internal/test_map.odin | 39 ++++++++-------------- 5 files changed, 16 insertions(+), 38 deletions(-) diff --git a/tests/core/container/test_core_avl.odin b/tests/core/container/test_core_avl.odin index 556f371af..0e2d0d94a 100644 --- a/tests/core/container/test_core_avl.odin +++ b/tests/core/container/test_core_avl.odin @@ -20,9 +20,6 @@ test_avl :: proc(t: ^testing.T) { iter := avl.iterator(&tree, avl.Direction.Forward) testing.expect(t, avl.iterator_get(&iter) == nil, "empty/iterator: first node should be nil") - r := rand.create(t.seed) - context.random_generator = rand.default_random_generator(&r) - // Test insertion. NR_INSERTS :: 32 + 1 // Ensure at least 1 collision. inserted_map := make(map[int]^avl.Node(int)) diff --git a/tests/core/container/test_core_rbtree.odin b/tests/core/container/test_core_rbtree.odin index 425a9b440..b686ef6dd 100644 --- a/tests/core/container/test_core_rbtree.odin +++ b/tests/core/container/test_core_rbtree.odin @@ -14,9 +14,6 @@ test_rbtree_integer :: proc(t: ^testing.T, $Key: typeid, $Value: typeid) { defer mem.tracking_allocator_destroy(&track) context.allocator = mem.tracking_allocator(&track) - r := rand.create(t.seed) - context.random_generator = rand.default_random_generator(&r) - log.infof("Testing Red-Black Tree($Key=%v,$Value=%v) using random seed %v.", type_info_of(Key), type_info_of(Value), t.seed) tree: rb.Tree(Key, Value) rb.init(&tree) diff --git a/tests/core/hash/test_core_hash.odin b/tests/core/hash/test_core_hash.odin index 0255717a2..c3f0bee91 100644 --- a/tests/core/hash/test_core_hash.odin +++ b/tests/core/hash/test_core_hash.odin @@ -53,8 +53,7 @@ test_xxhash_zero_streamed_random_updates :: proc(t: ^testing.T) { testing.expect(t, xxh3_128_err == nil, "Problem initializing XXH3_128 state") // XXH3_128_update - random_seed := rand.create(t.seed) - context.random_generator = rand.default_random_generator(&random_seed) + rand.reset(t.seed) for len(b) > 0 { update_size := min(len(b), rand.int_max(8192)) if update_size > 4096 { diff --git a/tests/core/slice/test_core_slice.odin b/tests/core/slice/test_core_slice.odin index 432636664..5825c49b6 100644 --- a/tests/core/slice/test_core_slice.odin +++ b/tests/core/slice/test_core_slice.odin @@ -11,8 +11,7 @@ test_sort_with_indices :: proc(t: ^testing.T) { test_sizes :: []int{7, 13, 347, 1031, 10111, 100003} for test_size in test_sizes { - r := rand.create(t.seed) - context.random_generator = rand.default_random_generator(&r) + rand.reset(t.seed) vals := make([]u64, test_size) r_idx := make([]int, test_size) // Reverse index @@ -63,8 +62,7 @@ test_sort_by_indices :: proc(t: ^testing.T) { test_sizes :: []int{7, 13, 347, 1031, 10111, 100003} for test_size in test_sizes { - r := rand.create(t.seed) - context.random_generator = rand.default_random_generator(&r) + rand.reset(t.seed) vals := make([]u64, test_size) r_idx := make([]int, test_size) // Reverse index diff --git a/tests/internal/test_map.odin b/tests/internal/test_map.odin index ab7e52f33..9bd5d34ea 100644 --- a/tests/internal/test_map.odin +++ b/tests/internal/test_map.odin @@ -16,8 +16,7 @@ map_insert_random_key_value :: proc(t: ^testing.T) { defer delete(m) unique_keys := 0 - r := rand.create(t.seed + seed_incr) - context.random_generator = rand.default_random_generator(&r) + rand.reset(t.seed + seed_incr) for _ in 0..