Rewrote stub file and strings_test.py
This commit is contained in:
47
exercises/concept/little-sisters-vocab/strings.py
Normal file
47
exercises/concept/little-sisters-vocab/strings.py
Normal file
@@ -0,0 +1,47 @@
|
||||
def add_prefix_un(word):
|
||||
'''
|
||||
|
||||
:param word: str of a root word
|
||||
:return: str of root word with un prefix
|
||||
|
||||
This function takes `word` as a parameter and
|
||||
returns a new word with an 'un' prefix.
|
||||
'''
|
||||
pass
|
||||
|
||||
def make_word_groups(vocab_words):
|
||||
'''
|
||||
|
||||
:param vocab_words: list of vocabulary words with a prefix.
|
||||
:return: str of prefix followed by vocabulary words with
|
||||
prefix applied, separated by ' :: '.
|
||||
|
||||
This function takes a `vocab_words` list and returns a string
|
||||
with the prefix and the words with prefix applied, separated
|
||||
by ' :: '.
|
||||
'''
|
||||
pass
|
||||
|
||||
def remove_suffix_ness(word):
|
||||
'''
|
||||
|
||||
:param word: str of word to remvoe suffix from.
|
||||
:return: str of word with suffix removed & spelling adjusted.
|
||||
|
||||
This function takes in a word and returns the base word with `ness` removed.
|
||||
'''
|
||||
pass
|
||||
|
||||
def noun_to_verb(sentence, index):
|
||||
'''
|
||||
|
||||
:param sentence: str that uses the word in sentance
|
||||
:param index: index of the word to remove and transform
|
||||
:return: str word that changes the extracted adjective to a verb.
|
||||
|
||||
A function takes a `sentence` using the
|
||||
vocabulary word, and the `index` of the word once that sentence
|
||||
is split apart. The function should return the extracted
|
||||
adjective as a verb.
|
||||
'''
|
||||
pass
|
||||
86
exercises/concept/little-sisters-vocab/strings_test.py
Normal file
86
exercises/concept/little-sisters-vocab/strings_test.py
Normal file
@@ -0,0 +1,86 @@
|
||||
import unittest
|
||||
from strings import add_prefix_un, make_word_groups, remove_suffix_ness, noun_to_verb
|
||||
|
||||
|
||||
class TestStrings(unittest.TestCase):
|
||||
def test_add_prefix_un(self):
|
||||
input_data = ["happy", "manageable", "fold", "eaten", "avoidable", "usual"]
|
||||
result_data = [f'un{item}' for item in input_data]
|
||||
number_of_variants = range(1, len(input_data) + 1)
|
||||
|
||||
for variant, word, result in zip(number_of_variants, input_data, result_data):
|
||||
with self.subTest(f"variation #{variant}", word=word, result=result):
|
||||
self.assertEqual(add_prefix_un(word), result,
|
||||
msg=f'Expected: {result} but got a different word instead.')
|
||||
|
||||
|
||||
def test_make_word_groups_en(self):
|
||||
input_data = ['en' ,'circle', 'fold', 'close','joy', 'lighten', 'tangle', 'able', 'code', 'culture']
|
||||
result_data = 'en :: encircle :: enfold :: enclose :: enjoy :: enlighten :: entangle :: enable :: encode :: enculture'
|
||||
|
||||
self.assertEqual(make_word_groups(input_data), result_data,
|
||||
msg=f'Expected {result_data} but got something else instead.')
|
||||
|
||||
|
||||
def test_make_word_groups_pre(self):
|
||||
input_data = ['pre', 'serve', 'dispose', 'position', 'requisite', 'digest',
|
||||
'natal', 'addressed', 'adolescent', 'assumption', 'mature', 'compute']
|
||||
result_data = ('pre :: preserve :: predispose :: preposition :: prerequisite :: '
|
||||
'predigest :: prenatal :: preaddressed :: preadolescent :: preassumption :: '
|
||||
'premature :: precompute')
|
||||
|
||||
self.assertEqual(make_word_groups(input_data), result_data,
|
||||
msg=f'Expected {result_data} but got something else instead.')
|
||||
|
||||
|
||||
def test_make_word_groups_auto(self):
|
||||
input_data = ['auto', 'didactic', 'graph', 'mate', 'chrome', 'centric', 'complete',
|
||||
'echolalia', 'encoder', 'biography']
|
||||
result_data = ('auto :: autodidactic :: autograph :: automate :: autochrome :: '
|
||||
'autocentric :: autocomplete :: autoecholalia :: autoencoder :: '
|
||||
'autobiography')
|
||||
|
||||
self.assertEqual(make_word_groups(input_data), result_data,
|
||||
msg=f'Expected {result_data} but got something else instead.')
|
||||
|
||||
|
||||
def test_make_words_groups_inter(self):
|
||||
input_data = ['inter', 'twine', 'connected', 'dependent', 'galactic', 'action',
|
||||
'stellar', 'cellular', 'continental', 'axial', 'operative', 'disciplinary']
|
||||
result_data = ('inter :: intertwine :: interconnected :: interdependent :: '
|
||||
'intergalactic :: interaction :: interstellar :: intercellular :: '
|
||||
'intercontinental :: interaxial :: interoperative :: interdisciplinary')
|
||||
|
||||
self.assertEqual(make_word_groups(input_data), result_data,
|
||||
msg=f'Expected {result_data} but got something else instead.')
|
||||
|
||||
|
||||
def test_remove_suffix_ness(self):
|
||||
input_data = ["heaviness", "sadness", "softness", "crabbiness", "lightness", "artiness", "edginess"]
|
||||
result_data = ["heavy", "sad", "soft", 'crabby', 'light', 'arty', 'edgy']
|
||||
number_of_variants = range(1, len(input_data) + 1)
|
||||
|
||||
for variant, word, result in zip(number_of_variants, input_data, result_data):
|
||||
with self.subTest(f"variation #{variant}", word=word, result=result):
|
||||
self.assertEqual(remove_suffix_ness(word), result,
|
||||
msg=f'Expected: {result} but got a different word instead.')
|
||||
|
||||
def test_noun_to_verb(self):
|
||||
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 face was filled with light.',
|
||||
'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, -1, -3, 5, 2, 1]
|
||||
result_data = ['brighten','darken','harden','soften',
|
||||
'lighten','dampen','shorten','weaken','blacken']
|
||||
number_of_variants = range(1, len(input_data) + 1)
|
||||
|
||||
for variant, sentence, index, result in zip(number_of_variants, input_data, index_data, result_data):
|
||||
with self.subTest(f"variation #{variant}", sentence=sentence, index=index, result=result):
|
||||
self.assertEqual(noun_to_verb(sentence, index), result,
|
||||
msg=f'Expected: {result} but got a different word instead.')
|
||||
Reference in New Issue
Block a user