1def not_too_expensive(price):
2 return price<=42 and price>=0
3
4def unique_names(**kwargs):
5 unique_chars = set()
6 for key in kwargs.keys():
7 unique_chars.update(key)
8 return len(unique_chars)
9
10def one_that_looks_nice(price,**kwargs):
11 return unique_names(**kwargs) % int(price) == 0
12
13def function_that_says_ni(*args, **kwargs):
14 for value in kwargs.values():
15 if "name" in value and "cost" in value:
16 if (value["name"].lower() in appropriate_answer) and (not_too_expensive(value["cost"]) and one_that_looks_nice(value["cost"],**kwargs)):
17 return round(float(value["cost"]),2)
18 return "Ni!"
19
20appropriate_answer=("храст", "shrub", "bush")
FE...FF.F.
======================================================================
ERROR: test_combination_of_arguments (test.TestNi.test_combination_of_arguments)
Test with combination of named and positional arguments.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 60, in test_combination_of_arguments
self.assertEqual(function_that_says_ni({'name': 'bush', 'cost': 1},
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/tmp/solution.py", line 16, in function_that_says_ni
if (value["name"].lower() in appropriate_answer) and (not_too_expensive(value["cost"]) and one_that_looks_nice(value["cost"],**kwargs)):
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/tmp/solution.py", line 11, in one_that_looks_nice
return unique_names(**kwargs) % int(price) == 0
~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~
ZeroDivisionError: integer modulo by zero
======================================================================
FAIL: test_all_possible_shrub_strings (test.TestNi.test_all_possible_shrub_strings)
Test with all possible strings that define a shrub.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 21, in test_all_possible_shrub_strings
self.assertEqual(function_that_says_ni({'name': 'shrub', 'cost': 1}), '1.00лв')
AssertionError: 'Ni!' != '1.00лв'
- Ni!
+ 1.00лв
======================================================================
FAIL: test_multiple_shrubs_sumс (test.TestNi.test_multiple_shrubs_sumс)
Test with a multiple shrubs and cornercase costs.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 34, in test_multiple_shrubs_sumс
self.assertEqual(function_that_says_ni({'name': 'shrub', 'cost': 20.00},
AssertionError: 'Ni!' != '42.00лв'
- Ni!
+ 42.00лв
======================================================================
FAIL: test_named_arguments (test.TestNi.test_named_arguments)
Test with named arguments.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 50, in test_named_arguments
self.assertEqual(function_that_says_ni(_abcde={'name': 'shrub', 'cost': 2.82},
AssertionError: 'Ni!' != '7.33лв'
- Ni!
+ 7.33лв
======================================================================
FAIL: test_single_with_no_named_args (test.TestNi.test_single_with_no_named_args)
Test with a single shrub that is passed as positional argument.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 17, in test_single_with_no_named_args
self.assertEqual(function_that_says_ni({'name': 'shrub', 'cost': 3.12}), '3.12лв')
AssertionError: 'Ni!' != '3.12лв'
- Ni!
+ 3.12лв
----------------------------------------------------------------------
Ran 10 tests in 0.001s
FAILED (failures=4, errors=1)
Виктор Бечев
19.10.2024 23:11Голям грях - индентацията ти е от табулации. Бързо, докато не е видял Жорката!
|
f | 1 | def not_too_expensive(price): | f | 1 | def not_too_expensive(price): |
n | 2 | if price<=42 and price>=0: | n | 2 | return price<=42 and price>=0 |
3 | return True | ||||
4 | return False | ||||
5 | |||||
6 | 3 | ||||
7 | def unique_names(**kwargs): | 4 | def unique_names(**kwargs): | ||
n | 8 | unique_chars = set() | n | 5 | unique_chars = set() |
9 | for key in kwargs.keys(): | 6 | for key in kwargs.keys(): | ||
10 | unique_chars.update(key) | 7 | unique_chars.update(key) | ||
11 | return len(unique_chars) | 8 | return len(unique_chars) | ||
12 | 9 | ||||
13 | def one_that_looks_nice(price,**kwargs): | 10 | def one_that_looks_nice(price,**kwargs): | ||
n | 14 | if unique_names(**kwargs) % int(price) == 0: | n | 11 | return unique_names(**kwargs) % int(price) == 0 |
15 | return True | ||||
16 | return False | ||||
17 | 12 | ||||
18 | def function_that_says_ni(*args, **kwargs): | 13 | def function_that_says_ni(*args, **kwargs): | ||
t | 19 | for value in kwargs.values(): | t | 14 | for value in kwargs.values(): |
20 | if "name" in value and "cost" in value: | 15 | if "name" in value and "cost" in value: | ||
21 | for _ in appropriate_answer: | ||||
22 | if (value["name"].lower() == _) and (not_too_expensive(value["cost"]) and one_that_looks_nice(value["cost"],**kwargs)): | 16 | if (value["name"].lower() in appropriate_answer) and (not_too_expensive(value["cost"]) and one_that_looks_nice(value["cost"],**kwargs)): | ||
23 | return round(float(value["cost"]),2) | 17 | return round(float(value["cost"]),2) | ||
24 | return "Ni!" | 18 | return "Ni!" | ||
25 | 19 | ||||
26 | appropriate_answer=("храст", "shrub", "bush") | 20 | appropriate_answer=("храст", "shrub", "bush") |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|
f | 1 | def not_too_expensive(price): | f | 1 | def not_too_expensive(price): |
2 | if price<=42 and price>=0: | 2 | if price<=42 and price>=0: | ||
3 | return True | 3 | return True | ||
4 | return False | 4 | return False | ||
5 | 5 | ||||
6 | 6 | ||||
7 | def unique_names(**kwargs): | 7 | def unique_names(**kwargs): | ||
8 | unique_chars = set() | 8 | unique_chars = set() | ||
9 | for key in kwargs.keys(): | 9 | for key in kwargs.keys(): | ||
10 | unique_chars.update(key) | 10 | unique_chars.update(key) | ||
11 | return len(unique_chars) | 11 | return len(unique_chars) | ||
12 | 12 | ||||
13 | def one_that_looks_nice(price,**kwargs): | 13 | def one_that_looks_nice(price,**kwargs): | ||
n | 14 | if unique_names(**kwargs) % price == 0: | n | 14 | if unique_names(**kwargs) % int(price) == 0: |
15 | return True | 15 | return True | ||
16 | return False | 16 | return False | ||
17 | 17 | ||||
18 | def function_that_says_ni(*args, **kwargs): | 18 | def function_that_says_ni(*args, **kwargs): | ||
19 | for value in kwargs.values(): | 19 | for value in kwargs.values(): | ||
20 | if "name" in value and "cost" in value: | 20 | if "name" in value and "cost" in value: | ||
21 | for _ in appropriate_answer: | 21 | for _ in appropriate_answer: | ||
22 | if (value["name"].lower() == _) and (not_too_expensive(value["cost"]) and one_that_looks_nice(value["cost"],**kwargs)): | 22 | if (value["name"].lower() == _) and (not_too_expensive(value["cost"]) and one_that_looks_nice(value["cost"],**kwargs)): | ||
t | 23 | return value["cost"] | t | 23 | return round(float(value["cost"]),2) |
24 | return "Ni!" | 24 | return "Ni!" | ||
25 | 25 | ||||
26 | appropriate_answer=("храст", "shrub", "bush") | 26 | appropriate_answer=("храст", "shrub", "bush") |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|