def test_split_words_without_space_returns_list_with_word(self): sentence_without_spaces = 'thisisasentencethathasnospaces' self.assertEqual( [sentence_without_spaces], helpers._split_words(sentence_without_spaces), 'Calling _split_words() on a string with no spaces should return a list with one member: the original string.' )
def to_pig_latin(text): """ Convert text to pig latin Args: text -- Text to convert """ if not isinstance(text, basestring): raise TypeError('to_pig_latin(): Arg must be a string.') converted_words = [] for word in _split_words(text): if not search('[a-zA-Z]', word): converted_words.append(word) continue trimmed_word = _trim_punctuation(word) if len(trimmed_word) == 0: converted_words.append(word) continue converted_word = word.replace(trimmed_word, _convert_word(trimmed_word)) converted_words.append(converted_word) return _join_words(converted_words)
def test_split_words_returns_list(self): test_sentences = [ 'test', '', ' ', 'test test', ' '.join(['test'] * 1000) ] for sentence in test_sentences: self.assertIsInstance( helpers._split_words(sentence), list, 'Calling _split_words() on %s should return an array.' % sentence )
def test_split_words_splits_on_space(self): test_sentences = { 'test test' : ['test', ' ', 'test'], 'test test' : ['test', ' ', 'test'] } for (sentence, words) in test_sentences.iteritems(): test_words = helpers._split_words(sentence) self.assertEqual( words, test_words, """ Calling _split_words() on %s returned an unexpected result. Expected: %s Actual: %s """ % (sentence, words, test_words) )
def test_split_words_empty_string_returns_list_with_empty_string(self): self.assertEqual( [''], helpers._split_words(''), 'Calling _split_words() on an empty string should return a list with one member: an empty string.' )