Skip to content

Commit 64956de

Browse files
committed
test: random comparison against non-buffered eval
1 parent 0f8bd8e commit 64956de

File tree

1 file changed

+31
-4
lines changed

1 file changed

+31
-4
lines changed

test/test_buffered_evaluation.jl

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
@testitem "Buffer creation and validation" begin
22
using DynamicExpressions
3-
using Test
43

54
# Test data setup
65
X = rand(2, 10) # 2 features, 10 samples
@@ -32,7 +31,6 @@ end
3231

3332
@testitem "Buffer correctness" begin
3433
using DynamicExpressions
35-
using Test
3634

3735
X = rand(2, 10)
3836
operators = OperatorEnum(; binary_operators=[+, *], unary_operators=[sin])
@@ -61,7 +59,6 @@ end
6159

6260
@testitem "Buffer index management" begin
6361
using DynamicExpressions
64-
using Test
6562

6663
X = rand(2, 10)
6764
operators = OperatorEnum(; binary_operators=[+, *], unary_operators=[sin])
@@ -99,7 +96,6 @@ end
9996

10097
@testitem "Buffer error handling" begin
10198
using DynamicExpressions
102-
using Test
10399

104100
X = rand(2, 10)
105101
operators = OperatorEnum(; binary_operators=[+, /, *], unary_operators=[sin])
@@ -119,3 +115,34 @@ end
119115
result1, ok1 = eval_tree_array(tree, X, operators; eval_options)
120116
@test !ok1
121117
end
118+
119+
@testitem "Random tree buffer evaluation" begin
120+
using DynamicExpressions
121+
using Random
122+
include("tree_gen_utils.jl")
123+
124+
# Test setup
125+
X = rand(2, 10)
126+
operators = OperatorEnum(;
127+
binary_operators=[+, -, *, /], unary_operators=[sin, cos, exp]
128+
)
129+
130+
for i in 1:100
131+
# Generate a random tree with varying size (1-10 nodes)
132+
n_nodes = rand(1:10)
133+
tree = gen_random_tree_fixed_size(n_nodes, operators, size(X, 1), Float64, Node)
134+
135+
# Regular evaluation
136+
result1, ok1 = eval_tree_array(tree, X, operators)
137+
138+
# Buffer evaluation
139+
buffer = Array{Float64}(undef, 2n_nodes, size(X, 2))
140+
buffer_ref = Ref(rand(1:10)) # Random starting index (will be reset)
141+
eval_options = EvalOptions(; buffer=buffer, buffer_ref=buffer_ref)
142+
result2, ok2 = eval_tree_array(tree, X, operators; eval_options)
143+
144+
# Results should be identical
145+
@test result1 result2
146+
@test ok1 == ok2
147+
end
148+
end

0 commit comments

Comments
 (0)