Exemplo n.º 1
0
class TestGaussianClass(unittest.TestCase):
    def setUp(self):
        self.gaussian = Gaussian(25, 2)
        self.gaussian.read_data_file('numbers.txt')

    def test_initialization(self):
        self.assertEqual(self.gaussian.mean, 25, 'incorrect mean')
        self.assertEqual(self.gaussian.stdev, 2,
                         'incorrect standard deviation')

    def test_readdata(self):
        self.assertEqual(self.gaussian.data,\
         [1, 3, 99, 100, 120, 32, 330, 23, 76, 44, 31], 'data not read in correctly')

    def test_meancalculation(self):
        self.assertEqual(self.gaussian.calculate_mean(),\
         sum(self.gaussian.data) / float(len(self.gaussian.data)), 'calculated mean not as expected')

    def test_stdevcalculation(self):
        self.assertEqual(round(self.gaussian.calculate_stdev(), 2), 92.87,
                         'sample standard deviation incorrect')
        self.assertEqual(round(self.gaussian.calculate_stdev(0), 2), 88.55,
                         'population standard deviation incorrect')

    def test_pdf(self):
        self.assertEqual(round(self.gaussian.pdf(25), 5), 0.19947,\
         'pdf function does not give expected result')
        self.gaussian.calculate_mean()
        self.gaussian.calculate_stdev()
        self.assertEqual(round(self.gaussian.pdf(75), 5), 0.00429,\
        'pdf function after calculating mean and stdev does not give expected result')

    def test_add(self):
        gaussian_one = Gaussian(25, 3)
        gaussian_two = Gaussian(30, 4)
        gaussian_sum = gaussian_one + gaussian_two

        self.assertEqual(gaussian_sum.mean, 55)
        self.assertEqual(gaussian_sum.stdev, 5)
Exemplo n.º 2
0
gaussian_three = gaussian_one + gaussian_two

print(gaussian_one.mean, gaussian_one.stdev)
print(gaussian_two.mean, gaussian_two.stdev)

print(gaussian_three.mean, gaussian_three.stdev)

print(gaussian_three)

#gaussian_three   need print command

gaussian_four = Gaussian()
gaussian_four.read_data_file('numbers.txt')
gaussian_four.calculate_mean()
gaussian_four.calculate_stdev()

gaussian_four.plot_histogram_pdf()

gaussian_four.plot_histogram()

gaussian_five = Gaussian(10, 5)
gaussian_five.plot_histogram()

print(gaussian_five)

gaussian_six = Gaussian()
gaussian_six.read_data_file('numbers2.txt')
gaussian_six.calculate_mean()
gaussian_six.calculate_stdev()
gaussian_six.plot_histogram_pdf()
Exemplo n.º 3
0
from Gaussiandistribution import Gaussian

gaussian_three = Gaussian()
gaussian_three.read_data_file('numbers.txt')

print(gaussian_three.calculate_stdev())
gaussian_three.plot_histogram_pdf()