|
1 | 1 | @testitem "Buffer creation and validation" begin |
2 | 2 | using DynamicExpressions |
3 | | - using Test |
4 | 3 |
|
5 | 4 | # Test data setup |
6 | 5 | X = rand(2, 10) # 2 features, 10 samples |
|
32 | 31 |
|
33 | 32 | @testitem "Buffer correctness" begin |
34 | 33 | using DynamicExpressions |
35 | | - using Test |
36 | 34 |
|
37 | 35 | X = rand(2, 10) |
38 | 36 | operators = OperatorEnum(; binary_operators=[+, *], unary_operators=[sin]) |
|
61 | 59 |
|
62 | 60 | @testitem "Buffer index management" begin |
63 | 61 | using DynamicExpressions |
64 | | - using Test |
65 | 62 |
|
66 | 63 | X = rand(2, 10) |
67 | 64 | operators = OperatorEnum(; binary_operators=[+, *], unary_operators=[sin]) |
|
99 | 96 |
|
100 | 97 | @testitem "Buffer error handling" begin |
101 | 98 | using DynamicExpressions |
102 | | - using Test |
103 | 99 |
|
104 | 100 | X = rand(2, 10) |
105 | 101 | operators = OperatorEnum(; binary_operators=[+, /, *], unary_operators=[sin]) |
|
119 | 115 | result1, ok1 = eval_tree_array(tree, X, operators; eval_options) |
120 | 116 | @test !ok1 |
121 | 117 | 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