Skip to content

Commit 541af87

Browse files
author
thinwybk
committed
add: tests for adapter.py
1 parent 8995bfe commit 541af87

1 file changed

Lines changed: 81 additions & 0 deletions

File tree

‎test_adapter.py‎

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
from adapter import Dog, Cat, Human, Car, Adapter
2+
import sys
3+
4+
if sys.version_info < (2, 7):
5+
import unittest2 as unittest
6+
else:
7+
import unittest
8+
9+
class ClassTest(unittest.TestCase):
10+
11+
@classmethod
12+
def setUpClass(self):
13+
self.dog = Dog()
14+
self.cat = Cat()
15+
self.human = Human()
16+
self.car = Car()
17+
18+
def test_dog_shall_bark(self):
19+
noise = self.dog.bark()
20+
expected_noise = "woof!"
21+
self.assertEqual(noise, expected_noise)
22+
23+
def test_cat_shall_meow(self):
24+
noise = self.cat.meow()
25+
expected_noise = "meow!"
26+
self.assertEqual(noise, expected_noise)
27+
28+
def test_human_shall_speak(self):
29+
noise = self.human.speak()
30+
expected_noise = "'hello'"
31+
self.assertEqual(noise, expected_noise)
32+
33+
def test_car_shall_make_loud_noise(self):
34+
noise = self.car.make_noise(1)
35+
expected_noise = "vroom!"
36+
self.assertEqual(noise, expected_noise)
37+
38+
def test_car_shall_make_very_loud_noise(self):
39+
noise = self.car.make_noise(10)
40+
expected_noise = "vroom!!!!!!!!!!"
41+
self.assertEqual(noise, expected_noise)
42+
43+
class AdapterTest(unittest.TestCase):
44+
45+
def test_dog_adapter_shall_make_noise(self):
46+
dog = Dog()
47+
dog_adapter = Adapter(dog, make_noise=dog.bark)
48+
noise = dog_adapter.make_noise()
49+
expected_noise = "woof!"
50+
self.assertEqual(noise, expected_noise)
51+
52+
def test_cat_adapter_shall_make_noise(self):
53+
cat = Cat()
54+
cat_adapter = Adapter(cat, make_noise=cat.meow)
55+
noise = cat_adapter.make_noise()
56+
expected_noise = "meow!"
57+
self.assertEqual(noise, expected_noise)
58+
59+
def test_human_adapter_shall_make_noise(self):
60+
human = Human()
61+
human_adapter = Adapter(human, make_noise=human.speak)
62+
noise = human_adapter.make_noise()
63+
expected_noise = "'hello'"
64+
self.assertEqual(noise, expected_noise)
65+
66+
def test_car_adapter_shall_make_loud_noise(self):
67+
car = Car()
68+
car_adapter = Adapter(car, make_noise=car.make_noise)
69+
noise = car_adapter.make_noise(1)
70+
expected_noise = "vroom!"
71+
self.assertEqual(noise, expected_noise)
72+
73+
def test_car_adapter_shall_make_very_loud_noise(self):
74+
car = Car()
75+
car_adapter = Adapter(car, make_noise=car.make_noise)
76+
noise = car_adapter.make_noise(10)
77+
expected_noise = "vroom!!!!!!!!!!"
78+
self.assertEqual(noise, expected_noise)
79+
80+
if __name__ == "__main__":
81+
unittest.main()

0 commit comments

Comments
 (0)