Completed
Push — master ( f964b6...b7c711 )
by Xianshun
01:02
created

MeanTestingUnitTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 41
Duplicated Lines 92.68 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 38
loc 41
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A test_mean_normal() 19 19 2
A test_mean_student() 19 19 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
import unittest
2
3
from numpy.random.mtrand import normal
4
5
from pysie.dsl.one_group import MeanTesting
6
from pysie.stats.distributions import MeanSamplingDistribution
7
from pysie.stats.samples import Sample, SampleDistribution
8
9
10
11
12
class MeanTestingUnitTest(unittest.TestCase):
13
14 View Code Duplication
    def test_mean_normal(self):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
15
        mu = 0.0
16
        sigma = 1.0
17
        sample_size = 31
18
        sample = Sample()
19
20
        for i in range(sample_size):
21
            sample.add_numeric(normal(mu, sigma))
22
23
        sampling_distribution = MeanSamplingDistribution(sample_distribution=SampleDistribution(sample))
24
        testing = MeanTesting(sampling_distribution=sampling_distribution, mean_null=0.0)
25
26
        print('one tail p-value: ' + str(testing.p_value_one_tail))
27
        print('two tail p-value: ' + str(testing.p_value_two_tail))
28
        reject_one_tail, reject_two_tail = testing.will_reject(0.01)
29
        print('will reject mean = 0 (one-tail) ? ' + str(reject_one_tail))
30
        print('will reject mean = 0 (two-tail) ? ' + str(reject_two_tail))
31
        self.assertFalse(reject_one_tail)
32
        self.assertFalse(reject_two_tail)
33
34 View Code Duplication
    def test_mean_student(self):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
35
        mu = 0.0
36
        sigma = 1.0
37
        sample_size = 29
38
        sample = Sample()
39
40
        for i in range(sample_size):
41
            sample.add_numeric(normal(mu, sigma))
42
43
        sampling_distribution = MeanSamplingDistribution(sample_distribution=SampleDistribution(sample))
44
        testing = MeanTesting(sampling_distribution=sampling_distribution, mean_null=0.0)
45
46
        print('one tail p-value: ' + str(testing.p_value_one_tail))
47
        print('two tail p-value: ' + str(testing.p_value_two_tail))
48
        reject_one_tail, reject_two_tail = testing.will_reject(0.01)
49
        print('will reject mean = 0 (one-tail) ? ' + str(reject_one_tail))
50
        print('will reject mean = 0 (two-tail) ? ' + str(reject_two_tail))
51
        self.assertFalse(reject_one_tail)
52
        self.assertFalse(reject_two_tail)
53
54
if __name__ == '__main__':
55
    unittest.main()
56