def test_a_longer_sentence(self): ''' test a multi-word sentence ''' sentence = 'Hello my name is Dolly and I would like to be your friend' expected = 'friend your be to like would I and Dolly is name my Hello' self.assertEqual(reverse_words(sentence), expected)
def test_simple_case(self): ''' test a simple three word sentence ''' sentence = "Hello, good day!" expected = "day! good Hello," self.assertEqual(reverse_words(sentence), expected)
def test_case_where_nothing_changes(self): ''' test a one-word sentence where a reversal of words should do nothing ''' sentence = "Hello" expected = sentence self.assertEqual(reverse_words(sentence), expected)
def test_reverses_long_string_of_words(self): """ Reverses a long string of space-delimited words """ result = reverse_words( "this is a long sentence that is being used to test the functionality of the function" ) self.assertEqual( result, "function the of functionality the test to used being is that sentence long a is this" )
def test_rand(self): words = [ "Kata", "should", "always", "have", "random", "tests", "case", "to", "avoid", "hardocoded", "solution.", "This", "is", "a", "rule!" ] for _ in range(50): s = (" " * randrange(1, 3)).join( randrange(words, randrange(len(words)))) exp = " ".join(("".join(list(s)[::-1])).split(" ")[::-1]) self.assertEqual(reverse_words(s), exp)
def test_reverse_words(): assert reverse_words("hello world!") == "world! hello" assert reverse_words("yoda doesn't speak like this") == \ "this like speak doesn't yoda" assert reverse_words("foobar") == "foobar" assert reverse_words("kata editor") == "editor kata" assert reverse_words("row row row your boat") == "boat your row row row" text_in = "The greatest victory is that which requires no battle" text_out = "battle no requires which that is victory greatest The" assert reverse_words(text_in) == text_out
def test(self): self.assertEqual( reverse_words('The quick brown fox jumps over the lazy dog.'), 'ehT kciuq nworb xof spmuj revo eht yzal .god') self.assertEqual(reverse_words('apple'), 'elppa') self.assertEqual(reverse_words('a b c d'), 'a b c d') self.assertEqual(reverse_words('double spaced words'), 'elbuod decaps sdrow') self.assertEqual(reverse_words('stressed desserts'), 'desserts stressed') self.assertEqual(reverse_words('hello hello'), 'olleh olleh')
def test_reverse_words_with_sentence_of_varying_length_words(): test_string = "I strive to engineer the most efficient solutions." expected = "I evirts ot reenigne eht tsom tneiciffe .snoitulos" assert reverse_words(test_string) == expected
def test_reverse_words_returns_unmodified_with_single_character_words(): test_string = "a b c d e f g h ? 1 2 4" assert reverse_words(test_string) == test_string
def test_reverse_words_with_two_word_sentence(): test_string = "hello, world" assert reverse_words(test_string) == ",olleh dlrow"
def test_reverse_words(self): string = 'just keep swimming' result = reverse_words(string) self.assertEqual(result, 'swimming keep just')
def test_reverse_words_in_a_line(self): self.assertEqual('test a is this', reverse_words('this is a test'))
def test_reverse_words_with_one_word(): test_string = "Engineer" assert reverse_words(test_string) == "reenignE"
def test_reverses_short_string_of_words(self): """ Reverse a short string of space-delimited words """ result = reverse_words("nathan thomas wrote this sentence") self.assertEqual(result, "sentence this wrote thomas nathan")
def test_generic(self): for idx, s in enumerate(self.strings): self.assertEqual(self.reversed_strings[idx], reverse_words(s))
def test_reverse_words_returns_unmodified_with_empty_sentence(): test_string = "" assert reverse_words(test_string) == ""
def test_reverse_words_returns_unmodified_with_None_input(): test_string = None assert reverse_words(test_string) is None
def test_returns_none_if_not_string_argument(self): """ Returns None if the argument passed in is not a string """ result = reverse_words([1, 2, 3, 4]) self.assertIsNone(result)
def test_reverse_words_maintains_leading_and_trailing_whitespace(): test_string = " evol " assert reverse_words(test_string) == " love "
def test_alnum(self): self.assertEqual('words some testing', reverse_words('testing some ' 'words'))
def test_reverse_words_with_one_word_dont_change_de_line(self): self.assertEqual('foobar', reverse_words('foobar'))
def testReverWord(self): self.assertEqual(rw.reverse_words("teste de python"), "python de teste")