Skip to content

Commit 952dd50

Browse files
committed
Test more errors
1 parent c01a406 commit 952dd50

1 file changed

Lines changed: 79 additions & 0 deletions

File tree

test/test_amplitudes.jl

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,85 @@ end
153153
end
154154

155155

156+
@testset "Invalid constructions" begin
157+
tlist = collect(range(0, 10, length = 101))
158+
S(t) = flattop(t, T = 10, t_rise = 2, func = :blackman)
159+
ϵ(t) = 1.0
160+
n = length(tlist) - 1
161+
162+
# LockedAmplitude: complex vector is not convertible to Vector{Float64}
163+
captured = IOCapture.capture(rethrow = Union{}) do
164+
LockedAmplitude(fill(1.0 + 1.0im, n))
165+
end
166+
@test captured.error
167+
@test contains(
168+
captured.value.msg,
169+
"shape that is a vector must be convertible to Vector{Float64}"
170+
)
171+
172+
# LockedAmplitude: non-vector, non-callable shape
173+
captured = IOCapture.capture(rethrow = Union{}) do
174+
LockedAmplitude(42)
175+
end
176+
@test captured.error
177+
@test contains(
178+
captured.value.msg,
179+
"shape must either be a Vector{Float64} or a callable"
180+
)
181+
182+
# ShapedAmplitude: complex vector control
183+
captured = IOCapture.capture(rethrow = Union{}) do
184+
ShapedAmplitude(fill(1.0 + 1.0im, n); shape = S)
185+
end
186+
@test captured.error
187+
@test contains(
188+
captured.value.msg,
189+
"control that is a vector must be convertible to Vector{Float64}"
190+
)
191+
192+
# ShapedAmplitude: complex vector shape
193+
captured = IOCapture.capture(rethrow = Union{}) do
194+
ShapedAmplitude(ϵ; shape = fill(1.0 + 1.0im, n))
195+
end
196+
@test captured.error
197+
@test contains(
198+
captured.value.msg,
199+
"shape that is a vector must be convertible to Vector{Float64}"
200+
)
201+
202+
# ShapedAmplitude: non-vector, non-callable control
203+
captured = IOCapture.capture(rethrow = Union{}) do
204+
ShapedAmplitude(42; shape = S)
205+
end
206+
@test captured.error
207+
@test contains(
208+
captured.value.msg,
209+
"control must either be a Vector{Float64} or a callable"
210+
)
211+
212+
# ShapedAmplitude: non-vector, non-callable shape
213+
captured = IOCapture.capture(rethrow = Union{}) do
214+
ShapedAmplitude(ϵ; shape = 42)
215+
end
216+
@test captured.error
217+
@test contains(
218+
captured.value.msg,
219+
"shape must either be a Vector{Float64} or a callable"
220+
)
221+
222+
# ShapedAmplitude: control and shape vectors of different lengths
223+
captured = IOCapture.capture(rethrow = Union{}) do
224+
ShapedAmplitude(ones(n); shape = ones(n - 1))
225+
end
226+
@test captured.error
227+
@test contains(
228+
captured.value.msg,
229+
"control and shape vectors must have the same length"
230+
)
231+
232+
end
233+
234+
156235
@testset "ShapedAmplitude substitute" begin
157236
tlist = collect(range(0, 10, length = 101))
158237
S(t) = flattop(t, T = 10, t_rise = 2, func = :blackman)

0 commit comments

Comments
 (0)