|
|
|
@ -22,7 +22,7 @@ from pygal import Box as ghostedBox
|
|
|
|
|
|
|
|
|
|
def test_quartiles(): |
|
|
|
|
a = [-2.0, 3.0, 4.0, 5.0, 8.0] # odd test data |
|
|
|
|
q0, q1, q2, q3, q4 = Box._box_points(a) |
|
|
|
|
(min_s, q0, q1, q2, q3, q4, max_s), outliers = Box._box_points(a) |
|
|
|
|
|
|
|
|
|
assert q1 == 7.0 / 4.0 |
|
|
|
|
assert q2 == 4.0 |
|
|
|
@ -31,17 +31,17 @@ def test_quartiles():
|
|
|
|
|
assert q4 == 23 / 4.0 + 6.0 # q3 + 1.5 * iqr |
|
|
|
|
|
|
|
|
|
b = [1.0, 4.0, 6.0, 8.0] # even test data |
|
|
|
|
q0, q1, q2, q3, q4 = Box._box_points(b) |
|
|
|
|
(min_s, q0, q1, q2, q3, q4, max_s), outliers = Box._box_points(b) |
|
|
|
|
|
|
|
|
|
assert q2 == 5.0 |
|
|
|
|
|
|
|
|
|
c = [2.0, None, 4.0, 6.0, None] # odd with None elements |
|
|
|
|
q0, q1, q2, q3, q4 = Box._box_points(c) |
|
|
|
|
(min_s, q0, q1, q2, q3, q4, max_s), outliers = Box._box_points(c) |
|
|
|
|
|
|
|
|
|
assert q2 == 4.0 |
|
|
|
|
|
|
|
|
|
d = [4] |
|
|
|
|
q0, q1, q2, q3, q4 = Box._box_points(d) |
|
|
|
|
(min_s, q0, q1, q2, q3, q4, max_s), outliers = Box._box_points(d) |
|
|
|
|
|
|
|
|
|
assert q0 == 4 |
|
|
|
|
assert q1 == 4 |
|
|
|
@ -49,9 +49,11 @@ def test_quartiles():
|
|
|
|
|
assert q3 == 4 |
|
|
|
|
assert q4 == 4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_quartiles_min_extremes(): |
|
|
|
|
a = [-2.0, 3.0, 4.0, 5.0, 8.0] # odd test data |
|
|
|
|
q0, q1, q2, q3, q4 = Box._box_points(a, mode='extremes') |
|
|
|
|
(min_s, q0, q1, q2, q3, q4, max_s), outliers = Box._box_points( |
|
|
|
|
a, mode='extremes') |
|
|
|
|
|
|
|
|
|
assert q1 == 7.0 / 4.0 |
|
|
|
|
assert q2 == 4.0 |
|
|
|
@ -60,17 +62,20 @@ def test_quartiles_min_extremes():
|
|
|
|
|
assert q4 == 8.0 # max |
|
|
|
|
|
|
|
|
|
b = [1.0, 4.0, 6.0, 8.0] # even test data |
|
|
|
|
q0, q1, q2, q3, q4 = Box._box_points(b, mode='extremes') |
|
|
|
|
(min_s, q0, q1, q2, q3, q4, max_s), outliers = Box._box_points( |
|
|
|
|
b, mode='extremes') |
|
|
|
|
|
|
|
|
|
assert q2 == 5.0 |
|
|
|
|
|
|
|
|
|
c = [2.0, None, 4.0, 6.0, None] # odd with None elements |
|
|
|
|
q0, q1, q2, q3, q4 = Box._box_points(c, mode='extremes') |
|
|
|
|
(min_s, q0, q1, q2, q3, q4, max_s), outliers = Box._box_points( |
|
|
|
|
c, mode='extremes') |
|
|
|
|
|
|
|
|
|
assert q2 == 4.0 |
|
|
|
|
|
|
|
|
|
d = [4] |
|
|
|
|
q0, q1, q2, q3, q4 = Box._box_points(d, mode='extremes') |
|
|
|
|
(min_s, q0, q1, q2, q3, q4, max_s), outliers = Box._box_points( |
|
|
|
|
d, mode='extremes') |
|
|
|
|
|
|
|
|
|
assert q0 == 4 |
|
|
|
|
assert q1 == 4 |
|
|
|
@ -79,6 +84,48 @@ def test_quartiles_min_extremes():
|
|
|
|
|
assert q4 == 4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_quartiles_tukey(): |
|
|
|
|
a = [] # empty data |
|
|
|
|
(min_s, q0, q1, q2, q3, q4, max_s), outliers = Box._box_points( |
|
|
|
|
a, mode='tukey') |
|
|
|
|
assert min_s == q0 == q1 == q2 == q3 == q4 == 0 |
|
|
|
|
assert outliers == [] |
|
|
|
|
|
|
|
|
|
# https://en.wikipedia.org/wiki/Quartile example 1 |
|
|
|
|
b = [6, 7, 15, 36, 39, 40, 41, 42, 43, 47, 49] |
|
|
|
|
(min_s, q0, q1, q2, q3, q4, max_s), outliers = Box._box_points( |
|
|
|
|
b, mode='tukey') |
|
|
|
|
assert min_s == q0 == 6 |
|
|
|
|
assert q1 == 20.25 |
|
|
|
|
assert q2 == 40 |
|
|
|
|
assert q3 == 42.75 |
|
|
|
|
assert max_s == q4 == 49 |
|
|
|
|
assert outliers == [] |
|
|
|
|
|
|
|
|
|
# previous test with added outlier 75 |
|
|
|
|
c = [6, 7, 15, 36, 39, 40, 41, 42, 43, 47, 49, 75] |
|
|
|
|
(min_s, q0, q1, q2, q3, q4, max_s), outliers = Box._box_points( |
|
|
|
|
c, mode='tukey') |
|
|
|
|
assert min_s == q0 == 6 |
|
|
|
|
assert q1 == 25.5 |
|
|
|
|
assert q2 == (40 + 41) / 2.0 |
|
|
|
|
assert q3 == 45 |
|
|
|
|
assert max_s == 75 |
|
|
|
|
assert outliers == [75] |
|
|
|
|
|
|
|
|
|
# one more outlier, -30 |
|
|
|
|
c = [6, 7, 15, 36, 39, 40, 41, 42, 43, 47, 49, 75, 77] |
|
|
|
|
(min_s, q0, q1, q2, q3, q4, max_s), outliers = Box._box_points( |
|
|
|
|
c, mode='tukey') |
|
|
|
|
assert min_s == q0 == 6 |
|
|
|
|
assert q1 == 30.75 |
|
|
|
|
assert q2 == 41 |
|
|
|
|
assert q3 == 47.5 |
|
|
|
|
assert max_s == 77 |
|
|
|
|
assert 75 in outliers |
|
|
|
|
assert 77 in outliers |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_simple_box(): |
|
|
|
|
box = ghostedBox() |
|
|
|
|
box.add('test1', [-1, 2, 3, 3.1, 3.2, 4, 5]) |
|
|
|
|