Skip to content

Commit e956141

Browse files
committed
Include test for safety of helper functions
1 parent a6e6dee commit e956141

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

test/test_safe_helpers.jl

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using DynamicExpressions
2+
using Test
3+
4+
function _square(x)
5+
return x^2
6+
end
7+
8+
operators = OperatorEnum(;
9+
binary_operators=[+, -, *, /], unary_operators=[cos, sin, _square]
10+
)
11+
@extend_operators operators
12+
x1, x2, x3 = (i -> Node(Float64; feature=i)).(1:3)
13+
14+
# Should work normally:
15+
@test _square(x1 + x2 / x3) * x2 + 0.5 isa Node
16+
17+
# But, upon redefining `operators`, we should get errors:
18+
operators = OperatorEnum(; binary_operators=[+, -, *], unary_operators=[cos, sin, _square])
19+
20+
# Safe:
21+
@test _square(x1 + x2) * x2 + 0.5 isa Node
22+
23+
# Breaks:
24+
@test_throws ErrorException _square(x1 + x2 / x3) * x2 + 0.5
25+
26+
operators = OperatorEnum(; binary_operators=[+, -, *, /], unary_operators=[cos, sin])
27+
# Safe:
28+
@test (x1 + x2 / x3) * x2 + 0.5 isa Node
29+
30+
# Breaks:
31+
@test_throws ErrorException _square(x1 + x2 / x3) * x2 + 0.5

test/unittest.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,7 @@ end
101101
@safetestset "Test containers preserved" begin
102102
include("test_container_preserved.jl")
103103
end
104+
105+
@safetestset "Test helpers break upon redefining" begin
106+
include("test_safe_helpers.jl")
107+
end

0 commit comments

Comments
 (0)