1def check_type(x, type_of_x):
2 return type(x) == type_of_x
3
4
5def no_it_isnt(list_of_vars):
6 reversed_list = []
7 for var in list_of_vars:
8 reversed_var = None
9 if check_type(var, str):
10 reversed_var = var[::-1]
11 elif check_type(var, int) or check_type(var, float):
12 reversed_var = -var
13 elif check_type(var, bool):
14 reversed_var = True if False else False
15 else:
16 reversed_var = var
17 reversed_list.append(reversed_var)
18
19 return reversed_list[::-1]
F..F.
======================================================================
FAIL: test_bool (test.TestOpposite)
Test with a bool.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 23, in test_bool
self.assertEqual(no_it_isnt([True, False]), [True, False])
AssertionError: Lists differ: [False, False] != [True, False]
First differing element 0:
False
True
- [False, False]
+ [True, False]
======================================================================
FAIL: test_mixed (test.TestOpposite)
Test with a long mixed content of types.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 34, in test_mixed
self.assertEqual(no_it_isnt([True, True, False]), [True, False, False])
AssertionError: Lists differ: [False, False, False] != [True, False, False]
First differing element 0:
False
True
- [False, False, False]
+ [True, False, False]
----------------------------------------------------------------------
Ran 5 tests in 0.001s
FAILED (failures=2)
n | n | 1 | def check_type(x, type_of_x): | ||
2 | return type(x) == type_of_x | ||||
3 | |||||
4 | |||||
1 | def no_it_isnt(list_of_vars): | 5 | def no_it_isnt(list_of_vars): | ||
2 | reversed_list = [] | 6 | reversed_list = [] | ||
3 | for var in list_of_vars: | 7 | for var in list_of_vars: | ||
4 | reversed_var = None | 8 | reversed_var = None | ||
n | 5 | if type(var) == str: | n | 9 | if check_type(var, str): |
6 | reversed_var = var[::-1] | 10 | reversed_var = var[::-1] | ||
n | 7 | elif type(var) == int or type(var) == float: | n | 11 | elif check_type(var, int) or check_type(var, float): |
8 | reversed_var = -var | 12 | reversed_var = -var | ||
t | 9 | elif type(var) == bool: | t | 13 | elif check_type(var, bool): |
10 | reversed_var = True if False else False | 14 | reversed_var = True if False else False | ||
11 | else: | 15 | else: | ||
12 | reversed_var = var | 16 | reversed_var = var | ||
13 | reversed_list.append(reversed_var) | 17 | reversed_list.append(reversed_var) | ||
14 | 18 | ||||
15 | return reversed_list[::-1] | 19 | return reversed_list[::-1] |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|
19.10.2023 17:40