Skip to content

Commit 1284cfb

Browse files
committed
test: improve coverage
1 parent 0781cf7 commit 1284cfb

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

test/test_composable_expression.jl

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ end
185185

186186
@testitem "ValidVector operations with Union{} return type" tags = [:part2] begin
187187
using SymbolicRegression: ValidVector
188-
using SymbolicRegression.ComposableExpressionModule: apply_operator
188+
using SymbolicRegression.ComposableExpressionModule: apply_operator, _match_eltype
189189

190190
error_op(::Any, ::Any) = error("This should cause Union{} inference")
191191

@@ -201,4 +201,17 @@ end
201201
b = 1.0
202202
result2 = apply_operator(*, a, b)
203203
@test result2 isa ValidVector{<:AbstractArray{Float64}}
204+
205+
# Test apply_operator when all inputs are valid
206+
valid_x = ValidVector([1.0, 2.0], true)
207+
valid_y = ValidVector([3.0, 4.0], true)
208+
valid_result = apply_operator(+, valid_x, valid_y)
209+
@test valid_result.valid == true
210+
@test valid_result.x [4.0, 6.0]
211+
212+
# cover _match_eltype
213+
arr = [1.0, 2.0]
214+
@test _match_eltype(ValidVector{Vector{Float64}}, arr) === arr # Same type
215+
arr_f32 = Float32[1.0, 2.0]
216+
@test _match_eltype(ValidVector{Vector{Float64}}, arr_f32) isa Vector{Float64} # Different type
204217
end

test/test_template_expression.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,7 @@ end
696696
@testitem "Test Float32/Float64 type conversion in TemplateExpression" tags = [:part2] begin
697697
using SymbolicRegression
698698
using SymbolicRegression: eval_loss
699+
using SymbolicRegression.TemplateExpressionModule: _match_input_eltype
699700

700701
template = @template_spec(expressions = (f,)) do x1, x2
701702
0.5 * f(x1, x2) # 0.5 is Float64 literal
@@ -719,4 +720,10 @@ end
719720
loss = eval_loss(template_expr, dataset, options)
720721
@test loss isa Float32
721722
@test loss 0.0
723+
724+
# Test _match_input_eltype coverage (covers lines 675-676)
725+
result_f64 = [1.0, 2.0]
726+
@test _match_input_eltype(Matrix{Float64}, result_f64) === result_f64 # Same type
727+
result_int = [1, 2]
728+
@test _match_input_eltype(Matrix{Float64}, result_int) === result_int # Non-float type
722729
end

0 commit comments

Comments
 (0)