Completed
Push — master ( 8a688c...c960ad )
by Xianshun
01:15
created

ContingencyTableUnitTest   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 17
rs 10
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A test_table() 0 16 1
1
import unittest
2
3
from numpy.random.mtrand import normal
4
5
from pysie.dsl.variable_independence_testing import Anova, ContingencyTable
6
from pysie.stats.samples import Sample
7
8
9
class AnovaUnitTest(unittest.TestCase):
10
    def test_anova(self):
11
        sample = Sample()
12
13
        mu1 = 1.0
14
        sigma1 = 1.0
15
16
        mu2 = 1.1
17
        sigma2 = 1.0
18
19
        mu3 = 1.09
20
        sigma3 = 1.0
21
22
        for i in range(100):
23
            sample.add_numeric(normal(mu1, sigma1), 'group1')
24
            sample.add_numeric(normal(mu2, sigma2), 'group2')
25
            sample.add_numeric(normal(mu3, sigma3), 'group3')
26
27
        testing = Anova(sample=sample)
28
29
        print('p-value: ' + str(testing.p_value))
30
        reject = testing.will_reject(0.01)
31
        print('will reject [same mean for all groups] ? ' + str(reject))
32
        self.assertFalse(reject)
33
34
35
class ContingencyTableUnitTest(unittest.TestCase):
36
    def test_table(self):
37
        table = ContingencyTable()
38
        table.set_cell('eventA', 'eventB', 10)
39
        table.set_cell('eventC', 'eventB', 20)
40
        table.set_cell('eventA', 'eventD', 15)
41
        table.set_cell('eventC', 'eventD', 10)
42
43
        print(table.get_column_total('eventB'))
44
        self.assertEqual(table.get_column_total('eventB'), 30)
45
        print(table.get_column_total('eventD'))
46
        self.assertEqual(table.get_column_total('eventD'), 25)
47
        print(table.get_row_total('eventA'))
48
        self.assertEqual(table.get_row_total('eventA'), 25)
49
        print(table.get_row_total('eventC'))
50
        self.assertEqual(table.get_row_total('eventC'), 30)
51
        self.assertEqual(table.get_total(), 55)
52
53
54
if __name__ == '__main__':
55
    unittest.main()
56