1
1
# Test methods with long descriptive names can omit docstrings
2
2
# pylint: disable=missing-docstring
3
+ import unittest
3
4
5
+ import numpy .testing
4
6
import numpy as np
5
7
from AnyQt .QtCore import QItemSelectionModel
6
8
from AnyQt .QtTest import QTest
7
9
8
10
from Orange .data import Table , ContinuousVariable , StringVariable , Domain
9
- from Orange .widgets .visualize .owboxplot import OWBoxPlot , FilterGraphicsRectItem
11
+ from Orange .widgets .visualize .owboxplot import (
12
+ OWBoxPlot , FilterGraphicsRectItem , _quantiles
13
+ )
10
14
from Orange .widgets .tests .base import WidgetTest , WidgetOutputsTestMixin
11
15
12
16
@@ -208,3 +212,40 @@ def __select_value(self, list, value):
208
212
if m .data (idx ) == value :
209
213
list .selectionModel ().setCurrentIndex (
210
214
idx , QItemSelectionModel .ClearAndSelect )
215
+
216
+
217
+ class TestUtils (unittest .TestCase ):
218
+ def test (self ):
219
+ np .testing .assert_array_equal (
220
+ _quantiles (range (1 , 8 + 1 ), [1. ] * 8 , [0.0 , 0.25 , 0.5 , 0.75 , 1.0 ]),
221
+ [1. , 2.5 , 4.5 , 6.5 , 8. ]
222
+ )
223
+ np .testing .assert_array_equal (
224
+ _quantiles (range (1 , 8 + 1 ), [1. ] * 8 , [0.0 , 0.25 , 0.5 , 0.75 , 1.0 ]),
225
+ [1. , 2.5 , 4.5 , 6.5 , 8. ]
226
+ )
227
+ np .testing .assert_array_equal (
228
+ _quantiles (range (1 , 4 + 1 ), [1. , 2. , 1. , 2 ],
229
+ [0.0 , 0.25 , 0.5 , 0.75 , 1.0 ]),
230
+ [1.0 , 2.0 , 2.5 , 4.0 , 4.0 ]
231
+ )
232
+ np .testing .assert_array_equal (
233
+ _quantiles (range (1 , 4 + 1 ), [2. , 1. , 1. , 2. ],
234
+ [0.0 , 0.25 , 0.5 , 0.75 , 1.0 ]),
235
+ [1.0 , 1.0 , 2.5 , 4.0 , 4.0 ]
236
+ )
237
+ np .testing .assert_array_equal (
238
+ _quantiles (range (1 , 4 + 1 ), [1. , 1. , 1. , 1. ],
239
+ [0.0 , 0.25 , 0.5 , 0.75 , 1.0 ]),
240
+ [1.0 , 1.5 , 2.5 , 3.5 , 4.0 ]
241
+ )
242
+ np .testing .assert_array_equal (
243
+ _quantiles (range (1 , 4 + 1 ), [1. , 1. , 1. , 1. ],
244
+ [0.0 , 0.25 , 0.5 , 0.75 , 1.0 ], interpolation = "higher" ),
245
+ [1 , 2 , 3 , 4 , 4 ]
246
+ )
247
+ np .testing .assert_array_equal (
248
+ _quantiles (range (1 , 4 + 1 ), [1. , 1. , 1. , 1. ],
249
+ [0.0 , 0.25 , 0.5 , 0.75 , 1.0 ], interpolation = "lower" ),
250
+ [1 , 1 , 2 , 3 , 4 ]
251
+ )
0 commit comments