Repository navigation
Expand file tree
/
Copy pathrun_tests.py
More file actions
64 lines (48 loc) · 3.15 KB
/
Copy pathrun_tests.py
File metadata and controls
64 lines (48 loc) · 3.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import unittest
from conditionals_challenges import can_climb, red_light_camera, can_ride_rollercoaster, login
class TestCase(unittest.TestCase):
def test_can_climb(self):
for case, message in {
(False, False, False): "Inputs: \n - has_helmet: False\n - has_rope: False \nYour program would have let the climber climb without a helmet or rope!",
(True, False, False): "Inputs: \n - has_helmet: True\n - has_rope: False \nYour program would have let the climber climb without a helmet!",
(False, True, False): "Inputs: \n - has_helmet: False\n - True: False \nYour program would have let the climber climb without a rope!",
(True, True, True): "Inputs: \n - has_helmet: False\n - has_rope: False \nYour program won't let the climber climb, but they have everything they need!",
}.items():
result = can_climb(case[0], case[1])
if type(result) != bool:
self.fail(msg=f"Inputs: \n - has_helmet: {case[0]}\n - has_rope: {case[1]} \nYour function returned {type(result)} instead of a boolean!")
self.assertEqual(can_climb(case[0], case[1]), case[2], msg=message)
def test_red_light_camera(self):
for case in [
("Red", True, True),
("Amber", True, False),
("Green", True, False),
("Red", False, False),
("Amber", False, False),
("Green", False, False),
]:
result = red_light_camera(case[0], case[1])
if type(result) != bool:
self.fail(msg=f"Inputs: \n - light_colour: {case[0]}\n - car_detected: {case[1]} \nYour function returned {type(result)} instead of a boolean!")
self.assertEqual(red_light_camera(case[0], case[1]), case[2], msg=f"Inputs: \n - light_colour: {case[0]}\n - car_detected: {case[1]} \nYour function should have returned {case[2]} but instead returned {result}!")
def test_can_ride_rollercoaster(self):
for case in [
(100.0, False, "the rider is too short"),
(200.0, True, "the rider is tall enough"),
(120.0, False, "the rider is exactly 120cm tall (they need to be TALLER than 120cm)"),
]:
result = can_ride_rollercoaster(case[0])
if type(result) != bool:
self.fail(msg=f"Input: {case[0]} \nYour function returned {type(result)} instead of a boolean!")
self.assertEqual(result, case[1], msg=f"At {case[0]}cm, {case[2]}. But your function returned {result}!")
def test_login(self):
for case in [
("PASSWORD123", False),
("quartzgleam?1", True)
]:
result = login(case[0])
if type(result) != bool:
self.fail(msg=f"Input: {case[0]} \nYour function returned {type(result)} instead of a boolean!")
self.assertEqual(result, case[1], msg=f"With input {case[0]} your function returned {result}. The password is 'quartzgleam?1!', so the correct result was {case[1]}!")
runner = unittest.TextTestRunner(verbosity=2)
runner.run(unittest.TestSuite((unittest.TestLoader().loadTestsFromTestCase(TestCase))))