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

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

2 точки общо

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

 1import unittest
 2from unittest.mock import patch, mock_open
 3from bangaranga import does_the_banga_rang, TheBangaDoesNotRangError
 4
 5class TestBangaranga(unittest.TestCase):
 6    def test_from_many_words(self):
 7        with patch("builtins.open", mock_open(read_data="bang a ranga")):
 8            result = does_the_banga_rang("file.txt")
 9        self.assertEqual(result, 3)
10
11    def test_minimum_words(self):
12        with patch("builtins.open", mock_open(read_data="bang a ranga banga ranga bangaranga")):
13            result = does_the_banga_rang("file.txt")
14        self.assertEqual(result, 1)
15    
16    def test_exception_OSEroror(self):
17        with patch("builtins.open", side_effect=OSError):
18            with self.assertRaises(TheBangaDoesNotRangError):
19                does_the_banga_rang("file.txt")
20    
21    def test_exception_IOEroror(self):
22        with patch("builtins.open", side_effect=IOError):
23            with self.assertRaises(TheBangaDoesNotRangError):
24                does_the_banga_rang("file.txt")
25    
26    def test_case_insensitive(self):
27        with patch("builtins.open", mock_open(read_data="BangA RangA li chuuuh")):
28            result = does_the_banga_rang("file.txt")
29        self.assertEqual(result, 3)
30    
31    def test_wrong_order(self):
32        with patch("builtins.open", mock_open(read_data="ranga e sled banga")):
33            result = does_the_banga_rang("file.txt")
34        self.assertEqual(result, 0)
35
36    def test_wrong_order_2(self):
37        with patch("builtins.open", mock_open(read_data="rang banga a")):
38            result = does_the_banga_rang("file.txt")
39        self.assertEqual(result, 0)
40
41    def test_whole_words(self):
42        with patch("builtins.open", mock_open(read_data="banga1 ili 2ranga ili puk 1bangaranga2")):
43            result = does_the_banga_rang("file.txt")
44        self.assertEqual(result, 0)
45    
46    def test_one_word(self):
47        with patch("builtins.open", mock_open(read_data="bangaranga")):
48            result = does_the_banga_rang("file.txt")
49        self.assertEqual(result, 1)
50    
51    def test_words_inbetween(self):
52        with patch("builtins.open", mock_open(read_data="neshtosi bang neshto si a neshto si tam ranga")):
53            result = does_the_banga_rang("file.txt")
54        self.assertEqual(result, 3)
55
56    def test_no_bangaranga(self):
57        with patch("builtins.open", mock_open(read_data="hello world bang")):
58            result = does_the_banga_rang("file.txt")
59        self.assertEqual(result, 0)
60
61if __name__ == '__main__':
62    unittest.main()

.F.......F
======================================================================
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 10 tests in 0.011s
|
| 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_case_insensitive (solution.TestBangaranga.test_case_insensitive)
| ----------------------------------------------------------------------
| Traceback (most recent call last):
| File "/tmp/solution.py", line 29, in test_case_insensitive
| self.assertEqual(result, 3)
| ~~~~~~~~~~~~~~~~^^^^^^^^^^^
| AssertionError: 2 != 3
|
| ----------------------------------------------------------------------
| Ran 11 tests in 0.011s
|
| FAILED (failures=1)

----------------------------------------------------------------------
Ran 10 tests in 0.244s

FAILED (failures=2)

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