aboutsummaryrefslogtreecommitdiff
path: root/wqflask/tests/unit/utility/test_corestats.py
blob: cf91a248fe4a5bb38d2c7e3c90b0cd9a3d6b045f (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
"""Test Core Stats"""

import unittest

from utility.corestats import Stats


class TestChunks(unittest.TestCase):
    "Test Utility method for chunking"

    def setUp(self):
        self.stat_test = Stats((x for x in range(1, 11)))

    def test_stats_sum(self):
        """ Test sequence sum """
        self.assertEqual(self.stat_test.sum(), 55)
        self.stat_test = Stats([])
        self.assertEqual(self.stat_test.sum(), None)

    def test_stats_count(self):
        """ Test sequence count """
        self.assertEqual(self.stat_test.count(), 10)
        self.stat_test = Stats([])
        self.assertEqual(self.stat_test.count(), 0)

    def test_stats_min(self):
        """ Test min value in sequence"""
        self.assertEqual(self.stat_test.min(), 1)
        self.stat_test = Stats([])
        self.assertEqual(self.stat_test.min(), None)

    def test_stats_max(self):
        """ Test max value in sequence """
        self.assertEqual(self.stat_test.max(), 10)
        self.stat_test = Stats([])
        self.assertEqual(self.stat_test.max(), None)

    def test_stats_avg(self):
        """ Test avg of sequence """
        self.assertEqual(self.stat_test.avg(), 5.5)
        self.stat_test = Stats([])
        self.assertEqual(self.stat_test.avg(), None)

    def test_stats_stdev(self):
        """ Test standard deviation of sequence """
        self.assertEqual(self.stat_test.stdev(), 3.0276503540974917)
        self.stat_test = Stats([])
        self.assertEqual(self.stat_test.stdev(), None)

    def test_stats_percentile(self):
        """ Test percentile of sequence """
        self.assertEqual(self.stat_test.percentile(20), 3.0)
        self.assertEqual(self.stat_test.percentile(101), None)
        self.stat_test = Stats([])
        self.assertEqual(self.stat_test.percentile(20), None)