def test_one_longest_word_from_one_word(self): """ This test checks if reducer works correctly for the input data of a single word with --number==1. """ test_job = LongestWordsJob() values = [['word']] self.assertEqual(next(test_job.reducer(None, values)), (None, 'word\n'))
def test_one_longest_word_from_many_words(self): """ This test checks if reducer works correctly for the input data of multiple words with --number==1. """ test_job = LongestWordsJob() values = (['word'], ['abacaba'], ['abacabadabacaba']) self.assertEqual(next(test_job.reducer(None, values)), (None, 'abacabadabacaba\n'))
def test_two_longest_words_in_long_line(self): """ This test checks if mapper words correctly for the line with many words with --number==2. """ test_job = LongestWordsJob(['--number=2']) self.assertEqual( next( test_job.mapper( None, 'This is a quiet long string with many words')), (None, ['string', 'quiet']))
def test_two_longest_words_from_many_words(self): """ This tests checks if reducer works correctly for the input data of multiple words with --number==2. """ test_job = LongestWordsJob(['--number=2']) values = (['word'], ['abacaba', 'adacadabadacada'], ['abacabadabacaba']) try: self.assertEqual(next(test_job.reducer(None, values)), (None, 'abacabadabacaba\nadacadabadacada\n')) except AssertionError: self.assertEqual(next(test_job.reducer(None, values)), (None, 'adacadabadacada\nabacabadabacaba\n'))
def test_one_longest_word_from_some_text(self): """ This test checks if the job works correctly for some simple ont-line text with --number==1. """ test_job = LongestWordsJob() test_job.sandbox(stdin=self.first_test_stdin) result = [] with test_job.make_runner() as runner: runner.run() for line in runner.stream_output(): key, value = test_job.parse_output_line(line) result.append(value) self.assertEqual(result, ['familiarize\n', '\n'])
def test_two_longest_words_from_some_text(self): """ This functions checks if the job works correctly for some multiple lines of text with --number==2. """ test_job = LongestWordsJob(['--number=2']) test_job.sandbox(stdin=self.second_test_stdin) result = [] with test_job.make_runner() as runner: runner.run() for line in runner.stream_output(): key, value = test_job.parse_output_line(line) result.append(value) try: self.assertEqual(result, ['second\n', 'fourth\n', '\n']) except AssertionError: self.assertEqual(result, ['fourth\n', 'second\n', '\n'])
def test_one_longest_word_in_one_word_line_line(self): """ This test checks if mapper works correctly for the line with a single word with --number==1. """ test_job = LongestWordsJob() self.assertEqual(next(test_job.mapper(None, 'word')), (None, ['word']))