How to use _box_points method in pytest-benchmark

Best Python code snippet using pytest-benchmark

test_box.py

Source:test_box.py Github

copy

Full Screen

...20from pygal.graph.box import Box21def test_quartiles():22 """Test box points for the 1.5IQR computation method"""23 a = [-2.0, 3.0, 4.0, 5.0, 8.0] # odd test data24 (min_s, q0, q1, q2, q3, q4, max_s), outliers = Box._box_points(25 a, mode='1.5IQR')26 assert q1 == 7.0 / 4.027 assert q2 == 4.028 assert q3 == 23 / 4.029 assert q0 == 7.0 / 4.0 - 6.0 # q1 - 1.5 * iqr30 assert q4 == 23 / 4.0 + 6.0 # q3 + 1.5 * iqr31 b = [1.0, 4.0, 6.0, 8.0] # even test data32 (min_s, q0, q1, q2, q3, q4, max_s), outliers = Box._box_points(33 b, mode='1.5IQR')34 assert q2 == 5.035 c = [2.0, None, 4.0, 6.0, None] # odd with None elements36 (min_s, q0, q1, q2, q3, q4, max_s), outliers = Box._box_points(37 c, mode='1.5IQR')38 assert q2 == 4.039 d = [4]40 (min_s, q0, q1, q2, q3, q4, max_s), outliers = Box._box_points(41 d, mode='1.5IQR')42 assert q0 == 443 assert q1 == 444 assert q2 == 445 assert q3 == 446 assert q4 == 447def test_quartiles_min_extremes():48 """Test box points for the extremes computation method"""49 a = [-2.0, 3.0, 4.0, 5.0, 8.0] # odd test data50 (min_s, q0, q1, q2, q3, q4, max_s), outliers = Box._box_points(51 a, mode='extremes')52 assert q1 == 7.0 / 4.053 assert q2 == 4.054 assert q3 == 23 / 4.055 assert q0 == -2.0 # min56 assert q4 == 8.0 # max57 b = [1.0, 4.0, 6.0, 8.0] # even test data58 (min_s, q0, q1, q2, q3, q4, max_s), outliers = Box._box_points(59 b, mode='extremes')60 assert q2 == 5.061 c = [2.0, None, 4.0, 6.0, None] # odd with None elements62 (min_s, q0, q1, q2, q3, q4, max_s), outliers = Box._box_points(63 c, mode='extremes')64 assert q2 == 4.065 d = [4]66 (min_s, q0, q1, q2, q3, q4, max_s), outliers = Box._box_points(67 d, mode='extremes')68 assert q0 == 469 assert q1 == 470 assert q2 == 471 assert q3 == 472 assert q4 == 473def test_quartiles_tukey():74 """Test box points for the tukey computation method"""75 a = [] # empty data76 (min_s, q0, q1, q2, q3, q4, max_s), outliers = Box._box_points(77 a, mode='tukey')78 assert min_s == q0 == q1 == q2 == q3 == q4 == 079 assert outliers == []80 # https://en.wikipedia.org/wiki/Quartile example 181 b = [6, 7, 15, 36, 39, 40, 41, 42, 43, 47, 49]82 (min_s, q0, q1, q2, q3, q4, max_s), outliers = Box._box_points(83 b, mode='tukey')84 assert min_s == q0 == 685 assert q1 == 20.2586 assert q2 == 4087 assert q3 == 42.7588 assert max_s == q4 == 4989 assert outliers == []90 # previous test with added outlier 7591 c = [6, 7, 15, 36, 39, 40, 41, 42, 43, 47, 49, 75]92 (min_s, q0, q1, q2, q3, q4, max_s), outliers = Box._box_points(93 c, mode='tukey')94 assert min_s == q0 == 695 assert q1 == 25.596 assert q2 == (40 + 41) / 2.097 assert q3 == 4598 assert max_s == 7599 assert outliers == [75]100 # one more outlier, 77101 c = [6, 7, 15, 36, 39, 40, 41, 42, 43, 47, 49, 75, 77]102 (min_s, q0, q1, q2, q3, q4, max_s), outliers = Box._box_points(103 c, mode='tukey')104 assert min_s == q0 == 6105 assert q1 == 30.75106 assert q2 == 41107 assert q3 == 47.5108 assert max_s == 77109 assert 75 in outliers110 assert 77 in outliers111def test_quartiles_stdev():112 """Test box points for the stdev computation method"""113 a = [35, 42, 35, 41, 36, 6, 12, 51, 33, 27, 46, 36, 44, 53, 75, 46, 16,114 51, 45, 29, 25, 26, 54, 61, 27, 40, 23, 34, 51, 37]115 SD = 14.67116 (min_s, q0, q1, q2, q3, q4, max_s), outliers = Box._box_points(117 a, mode='stdev')118 assert min_s == min(a)119 assert max_s == max(a)120 assert q2 == 36.5121 assert q4 <= q2 + SD122 assert q0 >= q2 - SD123 assert all(n in outliers for n in [6, 12, 16, 53, 54, 61, 75])124 b = [5] # test for posible zero division125 (min_s, q0, q1, q2, q3, q4, max_s), outliers = Box._box_points(126 b, mode='stdev')127 assert min_s == q0 == q1 == q2 == q3 == q4 == max_s == b[0]128 assert outliers == []129def test_simple_box():130 """Simple box test"""131 box = Box()132 box.add('test1', [-1, 2, 3, 3.1, 3.2, 4, 5])133 box.add('test2', [2, 3, 5, 6, 6, 4])134 box.title = 'Box test'135 q = box.render_pyquery()136 assert len(q(".axis.y")) == 1137 assert len(q(".legend")) == 2...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run pytest-benchmark automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful