forked from itsmemattchung/interviewcake
-
Notifications
You must be signed in to change notification settings - Fork 0
/
exercise_7.py
65 lines (46 loc) · 1.74 KB
/
exercise_7.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
#!/usr/bin/env python
from collections import Counter
import unittest
class TempTracker:
def __init__(self):
self.temperatures = []
def insert(self, temperature):
self.temperatures.append(float(temperature))
return self.temperatures
def get_max(self):
return max(self.temperatures)
def get_min(self):
return min(self.temperatures)
def get_mean(self):
return sum(self.temperatures) / len(self.temperatures)
def get_mode(self):
counter = Counter(self.temperatures)
return counter.most_common(1)[0][0]
return counter
class TestTempTracker(unittest.TestCase):
def setUp(self):
self.temp_tracker = TempTracker()
def test_insert(self):
self.assertEquals(self.temp_tracker.insert(99), [99])
self.assertEquals(self.temp_tracker.insert(80), [99,80])
def test_get_max(self):
self.temp_tracker.temperatures = [0,100,50,99,-55]
self.assertEquals(self.temp_tracker.get_max(), 100)
def test_get_min(self):
self.temp_tracker.temperatures = [0,100,50,99,-55]
self.assertEquals(self.temp_tracker.get_min(), -55)
def test_get_mean(self):
self.temp_tracker.insert(0)
self.temp_tracker.insert(100)
self.temp_tracker.insert(50)
self.temp_tracker.insert(99)
self.temp_tracker.insert(-55)
self.assertEquals(self.temp_tracker.get_mean(), 38.8)
def test_get_mode(self):
self.temp_tracker.insert(0)
self.temp_tracker.insert(100)
self.temp_tracker.insert(50)
self.temp_tracker.insert(99)
self.temp_tracker.insert(-55)
self.temp_tracker.insert(99)
self.assertEquals(self.temp_tracker.get_mode(), 99.0)