Домашни > Bang the ranga! > Решения > Решението на Никита Симинкович

Резултати
2 точки от тестове
0 точки от учител

2 точки общо

6 успешни теста
4 неуспешни теста
Код
Скрий всички коментари

 1from unittest import TestCase, main
 2from unittest.mock import Mock, mock_open, patch
 3
 4from bangaranga import does_the_banga_rang, TheBangaDoesNotRangError
 5
 6
 7class DoesTheBangaRangTests(TestCase):
 8    def setUp(self):
 9        self.func = does_the_banga_rang
10        self.func_error = TheBangaDoesNotRangError
11
12    def test_func_return_one(self):
13        with patch("builtins.open", mock_open(read_data="bangaranga")):
14            self.assertEqual(open("file.txt").read(), "bangaranga")
15            self.assertEqual(self.func("file.txt"), 1)
16
17    def test_func_return_one_case_insensitive(self):
18        with patch("builtins.open", mock_open(read_data="baNgaRanga")):
19            self.assertEqual(open("file.txt").read(), "baNgaRanga")
20            self.assertEqual(self.func("file.txt"), 1)
21
22    def test_func_return_multiple(self):
23        with patch("builtins.open", mock_open(read_data="bang a small ranga")):
24            self.assertEqual(open("file.txt").read(), "bang a small ranga")
25            self.assertEqual(self.func("file.txt"), 2)
26
27    def test_func_return_multiple_on_multiple_lines(self):
28        with patch("builtins.open", mock_open(read_data="bang A smAll\n raNga")):
29            self.assertEqual(open("file.txt").read(), "bang A smAll raNga")
30            self.assertEqual(self.func("file.txt"), 2)
31
32    def test_func_return_zero_no_words(self):
33        with patch("builtins.open", mock_open(read_data="Does the banga rang?")):
34            self.assertEqual(open("file.txt").read(), "Does the banga rang?")
35            self.assertEqual(self.func("file.txt"), 0)
36
37    def test_func_return_zero_misplaced_words(self):
38        with patch("builtins.open", mock_open(read_data="ranga is banga")):
39            self.assertEqual(open("file.txt").read(), "ranga is banga")
40            self.assertEqual(self.func("file.txt"), 0)
41
42    def test_func_return_zero_not_separated(self):
43        with patch("builtins.open", mock_open(read_data="bangar angabanga ranga")):
44            self.assertEqual(open("file.txt").read(), "ranga is banga")
45            self.assertEqual(self.func("file.txt"), 0)
46
47    def test_func_open_OSError_raises(self):
48        with patch("builtins.open", Mock(side_effect=OSError())):
49            with self.assertRaises(self.func_error):
50                self.func("file.txt")
51
52    def test_func_open_IOError_raises(self):
53        with patch("builtins.open", Mock(side_effect=IOError())):
54            with self.assertRaises(self.func_error):
55                self.func("file.txt")
56
57
58if __name__ == "__main__":
59    main()

....F.FF.F
======================================================================
FAIL: test_student_tests_catch_bad_implementation_matches_partial_words (test.StudentTestSuiteEvaluationTests.test_student_tests_catch_bad_implementation_matches_partial_words)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 98, in test
self.assertTrue(
~~~~~~~~~~~~~~~^
bad_result["failed_test_ids"],
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
f"Student tests passed against incorrect implementation: {implementation_name!r}.\n{format_student_output(bad_result['output'])}",
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
AssertionError: set() is not true : Student tests passed against incorrect implementation: 'bad_implementation_matches_partial_words'.
| Output:
| ----------------------------------------------------------------------
| Ran 6 tests in 0.005s
|
| OK

======================================================================
FAIL: test_student_tests_catch_bad_implementation_requires_adjacent_words (test.StudentTestSuiteEvaluationTests.test_student_tests_catch_bad_implementation_requires_adjacent_words)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 98, in test
self.assertTrue(
~~~~~~~~~~~~~~~^
bad_result["failed_test_ids"],
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
f"Student tests passed against incorrect implementation: {implementation_name!r}.\n{format_student_output(bad_result['output'])}",
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
AssertionError: set() is not true : Student tests passed against incorrect implementation: 'bad_implementation_requires_adjacent_words'.
| Output:
| ----------------------------------------------------------------------
| Ran 6 tests in 0.004s
|
| OK

======================================================================
FAIL: test_student_tests_catch_bad_implementation_returns_first_match_instead_of_minimum (test.StudentTestSuiteEvaluationTests.test_student_tests_catch_bad_implementation_returns_first_match_instead_of_minimum)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 98, in test
self.assertTrue(
~~~~~~~~~~~~~~~^
bad_result["failed_test_ids"],
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
f"Student tests passed against incorrect implementation: {implementation_name!r}.\n{format_student_output(bad_result['output'])}",
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
AssertionError: set() is not true : Student tests passed against incorrect implementation: 'bad_implementation_returns_first_match_instead_of_minimum'.
| Output:
| ----------------------------------------------------------------------
| Ran 6 tests in 0.004s
|
| OK

======================================================================
FAIL: test_student_tests_pass_against_correct_implementation (test.StudentTestSuiteEvaluationTests.test_student_tests_pass_against_correct_implementation)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 83, in test_student_tests_pass_against_correct_implementation
self.assertTrue(
~~~~~~~~~~~~~~~^
result["was_successful"], f"Student tests should pass against the correct implementation.\n{student_output}"
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
AssertionError: False is not true : Student tests should pass against the correct implementation.
| Output:
| ======================================================================
| FAIL: test_func_return_multiple (solution.DoesTheBangaRangTests.test_func_return_multiple)
| ----------------------------------------------------------------------
| Traceback (most recent call last):
| File "/tmp/solution.py", line 25, in test_func_return_multiple
| self.assertEqual(self.func("file.txt"), 2)
| ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^
| AssertionError: 3 != 2
|
| ======================================================================
| FAIL: test_func_return_multiple_on_multiple_lines (solution.DoesTheBangaRangTests.test_func_return_multiple_on_multiple_lines)
| ----------------------------------------------------------------------
| Traceback (most recent call last):
| File "/tmp/solution.py", line 29, in test_func_return_multiple_on_multiple_lines
| self.assertEqual(open("file.txt").read(), "bang A smAll raNga")
| ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| AssertionError: 'bang A smAll\n raNga' != 'bang A smAll raNga'
| - bang A smAll
| + bang A smAll raNga
| ? ++++++
| - raNga
|
|
| ======================================================================
| FAIL: test_func_return_zero_not_separated (solution.DoesTheBangaRangTests.test_func_return_zero_not_separated)
| ----------------------------------------------------------------------
| Traceback (most recent call last):
| File "/tmp/solution.py", line 44, in test_func_return_zero_not_separated
| self.assertEqual(open("file.txt").read(), "ranga is banga")
| ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| AssertionError: 'bangar angabanga ranga' != 'ranga is banga'
| - bangar angabanga ranga
| + ranga is banga
|
|
| ----------------------------------------------------------------------
| Ran 9 tests in 0.007s
|
| FAILED (failures=3)

----------------------------------------------------------------------
Ran 10 tests in 0.215s

FAILED (failures=4)

Дискусия
История
Това решение има само една версия.