forked from faif/python-patterns
-
Notifications
You must be signed in to change notification settings - Fork 11
/
test_state.py
63 lines (51 loc) · 1.96 KB
/
test_state.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
#!/usr/bin/env python
from state import Radio
import sys
if sys.version_info < (2, 7):
import unittest2 as unittest
else:
import unittest
class RadioTest(unittest.TestCase):
"""
Attention: Test case results depend on test case execution. The test cases
in this integration test class should be executed in an explicit order:
http://stackoverflow.com/questions/5387299/python-unittest-testcase-execution-order
"""
@classmethod
def setUpClass(self):
self.radio = Radio()
def test_initial_state(self):
state = self.radio.state.name
expected_state_name = 'AM'
self.assertEqual(state, expected_state_name)
def test_initial_am_station(self):
station = self.radio.state.stations[self.radio.state.pos]
expected_station = '1250'
self.assertEqual(station, expected_station)
def test_2nd_am_station_after_scan(self):
self.radio.scan()
station = self.radio.state.stations[self.radio.state.pos]
expected_station = '1380'
self.assertEqual(station, expected_station)
def test_3rd_am_station_after_scan(self):
self.radio.scan()
station = self.radio.state.stations[self.radio.state.pos]
expected_station = '1510'
self.assertEqual(station, expected_station)
def test_am_station_overflow_after_scan(self):
self.radio.scan()
station = self.radio.state.stations[self.radio.state.pos]
expected_station = '1250'
self.assertEqual(station, expected_station)
def test_shall_toggle_from_am_to_fm(self):
self.radio.toggle_amfm()
state = self.radio.state.name
expected_state_name = 'FM'
self.assertEqual(state, expected_state_name)
def test_shall_toggle_from_fm_to_am(self):
self.radio.toggle_amfm()
state = self.radio.state.name
expected_state_name = 'AM'
self.assertEqual(state, expected_state_name)
if __name__ == "__main__":
unittest.main()