Skip to content

Commit 51e60a9

Browse files
committed
move fill! tests to arraycommon
1 parent 4e96b83 commit 51e60a9

File tree

3 files changed

+55
-19
lines changed

3 files changed

+55
-19
lines changed

test/11_array.jl

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -136,14 +136,6 @@ using CategoricalArrays: DefaultRefType, catvaluetype, leveltype
136136
@test levels(x2) !== levels(x)
137137
@test isordered(x2) == isordered(x)
138138

139-
x2 = copy(x)
140-
@test fill!(x2, "a") === x2
141-
@test x2 == ["a", "a", "a"]
142-
@test levels(x2) == ["a", "b"]
143-
fill!(x2, "c")
144-
@test x2 == ["c", "c", "c"]
145-
@test levels(x2) == ["a", "b", "c"]
146-
147139
x[1] = x[2]
148140
@test x[1] === x.pool.valindex[2]
149141
@test x[2] === x.pool.valindex[2]

test/12_missingarray.jl

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -146,17 +146,6 @@ const ≅ = isequal
146146
@test levels(x2) !== levels(x)
147147
@test isordered(x2) == isordered(x)
148148

149-
x2 = copy(x)
150-
@test fill!(x2, "a") === x2
151-
@test x2 == ["a", "a", "a"]
152-
@test levels(x2) == ["a", "b"]
153-
fill!(x2, "c")
154-
@test x2 == ["c", "c", "c"]
155-
@test levels(x2) == ["a", "b", "c"]
156-
fill!(x2, missing)
157-
@test all(ismissing, x2)
158-
@test levels(x2) == ["a", "b", "c"]
159-
160149
x[1] = x[2]
161150
@test x[1] === x.pool.valindex[2]
162151
@test x[2] === x.pool.valindex[2]

test/13_arraycommon.jl

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,61 @@ end
427427
@test !isordered(x)
428428
end
429429

430+
@testset "fill!()" begin
431+
@testset "non-missing" begin
432+
x = categorical(["a", "b", "c"])
433+
x2 = copy(x)
434+
@test fill!(x2, "a") === x2
435+
@test x2 == ["a", "a", "a"]
436+
@test levels(x2) == ["a", "b", "c"]
437+
438+
@test fill!(x2, x[2]) == ["b", "b", "b"]
439+
@test levels(x2) == ["a", "b", "c"]
440+
441+
x2 = copy(x)
442+
@test_throws MethodError fill!(x2, missing)
443+
@test x2 == x
444+
@test_throws MethodError fill!(x2, 3)
445+
@test x2 == x
446+
447+
fill!(x2, :c)
448+
@test x2 == ["c", "c", "c"]
449+
@test levels(x2) == ["a", "b", "c"]
450+
451+
fill!(x2, "0")
452+
@test x2 == ["0", "0", "0"]
453+
@test levels(x2) == ["a", "b", "c", "0"]
454+
end
455+
456+
@testset "missing" begin
457+
x = categorical(Union{String, Missing}["a", "b", "c"])
458+
459+
x2 = copy(x)
460+
@test fill!(x2, "a") === x2
461+
@test x2 == ["a", "a", "a"]
462+
@test levels(x2) == ["a", "b", "c"]
463+
464+
@test fill!(x2, x[2]) == ["b", "b", "b"]
465+
@test levels(x2) == ["a", "b", "c"]
466+
467+
x2 = copy(x)
468+
fill!(x2, "0")
469+
@test x2 == ["0", "0", "0"]
470+
@test levels(x2) == ["a", "b", "c", "0"]
471+
472+
x2 = fill!(copy(x), missing)
473+
@test all(ismissing, x2)
474+
475+
x2 = copy(x)
476+
@test_throws MethodError fill!(x2, 3.0)
477+
@test x2 == x
478+
479+
fill!(x2, Symbol(1))
480+
@test x2 == ["1", "1", "1"]
481+
@test levels(x2) == ["a", "b", "c", "1"]
482+
end
483+
end
484+
430485
@testset "overflow of reftype is detected and doesn't corrupt data and levels" begin
431486
res = @test_throws LevelsException{Int, UInt8} CategoricalArray{Union{T, Int}, 1, UInt8}(256:-1:1)
432487
@test res.value.levels == [1]

0 commit comments

Comments
 (0)