Skip to content

Commit 5eb07d5

Browse files
PriynshLilithHafnerDilumAluthge
authored
Adding tests for AbstractArrayMath.jl (#56773)
added tests for lines 7, 137-154 (insertdims function) from base/abstractarraymath.jl --------- Co-authored-by: Lilith Orion Hafner <lilithhafner@gmail.com> Co-authored-by: Dilum Aluthge <dilum@aluthge.com>
1 parent 006f19c commit 5eb07d5

File tree

2 files changed

+55
-28
lines changed

2 files changed

+55
-28
lines changed

test/abstractarray.jl

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2206,3 +2206,24 @@ end
22062206
@test b.ref === a.ref
22072207
end
22082208
end
2209+
@testset "AbstractArrayMath" begin
2210+
@testset "IsReal" begin
2211+
A = [1, 2, 3, 4]
2212+
@test isreal(A) == true
2213+
B = [1.1, 2.2, 3.3, 4.4]
2214+
@test isreal(B) == true
2215+
C = [1, 2.2, 3]
2216+
@test isreal(C) == true
2217+
D = Real[]
2218+
@test isreal(D) == true
2219+
E = [1 + 1im, 2 - 2im]
2220+
@test isreal(E) == false
2221+
struct MyReal <: Real
2222+
value::Float64
2223+
end
2224+
F = [MyReal(1.0), MyReal(2.0)]
2225+
@test isreal(F) == true
2226+
G = ["a", "b", "c"]
2227+
@test_throws MethodError isreal(G)
2228+
end
2229+
end

test/arrayops.jl

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -307,34 +307,40 @@ end
307307
@test_throws ArgumentError dropdims(a, dims=3)
308308
@test_throws ArgumentError dropdims(a, dims=4)
309309
@test_throws ArgumentError dropdims(a, dims=6)
310-
311-
312-
a = rand(8, 7)
313-
@test @inferred(insertdims(a, dims=1)) == @inferred(insertdims(a, dims=(1,))) == reshape(a, (1, 8, 7))
314-
@test @inferred(insertdims(a, dims=3)) == @inferred(insertdims(a, dims=(3,))) == reshape(a, (8, 7, 1))
315-
@test @inferred(insertdims(a, dims=(1, 3))) == reshape(a, (1, 8, 1, 7))
316-
@test @inferred(insertdims(a, dims=(1, 2, 3))) == reshape(a, (1, 1, 1, 8, 7))
317-
@test @inferred(insertdims(a, dims=(1, 4))) == reshape(a, (1, 8, 7, 1))
318-
@test @inferred(insertdims(a, dims=(1, 3, 5))) == reshape(a, (1, 8, 1, 7, 1))
319-
@test @inferred(insertdims(a, dims=(1, 2, 4, 6))) == reshape(a, (1, 1, 8, 1, 7, 1))
320-
@test @inferred(insertdims(a, dims=(1, 3, 4, 6))) == reshape(a, (1, 8, 1, 1, 7, 1))
321-
@test @inferred(insertdims(a, dims=(1, 4, 6, 3))) == reshape(a, (1, 8, 1, 1, 7, 1))
322-
@test @inferred(insertdims(a, dims=(1, 3, 5, 6))) == reshape(a, (1, 8, 1, 7, 1, 1))
323-
324-
@test_throws ArgumentError insertdims(a, dims=(1, 1, 2, 3))
325-
@test_throws ArgumentError insertdims(a, dims=(1, 2, 2, 3))
326-
@test_throws ArgumentError insertdims(a, dims=(1, 2, 3, 3))
327-
@test_throws UndefKeywordError insertdims(a)
328-
@test_throws ArgumentError insertdims(a, dims=0)
329-
@test_throws ArgumentError insertdims(a, dims=(1, 2, 1))
330-
@test_throws ArgumentError insertdims(a, dims=4)
331-
@test_throws ArgumentError insertdims(a, dims=6)
332-
333-
# insertdims and dropdims are inverses
334-
b = rand(1,1,1,5,1,1,7)
335-
for dims in [1, (1,), 2, (2,), 3, (3,), (1,3), (1,2,3), (1,2), (1,3,5), (1,2,5,6), (1,3,5,6), (1,3,5,6), (1,6,5,3)]
336-
@test dropdims(insertdims(a; dims); dims) == a
337-
@test insertdims(dropdims(b; dims); dims) == b
310+
@testset "insertdims" begin
311+
a = rand(8, 7)
312+
@test @inferred(insertdims(a, dims=1)) == @inferred(insertdims(a, dims=(1,))) == reshape(a, (1, 8, 7))
313+
@test @inferred(insertdims(a, dims=3)) == @inferred(insertdims(a, dims=(3,))) == reshape(a, (8, 7, 1))
314+
@test @inferred(insertdims(a, dims=(1, 3))) == reshape(a, (1, 8, 1, 7))
315+
@test @inferred(insertdims(a, dims=(1, 2, 3))) == reshape(a, (1, 1, 1, 8, 7))
316+
@test @inferred(insertdims(a, dims=(1, 4))) == reshape(a, (1, 8, 7, 1))
317+
@test @inferred(insertdims(a, dims=(1, 3, 5))) == reshape(a, (1, 8, 1, 7, 1))
318+
@test @inferred(insertdims(a, dims=(1, 2, 4, 6))) == reshape(a, (1, 1, 8, 1, 7, 1))
319+
@test @inferred(insertdims(a, dims=(1, 3, 4, 6))) == reshape(a, (1, 8, 1, 1, 7, 1))
320+
@test @inferred(insertdims(a, dims=(1, 4, 6, 3))) == reshape(a, (1, 8, 1, 1, 7, 1))
321+
@test @inferred(insertdims(a, dims=(1, 3, 5, 6))) == reshape(a, (1, 8, 1, 7, 1, 1))
322+
@test_throws ArgumentError insertdims(a, dims=(1, 1, 2, 3))
323+
@test_throws ArgumentError insertdims(a, dims=(1, 2, 2, 3))
324+
@test_throws ArgumentError insertdims(a, dims=(1, 2, 3, 3))
325+
@test_throws UndefKeywordError insertdims(a)
326+
@test_throws ArgumentError insertdims(a, dims=0)
327+
@test_throws ArgumentError insertdims(a, dims=(1, 2, 1))
328+
@test_throws ArgumentError insertdims(a, dims=4)
329+
@test_throws ArgumentError insertdims(a, dims=6)
330+
A = reshape(1:6, 2, 3)
331+
@test_throws ArgumentError insertdims(A, dims=(2, 2))
332+
D = insertdims(A, dims=())
333+
@test size(D) == size(A)
334+
@test D == A
335+
E = ones(2, 3, 4)
336+
F = insertdims(E, dims=(2, 4, 6))
337+
@test size(F) == (2, 1, 3, 1, 4, 1)
338+
# insertdims and dropdims are inverses
339+
b = rand(1,1,1,5,1,1,7)
340+
for dims in [1, (1,), 2, (2,), 3, (3,), (1,3), (1,2,3), (1,2), (1,3,5), (1,2,5,6), (1,3,5,6), (1,3,5,6), (1,6,5,3)]
341+
@test dropdims(insertdims(a; dims); dims) == a
342+
@test insertdims(dropdims(b; dims); dims) == b
343+
end
338344
end
339345

340346
sz = (5,8,7)

0 commit comments

Comments
 (0)