|
51 | 51 | @test result === dest_array[1] |
52 | 52 | end |
53 | 53 | end |
| 54 | + |
| 55 | +@testitem "copy_into! with expressions" begin |
| 56 | + using DynamicExpressions |
| 57 | + using DynamicExpressions: |
| 58 | + copy_into!, allocate_container, get_operators, get_variable_names |
| 59 | + |
| 60 | + operators = OperatorEnum(; binary_operators=[+, *], unary_operators=[sin]) |
| 61 | + variable_names = ["x", "y"] |
| 62 | + |
| 63 | + # Test regular Expression |
| 64 | + ex = @parse_expression( |
| 65 | + sin(x + 2.0 * y), operators = operators, variable_names = variable_names |
| 66 | + ) |
| 67 | + container = allocate_container(ex) |
| 68 | + result = copy_into!(container, ex) |
| 69 | + |
| 70 | + @test result == ex |
| 71 | + @test result !== ex |
| 72 | + @test get_tree(result) !== get_tree(ex) |
| 73 | + @test get_operators(result, nothing) === get_operators(ex, nothing) |
| 74 | + @test get_variable_names(result, nothing) === get_variable_names(ex, nothing) |
| 75 | + |
| 76 | + # Test ParametricExpression |
| 77 | + parameters = [1.0 2.0; 3.0 4.0] |
| 78 | + pex = @parse_expression( |
| 79 | + sin(x + p1 * y + p2), |
| 80 | + operators = operators, |
| 81 | + variable_names = variable_names, |
| 82 | + expression_type = ParametricExpression, |
| 83 | + extra_metadata = (; parameters=parameters, parameter_names=["p1", "p2"]) |
| 84 | + ) |
| 85 | + container = allocate_container(pex) |
| 86 | + result = copy_into!(container, pex) |
| 87 | + |
| 88 | + @test result == pex |
| 89 | + @test result !== pex |
| 90 | + @test get_tree(result) !== get_tree(pex) |
| 91 | + @test get_operators(result, nothing) === get_operators(pex, nothing) |
| 92 | + @test get_variable_names(result, nothing) === get_variable_names(pex, nothing) |
| 93 | + @test result.metadata.parameters !== pex.metadata.parameters |
| 94 | + @test result.metadata.parameters == pex.metadata.parameters |
| 95 | +end |
0 commit comments