@@ -127,18 +127,18 @@ end
127
127
128
128
@testset " cut([5, 4, 3, 2], 2)" begin
129
129
x = @inferred cut ([5 , 4 , 3 , 2 ], 2 )
130
- @test x == [" Q2: [3.5 , 5.0 ]" , " Q2: [3.5 , 5.0 ]" , " Q1: [2.0, 3.5 )" , " Q1: [2.0, 3.5 )" ]
130
+ @test x == [" Q2: [4 , 5]" , " Q2: [4 , 5]" , " Q1: [2, 4 )" , " Q1: [2, 4 )" ]
131
131
@test isa (x, CategoricalArray)
132
132
@test isordered (x)
133
- @test levels (x) == [" Q1: [2.0, 3.5 )" , " Q2: [3.5 , 5.0 ]" ]
133
+ @test levels (x) == [" Q1: [2, 4 )" , " Q2: [4 , 5]" ]
134
134
end
135
135
136
136
@testset " cut(x, n) with missing values" begin
137
137
x = @inferred cut ([5 , 4 , 3 , missing , 2 ], 2 )
138
- @test x ≅ [" Q2: [3.5 , 5.0 ]" , " Q2: [3.5 , 5.0 ]" , " Q1: [2.0, 3.5 )" , missing , " Q1: [2.0, 3.5 )" ]
138
+ @test x ≅ [" Q2: [4 , 5]" , " Q2: [4 , 5]" , " Q1: [2, 4 )" , missing , " Q1: [2, 4 )" ]
139
139
@test isa (x, CategoricalArray)
140
140
@test isordered (x)
141
- @test levels (x) == [" Q1: [2.0, 3.5 )" , " Q2: [3.5 , 5.0 ]" ]
141
+ @test levels (x) == [" Q1: [2, 4 )" , " Q2: [4 , 5]" ]
142
142
end
143
143
144
144
@testset " cut(x, n) with invalid n" begin
@@ -255,20 +255,29 @@ end
255
255
@test_throws ArgumentError cut (1 : 8 , 0 : 2 : 10 , labels= fmt)
256
256
257
257
@test_throws ArgumentError cut ([fill (1 , 10 ); 4 ], 2 )
258
- @test_throws ArgumentError cut ([fill (1 , 10 ); 4 ], 3 )
259
258
x = cut ([fill (1 , 10 ); 4 ], 2 , allowempty= true )
260
- @test unique (x) == [" Q2: [1.0, 4.0]" ]
259
+ @test unique (x) == [" Q2: [1, 4]" ]
260
+ @test levels (x) == [" Q1: (1, 1)" , " Q2: [1, 4]" ]
261
+ @test_throws ArgumentError cut ([fill (1 , 10 ); 4 ], 3 )
261
262
x = cut ([fill (1 , 10 ); 4 ], 3 , allowempty= true )
262
- @test unique (x) == [" Q3: [1.0, 4.0]" ]
263
- @test levels (x) == [" Q1: (1.0, 1.0)" , " Q2: (1.0, 1.0)" , " Q3: [1.0, 4.0]" ]
263
+ @test unique (x) == [" Q3: [1, 4]" ]
264
+ @test levels (x) == [" Q1: (1, 1)" , " Q2: (1, 1)" , " Q3: [1, 4]" ]
265
+
266
+ x = cut ([fill (4 , 10 ); 1 ], 2 )
267
+ @test x == [fill (" Q2: [4, 4]" , 10 ); " Q1: [1, 4)" ]
268
+ @test levels (x) == [" Q1: [1, 4)" ; " Q2: [4, 4]" ]
269
+ @test_throws ArgumentError cut ([fill (4 , 10 ); 1 ], 3 )
270
+ x = cut ([fill (4 , 10 ); 1 ], 3 , allowempty= true )
271
+ @test x == [fill (" Q3: [4, 4]" , 10 ); " Q1: [1, 4)" ]
272
+ @test levels (x) == [" Q1: [1, 4)" , " Q2: (4, 4)" , " Q3: [4, 4]" ]
264
273
265
274
x = cut ([fill (1 , 5 ); fill (4 , 5 )], 2 )
266
- @test x == [fill (" Q1: [1.0, 2.5 )" , 5 ); fill (" Q2: [2.5 , 4.0 ]" , 5 )]
267
- @test levels (x) == [" Q1: [1.0, 2.5 )" , " Q2: [2.5 , 4.0 ]" ]
275
+ @test x == [fill (" Q1: [1, 4 )" , 5 ); fill (" Q2: [4 , 4]" , 5 )]
276
+ @test levels (x) == [" Q1: [1, 4 )" , " Q2: [4 , 4]" ]
268
277
@test_throws ArgumentError cut ([fill (1 , 5 ); fill (4 , 5 )], 3 )
269
278
x = cut ([fill (1 , 5 ); fill (4 , 5 )], 3 , allowempty= true )
270
- @test x == [fill (" Q2: [1.0 , 4.0 )" , 5 ); fill (" Q3: [4.0 , 4.0 ]" , 5 )]
271
- @test levels (x) == [" Q1: (1.0 , 1.0 )" , " Q2: [1.0 , 4.0 )" , " Q3: [4.0 , 4.0 ]" ]
279
+ @test x == [fill (" Q2: [1, 4)" , 5 ); fill (" Q3: [4, 4]" , 5 )]
280
+ @test levels (x) == [" Q1: (1, 1)" , " Q2: [1, 4)" , " Q3: [4, 4]" ]
272
281
end
273
282
274
283
@testset " cut with -0.0" begin
@@ -353,12 +362,21 @@ end
353
362
@test levels (x) == [" [-Inf, 2.0)" , " [2.0, 5.0]" ]
354
363
355
364
x = cut ([1 : 5 ; Inf ], 2 )
356
- @test x ≅ [fill (" Q1: [1.0, 3.5 )" , 3 ); fill (" Q2: [3.5 , Inf]" , 3 )]
357
- @test levels (x) == [" Q1: [1.0, 3.5 )" , " Q2: [3.5 , Inf]" ]
365
+ @test x ≅ [fill (" Q1: [1.0, 4.0 )" , 3 ); fill (" Q2: [4.0 , Inf]" , 3 )]
366
+ @test levels (x) == [" Q1: [1.0, 4.0 )" , " Q2: [4.0 , Inf]" ]
358
367
359
368
x = cut ([1 : 5 ; - Inf ], 2 )
360
- @test x ≅ [fill (" Q1: [-Inf, 2.5)" , 2 ); fill (" Q2: [2.5, 5.0]" , 3 ); " Q1: [-Inf, 2.5)" ]
361
- @test levels (x) == [" Q1: [-Inf, 2.5)" , " Q2: [2.5, 5.0]" ]
369
+ @test x ≅ [fill (" Q1: [-Inf, 3.0)" , 2 ); fill (" Q2: [3.0, 5.0]" , 3 ); " Q1: [-Inf, 3.0)" ]
370
+ @test levels (x) == [" Q1: [-Inf, 3.0)" , " Q2: [3.0, 5.0]" ]
371
+ end
372
+
373
+ @testset " cut when quantile falls exactly on a data value" begin
374
+ x = cut ([11 , 14 , 43 , 54 , 54 , 56 , 73 , 79 , 84 , 84 ], 3 )
375
+ @test x ==
376
+ [" Q1: [11, 54)" , " Q1: [11, 54)" , " Q1: [11, 54)" ,
377
+ " Q2: [54, 73)" , " Q2: [54, 73)" , " Q2: [54, 73)" ,
378
+ " Q3: [73, 84]" , " Q3: [73, 84]" , " Q3: [73, 84]" , " Q3: [73, 84]" ]
379
+ @test levels (x) == [" Q1: [11, 54)" , " Q2: [54, 73)" , " Q3: [73, 84]" ]
362
380
end
363
381
364
382
end
0 commit comments