Skip to content

Commit

Permalink
Merge common parts of tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nalimilan committed Dec 1, 2017
1 parent 51e60a9 commit 53acb30
Showing 1 changed file with 21 additions and 45 deletions.
66 changes: 21 additions & 45 deletions test/13_arraycommon.jl
Expand Up @@ -428,58 +428,34 @@ end
end

@testset "fill!()" begin
@testset "non-missing" begin
x = categorical(["a", "b", "c"])
x2 = copy(x)
@test fill!(x2, "a") === x2
@test x2 == ["a", "a", "a"]
@test levels(x2) == ["a", "b", "c"]
x = CategoricalArray{Union{String, T}}(["a", "b", "c"])
x2 = copy(x)
@test fill!(x2, "a") === x2
@test x2 == ["a", "a", "a"]
@test levels(x2) == ["a", "b", "c"]

@test fill!(x2, x[2]) == ["b", "b", "b"]
@test levels(x2) == ["a", "b", "c"]
@test fill!(x2, x[2]) == ["b", "b", "b"]
@test levels(x2) == ["a", "b", "c"]

x2 = copy(x)
@test_throws MethodError fill!(x2, missing)
@test x2 == x
@test_throws MethodError fill!(x2, 3)
@test x2 == x

fill!(x2, :c)
@test x2 == ["c", "c", "c"]
@test levels(x2) == ["a", "b", "c"]

fill!(x2, "0")
@test x2 == ["0", "0", "0"]
@test levels(x2) == ["a", "b", "c", "0"]
end

@testset "missing" begin
x = categorical(Union{String, Missing}["a", "b", "c"])

x2 = copy(x)
@test fill!(x2, "a") === x2
@test x2 == ["a", "a", "a"]
@test levels(x2) == ["a", "b", "c"]

@test fill!(x2, x[2]) == ["b", "b", "b"]
@test levels(x2) == ["a", "b", "c"]

x2 = copy(x)
fill!(x2, "0")
@test x2 == ["0", "0", "0"]
@test levels(x2) == ["a", "b", "c", "0"]
x2 = copy(x)
@test_throws MethodError fill!(x2, 3)
@test x2 == x

if T === Missing
x2 = fill!(copy(x), missing)
@test all(ismissing, x2)

x2 = copy(x)
@test_throws MethodError fill!(x2, 3.0)
else
@test_throws MethodError fill!(x2, missing)
@test x2 == x

fill!(x2, Symbol(1))
@test x2 == ["1", "1", "1"]
@test levels(x2) == ["a", "b", "c", "1"]
end

fill!(x2, :c)
@test x2 == ["c", "c", "c"]
@test levels(x2) == ["a", "b", "c"]

fill!(x2, "0")
@test x2 == ["0", "0", "0"]
@test levels(x2) == ["a", "b", "c", "0"]
end

@testset "overflow of reftype is detected and doesn't corrupt data and levels" begin
Expand Down

0 comments on commit 53acb30

Please sign in to comment.