Домашни > Bang the ranga! > Решения > Решението на Владимир Апостолов

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

0 точки общо

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

 1import unittest
 2import tempfile
 3from bangaranga import does_the_banga_rang, TheBangaDoesNotRangError
 4
 5
 6class TestFunction(unittest.TestCase):
 7    def make_file(file_content):
 8        temp_file = tempfile.NamedTemporaryFile(mode="w", delete=False)
 9        temp_file.write(file_content)
10        temp_file.close()
11        return temp_file.name
12
13    def test_returns_2_for_banga_and_ranga(self):
14        filename = self.make_file("banga and ranga")
15        self.assertEqual(does_the_banga_rang(filename), 2)
16
17    def test_returns_0_for_random_text(self):
18        filename = self.make_file("Vladi is the best Python developer.")
19        self.assertEqual(does_the_banga_rang(filename), 2)
20
21    def test_returns_1_for_bangaranga(self):
22        filename = self.make_file("bangaranga test file")
23        self.assertEqual(does_the_banga_rang(filename), 1)
24
25    def test_returns_3(self):
26        filename = self.make_file("bang a ranga")
27        self.assertEqual(does_the_banga_rang(filename), 3)
28
29    def test_is_case_sensitive(self):
30        filename = self.make_file("BANGA and RANGA")
31        self.assertEqual(does_the_banga_rang(filename), 1)
32
33    def test_respects_word_order(self):
34        filename = self.make_file("ranga something banga.")
35        self.assertEqual(does_the_banga_rang(filename), 0)
36
37    def test_throws_error(self):
38        with self.assertRaises(TheBangaDoesNotRangError) as exc:
39            does_the_banga_rang("error_file.txt")
40
41
42if __name__ == "__main__":
43    unittest.main()

FFFFF.FFFF
======================================================================
FAIL: test_student_tests_catch_bad_implementation_allows_partial_target_match (test.StudentTestSuiteEvaluationTests.test_student_tests_catch_bad_implementation_allows_partial_target_match)
----------------------------------------------------------------------
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_allows_partial_target_match'.
| Output:
| ----------------------------------------------------------------------
| Ran 1 test in 0.000s
|
| OK

======================================================================
FAIL: test_student_tests_catch_bad_implementation_case_sensitive (test.StudentTestSuiteEvaluationTests.test_student_tests_catch_bad_implementation_case_sensitive)
----------------------------------------------------------------------
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_case_sensitive'.
| Output:
| ----------------------------------------------------------------------
| Ran 1 test in 0.000s
|
| OK

======================================================================
FAIL: test_student_tests_catch_bad_implementation_does_not_handle_single_word_solution (test.StudentTestSuiteEvaluationTests.test_student_tests_catch_bad_implementation_does_not_handle_single_word_solution)
----------------------------------------------------------------------
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_does_not_handle_single_word_solution'.
| Output:
| ----------------------------------------------------------------------
| Ran 1 test in 0.000s
|
| OK

======================================================================
FAIL: test_student_tests_catch_bad_implementation_ignores_word_order (test.StudentTestSuiteEvaluationTests.test_student_tests_catch_bad_implementation_ignores_word_order)
----------------------------------------------------------------------
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_ignores_word_order'.
| Output:
| ----------------------------------------------------------------------
| Ran 1 test in 0.000s
|
| OK

======================================================================
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 1 test in 0.000s
|
| 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 1 test in 0.000s
|
| 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 1 test in 0.000s
|
| OK

======================================================================
FAIL: test_student_tests_catch_bad_implementation_returns_none_when_no_solution (test.StudentTestSuiteEvaluationTests.test_student_tests_catch_bad_implementation_returns_none_when_no_solution)
----------------------------------------------------------------------
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_none_when_no_solution'.
| Output:
| ----------------------------------------------------------------------
| Ran 1 test in 0.000s
|
| 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:
| ======================================================================
| ERROR: test_is_case_sensitive (solution.TestFunction.test_is_case_sensitive)
| ----------------------------------------------------------------------
| Traceback (most recent call last):
| File "/tmp/solution.py", line 30, in test_is_case_sensitive
| filename = self.make_file("BANGA and RANGA")
| TypeError: TestFunction.make_file() takes 1 positional argument but 2 were given
|
| ======================================================================
| ERROR: test_respects_word_order (solution.TestFunction.test_respects_word_order)
| ----------------------------------------------------------------------
| Traceback (most recent call last):
| File "/tmp/solution.py", line 34, in test_respects_word_order
| filename = self.make_file("ranga something banga.")
| TypeError: TestFunction.make_file() takes 1 positional argument but 2 were given
|
| ======================================================================
| ERROR: test_returns_0_for_random_text (solution.TestFunction.test_returns_0_for_random_text)
| ----------------------------------------------------------------------
| Traceback (most recent call last):
| File "/tmp/solution.py", line 18, in test_returns_0_for_random_text
| filename = self.make_file("Vladi is the best Python developer.")
| TypeError: TestFunction.make_file() takes 1 positional argument but 2 were given
|
| ======================================================================
| ERROR: test_returns_1_for_bangaranga (solution.TestFunction.test_returns_1_for_bangaranga)
| ----------------------------------------------------------------------
| Traceback (most recent call last):
| File "/tmp/solution.py", line 22, in test_returns_1_for_bangaranga
| filename = self.make_file("bangaranga test file")
| TypeError: TestFunction.make_file() takes 1 positional argument but 2 were given
|
| ======================================================================
| ERROR: test_returns_2_for_banga_and_ranga (solution.TestFunction.test_returns_2_for_banga_and_ranga)
| ----------------------------------------------------------------------
| Traceback (most recent call last):
| File "/tmp/solution.py", line 14, in test_returns_2_for_banga_and_ranga
| filename = self.make_file("banga and ranga")
| TypeError: TestFunction.make_file() takes 1 positional argument but 2 were given
|
| ======================================================================
| ERROR: test_returns_3 (solution.TestFunction.test_returns_3)
| ----------------------------------------------------------------------
| Traceback (most recent call last):
| File "/tmp/solution.py", line 26, in test_returns_3
| filename = self.make_file("bang a ranga")
| TypeError: TestFunction.make_file() takes 1 positional argument but 2 were given
|
| ----------------------------------------------------------------------
| Ran 7 tests in 0.001s
|
| FAILED (errors=6)

----------------------------------------------------------------------
Ran 10 tests in 0.031s

FAILED (failures=9)

Дискусия
История

f1import unittestf1import unittest
2import tempfile2import tempfile
3from bangaranga import does_the_banga_rang, TheBangaDoesNotRangError3from bangaranga import does_the_banga_rang, TheBangaDoesNotRangError
44
nn5 
5class TestFunction(unittest.TestCase):6class TestFunction(unittest.TestCase):
6    def make_file(file_content):7    def make_file(file_content):
n7        temp_file = tempfile.NamedTemporaryFile(mode = "w", delete=False)n8        temp_file = tempfile.NamedTemporaryFile(mode="w", delete=False)
8        temp_file.write(file_content)9        temp_file.write(file_content)
9        temp_file.close()10        temp_file.close()
10        return temp_file.name11        return temp_file.name
n11    n12 
12    def test_returns_2_for_banga_and_ranga(self):13    def test_returns_2_for_banga_and_ranga(self):
13        filename = self.make_file("banga and ranga")14        filename = self.make_file("banga and ranga")
n14        self.assertEqual(does_the_banga_rang(filename),2)n15        self.assertEqual(does_the_banga_rang(filename), 2)
1516
16    def test_returns_0_for_random_text(self):17    def test_returns_0_for_random_text(self):
17        filename = self.make_file("Vladi is the best Python developer.")18        filename = self.make_file("Vladi is the best Python developer.")
18        self.assertEqual(does_the_banga_rang(filename), 2)19        self.assertEqual(does_the_banga_rang(filename), 2)
n19    n20 
20    def test_returns_1_for_bangaranga(self):21    def test_returns_1_for_bangaranga(self):
21        filename = self.make_file("bangaranga test file")22        filename = self.make_file("bangaranga test file")
22        self.assertEqual(does_the_banga_rang(filename), 1)23        self.assertEqual(does_the_banga_rang(filename), 1)
n23    n24 
24    def test_returns_3(self):25    def test_returns_3(self):
25        filename = self.make_file("bang a ranga")26        filename = self.make_file("bang a ranga")
26        self.assertEqual(does_the_banga_rang(filename), 3)27        self.assertEqual(does_the_banga_rang(filename), 3)
n27    n28 
28    def test_is_case_sensitive(self):29    def test_is_case_sensitive(self):
29        filename = self.make_file("BANGA and RANGA")30        filename = self.make_file("BANGA and RANGA")
30        self.assertEqual(does_the_banga_rang(filename), 1)31        self.assertEqual(does_the_banga_rang(filename), 1)
n31    n32 
32    def test_respects_word_order(self):33    def test_respects_word_order(self):
33        filename = self.make_file("ranga something banga.")34        filename = self.make_file("ranga something banga.")
34        self.assertEqual(does_the_banga_rang(filename), 0)35        self.assertEqual(does_the_banga_rang(filename), 0)
n35    n36 
36    def test_throws_error(self):37    def test_throws_error(self):
37        with self.assertRaises(TheBangaDoesNotRangError) as exc:38        with self.assertRaises(TheBangaDoesNotRangError) as exc:
38            does_the_banga_rang("error_file.txt")39            does_the_banga_rang("error_file.txt")
3940
tt41 
40if __name__ == '__main__':42if __name__ == "__main__":
41    unittest.main()43    unittest.main()
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op