1
+ @testset " RecoPlan" begin
2
+ pre = RadonPreprocessingParameters (frames = collect (1 : 3 ))
3
+ reco = IterativeRadonReconstructionParameters (; shape = size (images)[1 : 3 ], angles = angles, iterations = 1 , reg = [L2Regularization (0.001 ), PositiveRegularization ()], solver = CGNR);
4
+ algo = IterativeRadonAlgorithm (IterativeRadonParameters (pre, reco))
5
+
6
+
7
+ @testset " Construction" begin
8
+ # From algorithm
9
+ plan_fromAlgo = toPlan (algo)
10
+
11
+ # With kwarg constructor
12
+ plan_fromKwargs = RecoPlan (IterativeRadonAlgorithm; parameter = RecoPlan (IterativeRadonParameters; pre = RecoPlan (RadonPreprocessingParameters; frames = collect (1 : 3 )),
13
+ reco = RecoPlan (IterativeRadonReconstructionParameters; shape = size (images)[1 : 3 ], angles = angles, iterations = 1 , reg = [L2Regularization (0.001 ), PositiveRegularization ()], solver = CGNR)))
14
+
15
+ # Individually with setproperty!
16
+ plan_pre = RecoPlan (RadonPreprocessingParameters)
17
+ plan_pre. frames = collect (1 : 3 )
18
+ @test build (plan_pre). frames == collect (1 : 3 )
19
+ @test build (plan_pre) isa RadonPreprocessingParameters
20
+
21
+ plan_reco = RecoPlan (IterativeRadonReconstructionParameters)
22
+ plan_reco. shape = size (images)[1 : 3 ]
23
+ plan_reco. angles = angles
24
+ plan_reco. iterations = 1
25
+ plan_reco. reg = [L2Regularization (0.001 ), PositiveRegularization ()]
26
+ plan_reco. solver = CGNR
27
+ @test build (plan_reco). solver == plan_reco. solver
28
+ @test build (plan_reco) isa IterativeRadonReconstructionParameters
29
+
30
+ plan_params = RecoPlan (IterativeRadonParameters)
31
+ plan_params. pre = plan_pre
32
+ plan_params. reco = plan_reco
33
+
34
+ plan_set = RecoPlan (IterativeRadonAlgorithm)
35
+ plan_set. parameter = plan_params
36
+
37
+ algo_1 = build (plan_fromAlgo)
38
+ algo_2 = build (plan_fromKwargs)
39
+ algo_3 = build (plan_set)
40
+ # Not the best, but the types dont define proper equals, so we use our default hash method
41
+ @test hash (algo_1. parameter. pre) == hash (algo_2. parameter. pre)
42
+ @test hash (algo_2. parameter. pre) == hash (algo_3. parameter. pre)
43
+ @test hash (algo_1. parameter. reco) == hash (algo_2. parameter. reco)
44
+ @test hash (algo_2. parameter. reco) == hash (algo_3. parameter. reco)
45
+ end
46
+
47
+ @testset " Properties" begin
48
+ # Test parameter with union property type
49
+ plan = RecoPlan (RadonFilteredBackprojectionParameters)
50
+ instance = nothing
51
+
52
+ @testset " Setter/Getter" begin
53
+ # Init missing
54
+ @test ismissing (plan. angles)
55
+ @test ismissing (plan. filter)
56
+
57
+ # Set/get
58
+ plan. angles = angles
59
+ @test plan. angles == angles
60
+ @test_throws Exception plan. doesntExist = 42
61
+
62
+ # Type checking
63
+ plan. filter = nothing
64
+ @test isnothing (plan. filter)
65
+ @test_throws Exception plan. filter = " Test"
66
+ @test isnothing (plan. filter)
67
+ plan. filter = missing
68
+ @test ismissing (plan. filter)
69
+ plan. filter = [0.2 ]
70
+ @test plan. filter == [0.2 ]
71
+
72
+ # Clearing
73
+ clear! (plan)
74
+ @test ismissing (plan. angles)
75
+ @test ismissing (plan. filter)
76
+
77
+ # Used during construction
78
+ plan. angles = angles
79
+ instance = build (plan)
80
+ @test instance. angles == angles
81
+ @test isnothing (instance. filter) # Default kwarg
82
+ end
83
+
84
+ outer = RecoPlan (DirectRadonParameters)
85
+ incorrect = RecoPlan (RadonPreprocessingParameters)
86
+ @testset " Nested Plans" begin
87
+ # Type checking
88
+ @test_throws Exception outer. reco = incorrect
89
+ outer. reco = instance
90
+ @test outer. reco == instance
91
+ outer. reco = plan
92
+ @test outer. reco == plan
93
+ # Clearing
94
+ plan. angles = angles
95
+ @test ! ismissing (outer. reco. angles)
96
+ clear! (outer)
97
+ @test ismissing (outer. reco. angles)
98
+ clear! (outer, false )
99
+ @test ismissing (outer. reco)
100
+ end
101
+
102
+ @testset " SetAll!" begin
103
+ # setAll! variants
104
+ clear! (plan)
105
+ # Kwargs
106
+ setAll! (plan; angles = angles, filter = nothing , doesntExist = 42 )
107
+ @test plan. angles == angles
108
+ @test isnothing (plan. filter)
109
+ clear! (plan)
110
+ # Dict{Symbol}
111
+ setAll! (plan, Dict {Symbol, Any} (:angles => angles, :filter => nothing , :doesntExist => 42 ))
112
+ @test plan. angles == angles
113
+ @test isnothing (plan. filter)
114
+ clear! (plan)
115
+ # Dict{String}
116
+ setAll! (plan, Dict {String, Any} (" angles" => angles, " filter" => nothing , " doesntExist" => 42 ))
117
+ @test plan. angles == angles
118
+ @test isnothing (plan. filter)
119
+ clear! (plan)
120
+ # Nested plan
121
+ outer. reco = plan
122
+ setAll! (plan; angles = angles, filter = nothing )
123
+ @test plan. angles == angles
124
+ @test isnothing (plan. filter)
125
+ clear! (plan)
126
+ end
127
+
128
+ @testset " Property names" begin
129
+ # Property names and filtering
130
+ struct TestParameters <: AbstractImageReconstructionParameters
131
+ a:: Int64
132
+ b:: Float64
133
+ _c:: String
134
+ end
135
+ test = RecoPlan (TestParameters)
136
+ @test in (:a , collect (propertynames (test)))
137
+ @test in (:b , collect (propertynames (test)))
138
+ @test ! in (:c , collect (propertynames (test)))
139
+ end
140
+ end
141
+
142
+ @testset " Observables" begin
143
+ plan = RecoPlan (RadonFilteredBackprojectionParameters)
144
+ observed = Ref {Bool} ()
145
+ fun = (val) -> observed[] = true
146
+ on (fun, plan, :angles )
147
+ plan. angles = angles
148
+ @test observed[]
149
+ observed[] = false
150
+ try
151
+ plan. angles = " Test"
152
+ catch e
153
+ end
154
+ @test ! (observed[])
155
+
156
+ off (plan, :angles , fun)
157
+ plan. angles = angles
158
+ @test ! (observed[])
159
+
160
+ obsv = plan[:angles ]
161
+ @test obsv isa Observable
162
+
163
+ on (fun, plan, :angles )
164
+ clear! (plan)
165
+ plan. angles = angles
166
+ @test ! (observed[])
167
+ end
168
+
169
+ @testset " Traversal" begin
170
+ end
171
+
172
+ end
0 commit comments