@@ -2,8 +2,6 @@ using TestItems: @testitem
2
2
3
3
@testitem " AssignOperator basic functionality" begin
4
4
using DynamicExpressions
5
- using DynamicExpressions. SpecialOperatorsModule: AssignOperator
6
- using DynamicExpressions. EvaluateModule: eval_tree_array
7
5
using Test
8
6
using Random
9
7
@@ -37,7 +35,32 @@ using TestItems: @testitem
37
35
38
36
# But, with the reverse order, we get the x2 _before_ it was reassigned
39
37
assign_expr_reverse = x2 + assign_x2 (0.0 * x1 + 3.0 )
38
+ @test string_tree (assign_expr_reverse) == " x2 + [x2 =]((0.0 * x1) + 3.0)"
40
39
result, completed = eval_tree_array (assign_expr_reverse, X)
41
40
@test completed == true
42
41
@test result == [3.5 , 4.5 , 5.5 ]
43
42
end
43
+
44
+ @testitem " AssignOperator with self-assignment" begin
45
+ using DynamicExpressions
46
+ using Test
47
+ using Random
48
+
49
+ assign_x1 = AssignOperator (; target_register= 1 )
50
+ operators = OperatorEnum (;
51
+ binary_operators= [+ , - , * , / ], unary_operators= [sin, cos, assign_x1]
52
+ )
53
+ variable_names = [" a" , " b" , " c" ]
54
+ X = rand (Float64, 2 , 10 )
55
+
56
+ x1 = Expression (Node (; feature= 1 ); operators, variable_names)
57
+ x2 = Expression (Node (; feature= 2 ); operators, variable_names)
58
+ x3 = Expression (Node (; feature= 3 ); operators, variable_names)
59
+
60
+ expr = assign_x1 (assign_x1 (x1 * 2 ) + x1)
61
+ @test string_tree (expr) == " [a =]([a =](a * 2.0) + a)"
62
+
63
+ result, completed = eval_tree_array (expr, X)
64
+ @test completed == true
65
+ @test result == X[1 , :] .* 4.0
66
+ end
0 commit comments