@@ -16,6 +16,7 @@ using CategoricalArrays: DefaultRefType, leveltype
1616 @test isordered (x) === ordered
1717 @test levels (x) == sort (unique (a))
1818 @test unique (x) == unique (a)
19+ @test typeof (unique (x)) === typeof (x)
1920 @test size (x) === (3 ,)
2021 @test length (x) === 3
2122
@@ -272,6 +273,7 @@ using CategoricalArrays: DefaultRefType, leveltype
272273 @test x == collect (a)
273274 @test isordered (x) === ordered
274275 @test levels (x) == unique (x) == unique (a)
276+ @test typeof (unique (x)) === typeof (x)
275277 @test size (x) === (4 ,)
276278 @test length (x) === 4
277279 @test leveltype (x) === Float64
@@ -437,6 +439,7 @@ using CategoricalArrays: DefaultRefType, leveltype
437439 @test x[4 ] === CategoricalValue (x. pool, 4 )
438440 @test levels (x) == unique (a)
439441 @test unique (x) == unique (collect (x))
442+ @test typeof (unique (x)) === typeof (x)
440443
441444 x[1 : 2 ] .= - 1
442445 @test x[1 ] === CategoricalValue (x. pool, 5 )
@@ -473,6 +476,7 @@ using CategoricalArrays: DefaultRefType, leveltype
473476 @test x == a
474477 @test isordered (x) === ordered
475478 @test levels (x) == unique (x) == unique (a)
479+ @test unique (x) isa CategoricalVector{String, R}
476480 @test size (x) === (2 , 3 )
477481 @test length (x) === 6
478482
@@ -729,27 +733,42 @@ end
729733 @test levels! (x, [" Young" , " Middle" , " Old" ]) === x
730734 @test levels (x) == [" Young" , " Middle" , " Old" ]
731735 @test unique (x) == [" Old" , " Young" , " Middle" ]
736+ @test typeof (unique (x)) === typeof (x)
732737 @test levels! (x, [" Young" , " Middle" , " Old" , " Unused" ]) === x
733738 @test levels (x) == [" Young" , " Middle" , " Old" , " Unused" ]
734739 @test unique (x) == [" Old" , " Young" , " Middle" ]
735740 @test levels! (x, [" Unused1" , " Young" , " Middle" , " Old" , " Unused2" ]) === x
736741 @test levels (x) == [" Unused1" , " Young" , " Middle" , " Old" , " Unused2" ]
737742 @test unique (x) == [" Old" , " Young" , " Middle" ]
738743
744+ y = copy (x)
745+ @test unique! (y) === y
746+ @test y == unique (x)
747+
739748 x = CategoricalArray (String[])
740749 @test isa (levels (x), Vector{String}) && isempty (levels (x))
741- @test isa (unique (x), Vector{String} ) && isempty (unique (x))
750+ @test isa (unique (x), typeof (x) ) && isempty (unique (x))
742751 @test levels! (x, [" Young" , " Middle" , " Old" ]) === x
743752 @test levels (x) == [" Young" , " Middle" , " Old" ]
744- @test isa (unique (x), Vector{String}) && isempty (unique (x))
753+ @test isa (unique (x), typeof (x)) && isempty (unique (x))
754+
755+ y = copy (x)
756+ @test unique! (y) === y
757+ @test y == unique (x)
745758
746759 # To test short-circuiting
747760 x = CategoricalArray (repeat (1 : 10 , inner= 10 ))
748761 @test levels (x) == collect (1 : 10 )
749762 @test unique (x) == collect (1 : 10 )
763+ @test unique (x) isa typeof (x)
750764 @test levels! (x, [19 : - 1 : 1 ; 20 ]) === x
751765 @test levels (x) == [19 : - 1 : 1 ; 20 ]
752766 @test unique (x) == collect (1 : 10 )
767+ @test unique (x) isa typeof (x)
768+
769+ y = copy (x)
770+ @test unique! (y) === y
771+ @test y == 1 : 10
753772end
754773
755774end
0 commit comments