-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_avg.py
71 lines (59 loc) · 2.33 KB
/
test_avg.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
import sys
if sys.version_info < (2, 7):
import unittest2 as unittest
else:
import unittest
from avg import simple_average, cumulative_average, windowed_average
class avgTest(unittest.TestCase):
elements = [1, 1, 2, 3, 5, 8, 13]
# def test_true(self):
# self.assertEquals(True, True)
# def test_state_not_persisted(self):
# gform = GForm('dG02c3hqdEZBaWZMN1NBdnBCZkVzdWc6MQ')
# self.assertIn('SmsSid', gform.labels)
# self.assertNotIn('One', gform.labels)
# gform = GForm('dHk3N2M5NlAtZV9mMlAyOEU5VE05dEE6MQ')
# self.assertNotIn('SmsSid', gform.labels)
# self.assertIn('One', gform.labels)
def test_simple_average(self):
average = simple_average()
rv = 0
for element in self.elements:
rv = average.calculate(element)
self.assertEquals(rv, 4.714285714285714)
def test_simple_average_has_count(self):
count = 10
average = simple_average()
for element in range(0,count):
average.calculate(element)
self.assertEquals(average.count, count)
def test_cumulative_average(self):
average = cumulative_average()
rv = 0
for element in self.elements:
rv = average.calculate(element)
self.assertEquals(rv, 4.714285714285714)
def test_cumulative_average_has_count(self):
count = 10
average = cumulative_average()
for element in range(0,count):
average.calculate(element)
self.assertEquals(average.count, count)
def test_windowed_average(self):
average = windowed_average(len(self.elements))
rv = 0
for element in self.elements:
rv = average.calculate(element)
self.assertEquals(rv, 4.714285714285714)
def test_windowed_average_has_count(self):
count = 10
average = windowed_average()
for element in range(0,count):
average.calculate(element)
self.assertEquals(average.count, count)
def test_windowed_average_uses_correct_length(self):
tests = [(1, 1), (1, 1), (4, 2), (6, 3.0), (1, 2.6), (3, 2.6666666666666665), (6, 3.142857142857143)]
average = windowed_average()
for (element, expected) in tests:
rv = average.calculate(element)
self.assertEquals(rv, expected)