|
1 | 1 | using DynamicExpressions |
2 | 2 | using Test |
3 | | -using Zygote |
4 | 3 |
|
5 | 4 | # Before defining OperatorEnum, calling the implicit (deprecated) |
6 | 5 | # syntax should fail: |
7 | | -tree = Node(; feature=1) |
| 6 | +tree = Node{Float64}(; feature=1) |
8 | 7 |
|
9 | 8 | if VERSION >= v"1.8" |
10 | | - @test_throws ErrorException tree([1.0 2.0]') |
11 | | - @test_throws "Please use the " tree([1.0 2.0]') |
12 | | - @test_throws ErrorException tree'([1.0 2.0]') |
13 | | - @test_throws "Please use the " tree'([1.0 2.0]') |
| 9 | + @test_throws ErrorException tree([1.0; 2.0;;]) |
| 10 | + @test_throws "Please use the " tree([1.0; 2.0;;]) |
| 11 | + @test_throws ErrorException tree'([1.0; 2.0;;]) |
| 12 | + @test_throws "Please use the " tree'([1.0; 2.0;;]) |
14 | 13 | end |
15 | 14 |
|
| 15 | +# Initial strings are still somewhat useful |
16 | 16 | @test string(tree) == "x1" |
17 | 17 | @test string(Node(1, tree)) == "unary_operator[1](x1)" |
18 | 18 | @test string(Node(1, tree, tree)) == "binary_operator[1](x1, x1)" |
19 | 19 |
|
20 | | -# Also test warnings: |
21 | | -for constructor in (OperatorEnum, GenericOperatorEnum) |
22 | | - operators = constructor(; binary_operators=[+, -, *, /], unary_operators=[cos, sin]) |
23 | | - tree([1.0 2.0]') |
24 | | - # Can't test for this: |
25 | | - # expected_warn_msg = "The `tree(X; kws...)` syntax is deprecated" |
26 | | - # @test occursin(expected_warn_msg, msg) |
| 20 | +# Before loading extensions, should fail with helpful message: |
| 21 | +operators = OperatorEnum(; binary_operators=[+, -, *, /], unary_operators=[cos, sin]) |
| 22 | +x1, x2 = Node{Float64}(; feature=1), Node{Float64}(; feature=2) |
| 23 | +tree = cos(2.1 * x1) + sin(x2) |
27 | 24 |
|
28 | | - constructor == GenericOperatorEnum && continue |
| 25 | +if VERSION >= v"1.9" |
| 26 | + @test_throws( |
| 27 | + "Please load the `SymbolicUtils` package to use `node_to_symbolic`.", |
| 28 | + node_to_symbolic(tree, operators) |
| 29 | + ) |
| 30 | + @test_throws( |
| 31 | + "Please load the `SymbolicUtils` package to use `symbolic_to_node`.", |
| 32 | + symbolic_to_node(tree, operators) |
| 33 | + ) |
29 | 34 |
|
30 | | - tree'([1.0 2.0]') |
31 | | - # Can't test for this: |
32 | | - # expected_warn_msg = "The `tree'(X; kws...)` syntax is deprecated" |
33 | | - # @test occursin(expected_warn_msg, msg) |
| 35 | + @test_throws("Please load the Zygote.jl package.", tree'(ones(2, 10))) |
34 | 36 | end |
0 commit comments