11using Test
2+ using IOCapture: IOCapture
23using QuantumPropagators. Interfaces: check_amplitude, check_control
34using QuantumPropagators. Shapes: flattop
45using QuantumPropagators. Amplitudes: LockedAmplitude, ShapedAmplitude
@@ -25,7 +26,11 @@ using QuantumPropagators.Controls: discretize_on_midpoints
2526 @test length (get_controls (ampl)) == 0
2627 t = t_mid (tlist, 20 )
2728 @test evaluate (ampl, tlist, 20 ) ≈ S (t)
28- @test_throws Exception evaluate (ampl, t)
29+ captured = IOCapture. capture (rethrow = Union{}) do
30+ evaluate (ampl, t)
31+ end
32+ @test captured. error
33+ @test contains (captured. value. msg, " can only be evaluated with (tlist, n)" )
2934
3035end
3136
4954 t = t_mid (tlist, 20 )
5055 @test evaluate (ampl, tlist, 20 ) ≈ ϵ (t) * S (t)
5156
52-
5357 ampl = ShapedAmplitude (ϵ, tlist; shape = S)
5458 @test startswith (" $ampl " , " ShapedAmplitude(" )
5559 controls = get_controls (ampl)
5862 @test check_amplitude (ampl; tlist)
5963 t = t_mid (tlist, 20 )
6064 @test evaluate (ampl, tlist, 20 ) ≈ ϵ (t) * S (t)
61- @test_throws Exception evaluate (ampl, t)
65+ captured = IOCapture. capture (rethrow = Union{}) do
66+ evaluate (ampl, t)
67+ end
68+ @test captured. error
69+ @test contains (
70+ captured. value. msg,
71+ " vector control and shape can only be evaluated with (tlist, n)"
72+ )
6273
6374end
6475
116127 @test check_amplitude (ampl; tlist)
117128 t = t_mid (tlist, 20 )
118129 @test evaluate (ampl, tlist, 20 ) ≈ ϵ (t) * S (t)
119- @test_throws Exception evaluate (ampl, t)
130+ captured = IOCapture. capture (rethrow = Union{}) do
131+ evaluate (ampl, t)
132+ end
133+ @test captured. error
134+ @test contains (captured. value. msg, " vector shape can only be evaluated with (tlist, n)" )
120135
121136 # vector control, callable shape
122137 ampl = ShapedAmplitude (ϵ_vec; shape = S)
126141 @test check_amplitude (ampl; tlist)
127142 t = t_mid (tlist, 20 )
128143 @test evaluate (ampl, tlist, 20 ) ≈ ϵ (t) * S (t)
129- @test_throws Exception evaluate (ampl, t)
144+ captured = IOCapture. capture (rethrow = Union{}) do
145+ evaluate (ampl, t)
146+ end
147+ @test captured. error
148+ @test contains (
149+ captured. value. msg,
150+ " vector control can only be evaluated with (tlist, n)"
151+ )
130152
131153end
132154
144166 @test check_amplitude (ampl2; tlist)
145167 t = t_mid (tlist, 20 )
146168 @test evaluate (ampl2, tlist, 20 ) ≈ ϵ (t) * S (t)
147- @test_throws Exception evaluate (ampl2, t)
169+ captured = IOCapture. capture (rethrow = Union{}) do
170+ evaluate (ampl2, t)
171+ end
172+ @test captured. error
173+ @test contains (
174+ captured. value. msg,
175+ " vector control can only be evaluated with (tlist, n)"
176+ )
148177
149178end
0 commit comments