Skip to content

Commit f30c612

Browse files
committed
🚨 Add more tests related to CRP and MRP
1 parent 73f1f94 commit f30c612

2 files changed

Lines changed: 74 additions & 0 deletions

File tree

test/crp.jl

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,3 +225,40 @@ end
225225
@test isapprox(dc, dc_num; rtol = 1e-4, atol = 1e-6)
226226
end
227227
end
228+
229+
# -- Functions: getindex, length, setindex! ------------------------------------------------
230+
231+
@testset "General Functions of CRP: Iterable Object API" begin
232+
c = CRP(randn(), randn(), randn())
233+
@test length(c) == 3
234+
@test c[1] == c.q1
235+
@test c[2] == c.q2
236+
@test c[3] == c.q3
237+
238+
@test_throws BoundsError c[0]
239+
@test_throws BoundsError c[4]
240+
241+
v = zeros(10)
242+
243+
v[4:6] = c
244+
245+
@test v[1] == 0
246+
@test v[2] == 0
247+
@test v[3] == 0
248+
@test v[4] == c.q1
249+
@test v[5] == c.q2
250+
@test v[6] == c.q3
251+
@test v[7] == 0
252+
@test v[8] == 0
253+
@test v[9] == 0
254+
@test v[10] == 0
255+
256+
@test firstindex(c) === 1
257+
@test lastindex(c) === 3
258+
259+
v = c[:]
260+
261+
@test v[1] == c.q1
262+
@test v[2] == c.q2
263+
@test v[3] == c.q3
264+
end

test/mrp.jl

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,3 +238,40 @@ end
238238
@test isapprox(dm, dm_num; rtol = 1e-4, atol = 1e-6)
239239
end
240240
end
241+
242+
# -- Functions: getindex, length, setindex! ------------------------------------------------
243+
244+
@testset "General Functions of MRP: Iterable Object API" begin
245+
m = MRP(randn(), randn(), randn())
246+
@test length(m) == 3
247+
@test m[1] == m.q1
248+
@test m[2] == m.q2
249+
@test m[3] == m.q3
250+
251+
@test_throws BoundsError m[0]
252+
@test_throws BoundsError m[4]
253+
254+
v = zeros(10)
255+
256+
v[4:6] = m
257+
258+
@test v[1] == 0
259+
@test v[2] == 0
260+
@test v[3] == 0
261+
@test v[4] == m.q1
262+
@test v[5] == m.q2
263+
@test v[6] == m.q3
264+
@test v[7] == 0
265+
@test v[8] == 0
266+
@test v[9] == 0
267+
@test v[10] == 0
268+
269+
@test firstindex(m) === 1
270+
@test lastindex(m) === 3
271+
272+
v = m[:]
273+
274+
@test v[1] == m.q1
275+
@test v[2] == m.q2
276+
@test v[3] == m.q3
277+
end

0 commit comments

Comments
 (0)