-
Notifications
You must be signed in to change notification settings - Fork 0
/
strings_test.py
147 lines (121 loc) · 7.15 KB
/
strings_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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
"""Tests for the functions in the strings module."""
import unittest
import pytest
from strings import (add_prefix_un,
make_word_groups,
remove_suffix_ness,
adjective_to_verb)
class LittleSistersVocabTest(unittest.TestCase):
"""Tests for the functions in the strings module."""
@pytest.mark.task(taskno=1)
def test_add_prefix_un(self):
"""Test the add_prefix_un function."""
input_data = ['happy', 'manageable',
'fold', 'eaten', 'avoidable', 'usual']
result_data = [f'un{item}' for item in input_data]
for variant, (word, expected) in enumerate(zip(input_data, result_data), start=1):
with self.subTest(f'variation #{variant}', word=word, expected=expected):
actual_result = add_prefix_un(word)
error_message = (f'Called add_prefix_un("{word}"). '
f'The function returned "{
actual_result}", but the '
f'tests expected "{expected}" after adding "un" as a prefix.')
self.assertEqual(actual_result, expected, msg=error_message)
@pytest.mark.task(taskno=2)
def test_make_word_groups_en(self):
"""Test the make_word_groups function."""
input_data = ['en', 'circle', 'fold', 'close', 'joy',
'lighten', 'tangle', 'able', 'code', 'culture']
expected = ('en :: encircle :: enfold :: enclose :: enjoy :: enlighten ::'
' entangle :: enable :: encode :: enculture')
actual_result = make_word_groups(input_data)
error_message = (f'Called make_word_groups({input_data}). '
f'The function returned "{actual_result}", '
f'but the tests expected "{expected}" for the '
'word groups.')
self.assertEqual(actual_result, expected, msg=error_message)
@pytest.mark.task(taskno=2)
def test_make_word_groups_pre(self):
"""Test the make_word_groups_pre function."""
input_data = ['pre', 'serve', 'dispose', 'position', 'requisite', 'digest',
'natal', 'addressed', 'adolescent', 'assumption', 'mature', 'compute']
expected = ('pre :: preserve :: predispose :: preposition :: prerequisite :: '
'predigest :: prenatal :: preaddressed :: preadolescent :: preassumption :: '
'premature :: precompute')
actual_result = make_word_groups(input_data)
error_message = (f'Called make_word_groups({input_data}). '
f'The function returned "{actual_result}", '
f'but the tests expected "{expected}" for the '
'word groups.')
self.assertEqual(actual_result, expected, msg=error_message)
@pytest.mark.task(taskno=2)
def test_make_word_groups_auto(self):
"""Test the make_word_groups_auto function."""
input_data = ['auto', 'didactic', 'graph', 'mate', 'chrome', 'centric', 'complete',
'echolalia', 'encoder', 'biography']
expected = ('auto :: autodidactic :: autograph :: automate :: autochrome :: '
'autocentric :: autocomplete :: autoecholalia :: autoencoder :: '
'autobiography')
actual_result = make_word_groups(input_data)
error_message = (f'Called make_word_groups({input_data}). '
f'The function returned "{actual_result}", '
f'but the tests expected "{expected}" for the word groups.')
self.assertEqual(actual_result, expected, msg=error_message)
@pytest.mark.task(taskno=2)
def test_make_words_groups_inter(self):
"""Test the make_words_groups_inter function."""
input_data = ['inter', 'twine', 'connected', 'dependent', 'galactic', 'action',
'stellar', 'cellular', 'continental', 'axial', 'operative', 'disciplinary']
expected = ('inter :: intertwine :: interconnected :: interdependent :: '
'intergalactic :: interaction :: interstellar :: intercellular :: '
'intercontinental :: interaxial :: interoperative :: interdisciplinary')
actual_result = make_word_groups(input_data)
error_message = (f'Called make_word_groups({input_data}). '
f'The function returned "{actual_result}", '
f'but the tests expected "{expected}" for the word groups.')
self.assertEqual(actual_result, expected, msg=error_message)
@pytest.mark.task(taskno=3)
def test_remove_suffix_ness(self):
"""Test the remove_suffix_ness function."""
input_data = ['heaviness', 'sadness', 'softness',
'crabbiness', 'lightness', 'artiness', 'edginess'
]
result_data = ['heavy', 'sad', 'soft',
'crabby', 'light', 'arty', 'edgy']
for variant, (word, expected) in enumerate(zip(input_data, result_data), start=1):
with self.subTest(f'variation #{variant}', word=word, expected=expected):
actual_result = remove_suffix_ness(word)
error_message = (f'Called remove_suffix_ness("{word}"). '
f'The function returned "{actual_result}", '
f'but the tests expected "{expected}" after the '
'suffix was removed.')
self.assertEqual(actual_result, expected, msg=error_message)
@pytest.mark.task(taskno=4)
def test_adjective_to_verb(self):
"""Test the adjective_to_verb function."""
input_data = ['Look at the bright sky.',
'His expression went dark.',
'The bread got hard after sitting out.',
'The butter got soft in the sun.',
'Her eyes were light blue.',
'The morning fog made everything damp with mist.',
'He cut the fence pickets short by mistake.',
'Charles made weak crying noises.',
'The black oil got on the white dog.']
index_data = [-2, -1, 3, 3, -2, -3, 5, 2, 1]
result_data = ['brighten', 'darken', 'harden', 'soften',
'lighten', 'dampen', 'shorten', 'weaken', 'blacken']
for variant, (sentence, index, expected) in enumerate(
zip(input_data, index_data, result_data),
start=1):
with self.subTest(
f'variation #{variant}',
sentence=sentence,
index=index,
expected=expected):
actual_result = adjective_to_verb(sentence, index)
error_message = (f'Called adjective_to_verb("{sentence}", {index}). '
f'The function returned "{actual_result}", but the tests '
f'expected "{expected}" as the verb for '
f'the word at index {index}.')
self.assertEqual(actual_result, expected, msg=error_message)