@@ -2,8 +2,6 @@ using TestItems: @testitem
22
33@testitem " AssignOperator basic functionality" begin
44 using DynamicExpressions
5- using DynamicExpressions. SpecialOperatorsModule: AssignOperator
6- using DynamicExpressions. EvaluateModule: eval_tree_array
75 using Test
86 using Random
97
@@ -37,7 +35,32 @@ using TestItems: @testitem
3735
3836 # But, with the reverse order, we get the x2 _before_ it was reassigned
3937 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)"
4039 result, completed = eval_tree_array (assign_expr_reverse, X)
4140 @test completed == true
4241 @test result == [3.5 , 4.5 , 5.5 ]
4342end
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