@@ -14,6 +14,19 @@ macro test_strict_subsumption(x, y)
14
14
end
15
15
end
16
16
17
+ function test_equal (o1:: VarName{sym1} , o2:: VarName{sym2} ) where {sym1, sym2}
18
+ return sym1 === sym2 && test_equal (o1. optic, o2. optic)
19
+ end
20
+ function test_equal (o1:: ComposedFunction , o2:: ComposedFunction )
21
+ return test_equal (o1. inner, o2. inner) && test_equal (o1. outer, o2. outer)
22
+ end
23
+ function test_equal (o1:: Accessors.IndexLens , o2:: Accessors.IndexLens )
24
+ return test_equal (o1. indices, o2. indices)
25
+ end
26
+ function test_equal (o1, o2)
27
+ return o1 == o2
28
+ end
29
+
17
30
@testset " varnames" begin
18
31
@testset " construction & concretization" begin
19
32
i = 1 : 10
27
40
28
41
# concretization
29
42
y = zeros (10 , 10 )
30
- x = (a = [1.0 2.0 ; 3.0 4.0 ; 5.0 6.0 ], );
43
+ x = (a = [1.0 2.0 ; 3.0 4.0 ; 5.0 6.0 ],);
31
44
32
45
@test @varname (y[begin , i], true ) == @varname (y[1 , 1 : 10 ])
33
- @test get (y, @varname (y[:], true )) == get (y , @varname (y[1 : 100 ]))
34
- @test get (y, @varname (y[:, begin ], true )) == get (y , @varname (y[1 : 10 , 1 ]))
35
- @test getoptic (AbstractPPL. concretize (@varname (y[:]), y)). indices[1 ] ===
46
+ @test test_equal ( @varname (y[:], true ), @varname (y[1 : 100 ]))
47
+ @test test_equal ( @varname (y[:, begin ], true ), @varname (y[1 : 10 , 1 ]))
48
+ @test getoptic (AbstractPPL. concretize (@varname (y[:]), y)). indices[1 ] ===
36
49
AbstractPPL. ConcretizedSlice (to_indices (y, (:,))[1 ])
37
- @test get (x, @varname (x. a[1 : end , end ][:], true )) == get (x, @varname (x. a[1 : 3 ,2 ][1 : 3 ]))
50
+ @test test_equal (@varname (x. a[1 : end , end ][:], true ), @varname (x. a[1 : 3 ,2 ][1 : 3 ]))
51
+ end
52
+
53
+ @testset " get & set" begin
54
+ x = (a = [1.0 2.0 ; 3.0 4.0 ; 5.0 6.0 ], b = 1.0 );
55
+ @test get (x, @varname (a[1 , 2 ])) == 2.0
56
+ @test get (x, @varname (b)) == 1.0
57
+ @test set (x, @varname (a[1 , 2 ]), 10 ) == (a = [1.0 10.0 ; 3.0 4.0 ; 5.0 6.0 ], b = 1.0 )
58
+ @test set (x, @varname (b), 10 ) == (a = [1.0 2.0 ; 3.0 4.0 ; 5.0 6.0 ], b = 10.0 )
38
59
end
39
60
40
61
@testset " subsumption with standard indexing" begin
83
104
84
105
@testset " non-standard indexing" begin
85
106
A = rand (10 , 10 )
86
- @test get (A, @varname (A[1 , Not (3 )], true )) == get (A , @varname (A[1 , [1 , 2 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ]]))
107
+ @test test_equal ( @varname (A[1 , Not (3 )], true ), @varname (A[1 , [1 , 2 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ]]))
87
108
88
109
B = OffsetArray (A, - 5 , - 5 ) # indices -4:5×-4:5
89
- @test collect ( get (B, @varname (B[1 , :], true ))) == collect ( get (B , @varname (B[1 , - 4 : 5 ]) ))
110
+ @test test_equal ( @varname (B[1 , :], true ), @varname (B[1 , - 4 : 5 ]))
90
111
91
112
end
92
113
@testset " type stability" begin
96
117
@inferred VarName {:a} (PropertyLens (:b ))
97
118
@inferred VarName {:a} (Accessors. opcompose (IndexLens (1 ), PropertyLens (:b )))
98
119
99
- a = [1 , 2 , 3 ]
100
- @inferred get (a, @varname (a[1 ]))
101
-
102
120
b = (a= [1 , 2 , 3 ],)
103
- @inferred get (b, @varname (b . a[1 ]))
121
+ @inferred get (b, @varname (a[1 ]))
104
122
@inferred Accessors. set (b, @varname (a[1 ]), 10 )
105
123
106
124
c = (b= (a= [1 , 2 , 3 ],),)
107
- @inferred get (c, @varname (c . b. a[1 ]))
125
+ @inferred get (c, @varname (b. a[1 ]))
108
126
@inferred Accessors. set (c, @varname (b. a[1 ]), 10 )
109
127
end
110
128
end
0 commit comments