Skip to content

Commit 7273bf7

Browse files
authored
use concrete pairs in tests (#222)
1 parent 02eb43a commit 7273bf7

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

test/runtests.jl

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ using Test
1111
using Documenter: doctest
1212
doctest(StructArrays)
1313

14-
1514
@testset "index" begin
1615
a, b = [1 2; 3 4], [4 5; 6 7]
1716
t = StructArray((a = a, b = b))
@@ -326,7 +325,6 @@ end
326325
end
327326
end
328327

329-
330328
struct A
331329
x::Int
332330
y::Int
@@ -347,11 +345,11 @@ end
347345
@test StructArray(a=a, b=b) == StructArray((a=a, b=b))
348346
@test StructArray{ComplexF64}(re=a, im=b) == StructArray{ComplexF64}((a, b))
349347
f1() = StructArray(a=[1.2], b=["test"])
350-
f2() = StructArray{Pair}(first=[1.2], second=["test"])
348+
f2() = StructArray{Pair{Float64, String}}(first=[1.2], second=["test"])
351349
t1 = @inferred f1()
352350
t2 = @inferred f2()
353351
@test t1 == StructArray((a=[1.2], b=["test"]))
354-
@test t2 == StructArray{Pair}(([1.2], ["test"]))
352+
@test t2 == StructArray{Pair{Float64, String}}(([1.2], ["test"]))
355353
end
356354

357355
@testset "complex" begin
@@ -390,36 +388,40 @@ end
390388
end
391389

392390
@testset "resize!" begin
393-
t = StructArray{Pair}(([3, 5], ["a", "b"]))
391+
t = StructArray{Pair{Int, String}}(([3, 5], ["a", "b"]))
394392
resize!(t, 5)
395393
@test length(t) == 5
396394
p = 1 => "c"
397395
t[5] = p
398396
@test t[5] == p
399397
end
398+
400399
@testset "sizehint!" begin
401-
t = StructArray{Pair}(([3, 5], [:a, :b]))
400+
t = StructArray{Pair{Int, Symbol}}(([3, 5], [:a, :b]))
402401
sizehint!(t, 5)
403402
@test @allocated(resize!(t, 5)) == 0
404403
@test length(t) == 5
405404
p = 1 => :c
406405
t[5] = p
407406
@test t[5] == p
408407
end
408+
409409
@testset "concat" begin
410-
t = StructArray{Pair}(([3, 5], ["a", "b"]))
410+
t = StructArray{Pair{Int, String}}(([3, 5], ["a", "b"]))
411411
push!(t, (2 => "d"))
412-
@test t == StructArray{Pair}(([3, 5, 2], ["a", "b", "d"]))
412+
@test t == StructArray{Pair{Int, String}}(([3, 5, 2], ["a", "b", "d"]))
413413
@test pop!(t) == (2 => "d")
414414
push!(t, (2 => "c"))
415-
@test t == StructArray{Pair}(([3, 5, 2], ["a", "b", "c"]))
415+
@test t == StructArray{Pair{Int, String}}(([3, 5, 2], ["a", "b", "c"]))
416416
append!(t, t)
417-
@test t == StructArray{Pair}(([3, 5, 2, 3, 5, 2], ["a", "b", "c", "a", "b", "c"]))
418-
t = StructArray{Pair}(([3, 5], ["a", "b"]))
419-
t2 = StructArray{Pair}(([1, 6], ["a", "b"]))
420-
@test cat(t, t2; dims=1)::StructArray == StructArray{Pair}(([3, 5, 1, 6], ["a", "b", "a", "b"])) == vcat(t, t2)
417+
@test t == StructArray{Pair{Int, String}}(([3, 5, 2, 3, 5, 2], ["a", "b", "c", "a", "b", "c"]))
418+
t = StructArray{Pair{Int, String}}(([3, 5], ["a", "b"]))
419+
t2 = StructArray{Pair{Int, String}}(([1, 6], ["a", "b"]))
420+
vertical_concat = StructArray{Pair{Int, String}}(([3, 5, 1, 6], ["a", "b", "a", "b"]))
421+
@test cat(t, t2; dims=1)::StructArray == vertical_concat == vcat(t, t2)
421422
@test vcat(t, t2) isa StructArray
422-
@test cat(t, t2; dims=2)::StructArray == StructArray{Pair}(([3 1; 5 6], ["a" "a"; "b" "b"])) == hcat(t, t2)
423+
horizontal_concat = StructArray{Pair{Int, String}}(([3 1; 5 6], ["a" "a"; "b" "b"]))
424+
@test cat(t, t2; dims=2)::StructArray == horizontal_concat == hcat(t, t2)
423425
@test hcat(t, t2) isa StructArray
424426
end
425427

0 commit comments

Comments
 (0)