Skip to content

Commit 59b26bc

Browse files
committed
test: improve coverage
1 parent a08202c commit 59b26bc

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

test/test_expressions.jl

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,36 @@ end
237237
end
238238
end
239239

240+
@testitem "No operators and variable names" begin
241+
using DynamicExpressions
242+
243+
x1 = Node{Float64}(; feature=1)
244+
expr = Expression(x1; operators=nothing, variable_names=nothing)
245+
246+
@test sprint(show, expr) == "x1"
247+
@test copy(expr) == expr
248+
@test hash(expr) == hash(copy(expr))
249+
250+
@test sprint(show, get_metadata(expr)) ==
251+
"Metadata((operators = nothing, variable_names = nothing))"
252+
253+
cos_x1 = Node{Float64}(; op=1, l=x1)
254+
expr = Expression(cos_x1; operators=nothing, variable_names=nothing)
255+
@test sprint(show, expr) == "unary_operator[1](x1)"
256+
@test copy(expr) == expr
257+
@test hash(expr) == hash(copy(expr))
258+
259+
@test sprint(show, get_metadata(expr)) ==
260+
"Metadata((operators = nothing, variable_names = nothing))"
261+
262+
@test_throws MethodError expr(rand(Float64, 2, 5))
263+
264+
# Now, with passing operators explicitly
265+
X = rand(Float64, 2, 5)
266+
operators = OperatorEnum(; unary_operators=[cos])
267+
@test expr(X, operators) cos.(X[1, :])
268+
end
269+
240270
@testitem "Miscellaneous expression calls" begin
241271
using DynamicExpressions
242272
using DynamicExpressions: get_tree, get_operators

test/test_multi_expression.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@
6060
multi_ex, nothing
6161
)
6262
@test_throws "`get_tree` function must be implemented for" DE.get_tree(multi_ex)
63+
@test_throws "`get_contents` function must be implemented for" DE.get_contents(
64+
multi_ex
65+
)
66+
@test_throws "`get_metadata` function must be implemented for" DE.get_metadata(
67+
multi_ex
68+
)
6369
@test_throws "`copy` function must be implemented for" copy(multi_ex)
6470
@test_throws "`get_scalar_constants` function must be implemented for" get_scalar_constants(
6571
multi_ex

0 commit comments

Comments
 (0)