-
Notifications
You must be signed in to change notification settings - Fork 0
/
zscore_test.py
92 lines (73 loc) · 3.13 KB
/
zscore_test.py
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import unittest
from zscore import ZscoreCalc
class ZscoreTest(unittest.TestCase):
# general test
def test_zscore(self):
zscore = ZscoreCalc()
raw_score = 6
population_mean = 4.4
standard_deviation = 2.2
expected_output = 0.7273
actual_output = ZscoreCalc.calc_zscore(zscore, raw_score, population_mean, standard_deviation)
self.assertEqual(expected_output, actual_output, 'General case failed')
# negative tests
def test_zscore2(self):
zscore = ZscoreCalc()
raw_score = -9.9
population_mean = 3.45
standard_deviation = 1.587
expected_output = -8.4121
actual_output = ZscoreCalc.calc_zscore(zscore, raw_score, population_mean, standard_deviation)
self.assertEqual(expected_output, actual_output, 'Negative test 1 failed')
def test_zscore3(self):
zscore = ZscoreCalc()
raw_score = 9.9
population_mean = -3.45
standard_deviation = 1.587
expected_output = 8.4121
actual_output = ZscoreCalc.calc_zscore(zscore, raw_score, population_mean, standard_deviation)
self.assertEqual(expected_output, actual_output, 'Negative test 2 failed')
def test_zscore4(self):
zscore = ZscoreCalc()
raw_score = -9.9
population_mean = -3.45
standard_deviation = 1.587
expected_output = -4.0643
actual_output = ZscoreCalc.calc_zscore(zscore, raw_score, population_mean, standard_deviation)
self.assertEqual(expected_output, actual_output, 'Negative test 3 failed')
# standard deviation conditional test
def test_zscore5(self):
zscore = ZscoreCalc()
raw_score = 9.9
population_mean = -3.45
standard_deviation = 0
expected_output = None
actual_output = ZscoreCalc.calc_zscore(zscore, raw_score, population_mean, standard_deviation)
self.assertEqual(expected_output, actual_output, 'Standard deviation conditional failed')
# nonsense input
def test_zscore6(self):
zscore = ZscoreCalc()
raw_score = 9.9
population_mean = -3.45
standard_deviation = 'crash bandicoot'
expected_output = None
actual_output = ZscoreCalc.calc_zscore(zscore, raw_score, population_mean, standard_deviation)
self.assertEqual(expected_output, actual_output, 'Input check failed')
# test calculating zscore from a list
def test_zscore7(self):
zscore = ZscoreCalc()
raw_score = 12.67
lst = [4, 7.4, 3.2, 6, 5.321, 8, 1]
expected_output = 3.1313
actual_output = ZscoreCalc.calc_zscore_from_list(zscore, raw_score, lst)
self.assertEqual(expected_output, actual_output, 'Zscore from list test failed')
# nonsense entered into calculate zscore from list test
def test_zscore8(self):
zscore = ZscoreCalc()
raw_score = 12.67
lst = 'rubber duck'
expected_output = None
actual_output = ZscoreCalc.calc_zscore_from_list(zscore, raw_score, lst)
self.assertEqual(expected_output, actual_output, 'Nonsense test failed')
if __name__ == '__main__':
unittest.main()