-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathtest_car.py
More file actions
46 lines (30 loc) · 853 Bytes
/
test_car.py
File metadata and controls
46 lines (30 loc) · 853 Bytes
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
import pytest
import random
from car import Car
@pytest.fixture
def car():
return Car()
def test_initial_speed(car):
assert car.speed == 0
def test_initial_odometer(car):
assert car.odometer == 0
def test_initial_time(car):
assert car.time == 0
# Tests for changing speed
def test_change_speed(car):
car.change_speed(7)
assert car.speed == 7
def test_multiple_speed_change(car):
total_change = 0
random.seed(42)
for _ in range(3):
change = random.randint(0, 10)
total_change += change
car.change_speed(change)
assert car.speed == total_change
# Tests for getting current speed
def test_get_current_speed_from_start(car):
assert car.get_current_speed() == 0
def test_get_current_speed_after_change(car):
car.change_speed(27)
assert car.get_current_speed() == 27