Completed
Push — master ( f89968...a9e9bf )
by Xianshun
01:02
created

MeanSamplingDistributionUnitTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 47
Duplicated Lines 55.32 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
dl 26
loc 47
rs 10
c 2
b 0
f 0
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A test_confidence_interval_with_sample_stats_student() 0 8 1
A test_confidence_interval_with_sample_student() 13 13 2
A test_confidence_interval_with_sample_stats_normal() 0 8 1
A test_confidence_interval_with_sample_normal() 13 13 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 import normal
4
5
from pysie.stats.distributions import MeanSamplingDistribution, DistributionFamily
6
from pysie.stats.samples import Sample, SampleDistribution
7
8
9
class MeanSamplingDistributionUnitTest(unittest.TestCase):
10
11
    def test_confidence_interval_with_sample_stats_normal(self):
12
        sample_mean = 0
13
        sample_sd = 1
14
        sample_size = 31
15
        sampling_distribution = MeanSamplingDistribution(sample_mean=sample_mean, sample_sd=sample_sd, sample_size=sample_size)
16
        self.assertEqual(sampling_distribution.distribution_family, DistributionFamily.normal)
17
        print('sampling distribution: (point_estimate = ' + str(sampling_distribution.point_estimate) + ', standard_error=' + str(sampling_distribution.standard_error) + ')')
18
        print('confidence interval for 95% confidence level: ' + str(sampling_distribution.confidence_interval(0.95)))
19
20 View Code Duplication
    def test_confidence_interval_with_sample_normal(self):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
21
        mu = 0.0
22
        sigma = 1.0
23
        sample_size = 31
24
        sample = Sample()
25
26
        for i in range(sample_size):
27
            sample.add_numeric(normal(mu, sigma))
28
29
        sampling_distribution = MeanSamplingDistribution(sample_distribution=SampleDistribution(sample))
30
        self.assertEqual(sampling_distribution.distribution_family, DistributionFamily.normal)
31
        print('sampling distribution: (point_estimate = ' + str(sampling_distribution.point_estimate) + ', standard_error=' + str(sampling_distribution.standard_error) + ')')
32
        print('confidence interval for 95% confidence level: ' + str(sampling_distribution.confidence_interval(0.95)))
33
34
    def test_confidence_interval_with_sample_stats_student(self):
35
        sample_mean = 0
36
        sample_sd = 1
37
        sample_size = 29
38
        sampling_distribution = MeanSamplingDistribution(sample_mean=sample_mean, sample_sd=sample_sd, sample_size=sample_size)
39
        self.assertEqual(sampling_distribution.distribution_family, DistributionFamily.student_t)
40
        print('sampling distribution: (point_estimate = ' + str(sampling_distribution.point_estimate) + ', standard_error=' + str(sampling_distribution.standard_error) + ')')
41
        print('confidence interval for 95% confidence level: ' + str(sampling_distribution.confidence_interval(0.95)))
42
43 View Code Duplication
    def test_confidence_interval_with_sample_student(self):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
44
        mu = 0.0
45
        sigma = 1.0
46
        sample_size = 29
47
        sample = Sample()
48
49
        for i in range(sample_size):
50
            sample.add_numeric(normal(mu, sigma))
51
52
        sampling_distribution = MeanSamplingDistribution(sample_distribution=SampleDistribution(sample))
53
        self.assertEqual(sampling_distribution.distribution_family, DistributionFamily.student_t)
54
        print('sampling distribution: (point_estimate = ' + str(sampling_distribution.point_estimate) + ', standard_error=' + str(sampling_distribution.standard_error) + ')')
55
        print('confidence interval for 95% confidence level: ' + str(sampling_distribution.confidence_interval(0.95)))
56
57
if __name__ == '__main__':
58
    unittest.main()
59