Skip to content

Commit 921c591

Browse files
committed
test: improve coverage
1 parent a89d22f commit 921c591

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

src/Expression.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ end
100100
return Expression(tree, Metadata(d))
101101
end
102102

103-
has_node_type(::Union{E,Type{E}}) where {N,E<:AbstractExpression{<:Any,N}} = true
104-
has_node_type(::Union{E,Type{E}}) where {E<:AbstractExpression} = false
103+
has_node_type(::Union{E,Type{E}}) where {N,E<:AbstractExpression{<:Any,N}} = true # COV_EXCL_LINE
104+
has_node_type(::Union{E,Type{E}}) where {E<:AbstractExpression} = false # COV_EXCL_LINE
105105
node_type(::Union{E,Type{E}}) where {N,E<:AbstractExpression{<:Any,N}} = N
106106
function max_degree(::Union{E,Type{E}}) where {E<:AbstractExpression}
107107
return has_node_type(E) ? max_degree(node_type(E)) : max_degree(Node)

src/base.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,15 +223,16 @@ end
223223
leaf_equal(a, b)
224224
else
225225
(
226-
branch_equal(a, b) && Base.Cartesian.@nif(
226+
branch_equal(a, b) && Base.Cartesian.@nif( # COV_EXCL_LINE
227227
$D,
228228
i -> deg == i, # COV_EXCL_LINE
229-
i ->
229+
i -> begin # COV_EXCL_LINE
230230
let cs_a = get_children(a, Val(i)), cs_b = get_children(b, Val(i)) # COV_EXCL_LINE
231231
Base.Cartesian.@nall(
232232
i, j -> inner_is_equal(cs_a[j], cs_b[j], id_maps)
233233
)
234234
end
235+
end
235236
)
236237
)
237238
end

test/test_n_arity_nodes.jl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,23 @@ end
354354
tree_f64_d3_for_convert = tree_tmr
355355
converted_tree_f32_d3_explicit_D = convert(Node{Float32,3}, tree_f64_d3_for_convert)
356356
@test typeof(converted_tree_f32_d3_explicit_D) == Node{Float32,3}
357+
358+
# Test that converting between nodes with different degrees throws ArgumentError
359+
tree_d2 = Node{Float64,2}(; val=1.0) # Node with max degree 2
360+
tree_d3 = Node{Float64,3}(; val=1.0) # Node with max degree 3
361+
362+
@test_throws ArgumentError convert(Node{Float64,2}, tree_d3)
363+
@test_throws ArgumentError convert(Node{Float64,3}, tree_d2)
364+
365+
# Verify the error message contains the expected text
366+
try
367+
convert(Node{Float64,2}, tree_d3)
368+
@test false # Should not reach here
369+
catch e
370+
@test e isa ArgumentError
371+
@test occursin("Cannot convert", e.msg)
372+
@test occursin("because they have different degrees", e.msg)
373+
end
357374
end
358375

359376
@testitem "LoopVectorizationExt with N-ary (degn_eval)" tags = [:narity] begin

0 commit comments

Comments
 (0)