mirror of
https://github.com/Ed94/Odin.git
synced 2026-06-21 13:14:59 -07:00
Use T.seed in tests where applicable
This commit is contained in:
@@ -8,7 +8,7 @@ import "core:log"
|
||||
|
||||
@(test)
|
||||
test_avl :: proc(t: ^testing.T) {
|
||||
log.infof("Testing avl, using random seed %v, add -define:RANDOM_SEED=%v to reuse it.", random_seed, random_seed)
|
||||
log.infof("Testing avl using random seed %v.", t.seed)
|
||||
|
||||
// Initialization.
|
||||
tree: avl.Tree(int)
|
||||
@@ -21,7 +21,7 @@ test_avl :: proc(t: ^testing.T) {
|
||||
testing.expect(t, avl.iterator_get(&iter) == nil, "empty/iterator: first node should be nil")
|
||||
|
||||
r: rand.Rand
|
||||
rand.init(&r, random_seed)
|
||||
rand.init(&r, t.seed)
|
||||
|
||||
// Test insertion.
|
||||
NR_INSERTS :: 32 + 1 // Ensure at least 1 collision.
|
||||
|
||||
@@ -8,12 +8,6 @@ import "core:mem"
|
||||
import "core:slice"
|
||||
import "core:log"
|
||||
|
||||
@(private)
|
||||
_RANDOM_SEED :: #config(RANDOM_SEED, u64(0))
|
||||
|
||||
// Exported
|
||||
random_seed := u64(intrinsics.read_cycle_counter()) when _RANDOM_SEED == 0 else u64(_RANDOM_SEED)
|
||||
|
||||
test_rbtree_integer :: proc(t: ^testing.T, $Key: typeid, $Value: typeid) {
|
||||
track: mem.Tracking_Allocator
|
||||
mem.tracking_allocator_init(&track, context.allocator)
|
||||
@@ -21,9 +15,9 @@ test_rbtree_integer :: proc(t: ^testing.T, $Key: typeid, $Value: typeid) {
|
||||
context.allocator = mem.tracking_allocator(&track)
|
||||
|
||||
r: rand.Rand
|
||||
rand.init(&r, random_seed)
|
||||
rand.init(&r, t.seed)
|
||||
|
||||
log.infof("Testing Red-Black Tree($Key=%v,$Value=%v), using random seed %v, add -define:RANDOM_SEED=%v to reuse it.", type_info_of(Key), type_info_of(Value), random_seed, random_seed)
|
||||
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)
|
||||
|
||||
@@ -243,4 +237,4 @@ verify_rbtree_propery_5_helper :: proc(t: ^testing.T, n: ^$N/rb.Node($Key, $Valu
|
||||
verify_rbtree_propery_5_helper(t, n._right, black_count, path_black_count)
|
||||
}
|
||||
// Properties 4 and 5 together guarantee that no path in the tree is more than about twice as long as any other path,
|
||||
// which guarantees that it has O(log n) height.
|
||||
// which guarantees that it has O(log n) height.
|
||||
|
||||
Reference in New Issue
Block a user