-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbottles_test.py
115 lines (96 loc) · 2.92 KB
/
bottles_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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import pytest
from bottles import CountdownSong, BottleVerse
def responds_to_lyrics(role_player):
return hasattr(role_player, 'lyrics') and callable(role_player.lyrics)
class TestBottleVerse:
def test_plays_verse_role(self):
assert responds_to_lyrics(BottleVerse)
def test_verse_general_rule_upper_bound(self):
expected = (
'99 bottles of beer on the wall, '
'99 bottles of beer.\n'
'Take one down and pass it around, '
'98 bottles of beer on the wall.\n'
)
assert BottleVerse.lyrics(99) == expected
def test_verse_general_rule_lower_bound(self):
expected = (
'3 bottles of beer on the wall, '
'3 bottles of beer.\n'
'Take one down and pass it around, '
'2 bottles of beer on the wall.\n'
)
assert BottleVerse.lyrics(3) == expected
def test_verse_7(self):
expected = (
'7 bottles of beer on the wall, '
'7 bottles of beer.\n'
'Take one down and pass it around, '
'1 six-pack of beer on the wall.\n'
)
assert BottleVerse.lyrics(7) == expected
def test_verse_6(self):
expected = (
'1 six-pack of beer on the wall, '
'1 six-pack of beer.\n'
'Take one down and pass it around, '
'5 bottles of beer on the wall.\n'
)
assert BottleVerse.lyrics(6) == expected
def test_verse_2(self):
expected = (
'2 bottles of beer on the wall, '
'2 bottles of beer.\n'
'Take one down and pass it around, '
'1 bottle of beer on the wall.\n'
)
assert BottleVerse.lyrics(2) == expected
def test_verse_1(self):
expected = (
'1 bottle of beer on the wall, '
'1 bottle of beer.\n'
'Take it down and pass it around, '
'no more bottles of beer on the wall.\n'
)
assert BottleVerse.lyrics(1) == expected
def test_verse_0(self):
expected = (
'No more bottles of beer on the wall, '
'no more bottles of beer.\n'
'Go to the store and buy some more, '
'99 bottles of beer on the wall.\n'
)
assert BottleVerse.lyrics(0) == expected
class VerseFake:
@staticmethod
def lyrics(number):
return f'This is verse {number}.\n'
class TestVerseFake:
def test_plays_verse_role(self):
assert responds_to_lyrics(VerseFake)
class TestCountdownSong:
def test_verse(self):
expected = 'This is verse 500.\n'
assert CountdownSong(verse_template=VerseFake).verse(500) == expected
def test_verses(self):
expected = (
'This is verse 99.\n'
'\n'
'This is verse 98.\n'
'\n'
'This is verse 97.\n'
)
assert CountdownSong(verse_template=VerseFake).verses(99, 97) == expected
def test_song(self):
expected = (
'This is verse 47.\n'
'\n'
'This is verse 46.\n'
'\n'
'This is verse 45.\n'
'\n'
'This is verse 44.\n'
'\n'
'This is verse 43.\n'
)
assert CountdownSong(verse_template=VerseFake, max=47, min=43).song() == expected