75 lines
2.4 KiB
Python
75 lines
2.4 KiB
Python
import pytest
|
|
from bicycle_drive_train import BikeDriveTrain
|
|
|
|
|
|
@pytest.fixture(scope="module")
|
|
def drive_train():
|
|
"""
|
|
list of front cog tooth counts. For example it could be initialized with [38,30]
|
|
list of rear cog tooth counts. For example it could be initialized with [28, 23, 19, 16]
|
|
"""
|
|
return BikeDriveTrain([38, 30], [28, 23, 19, 16])
|
|
|
|
def test_bike_drive_train(drive_train):
|
|
assert drive_train.front_cogs == [38, 30]
|
|
assert drive_train.rear_cogs == [28, 23, 19, 16]
|
|
|
|
def test_bike_drive_train_ratios(drive_train):
|
|
# generate list of the gear ratios for the given front crank and rear cassette
|
|
ratios = [(38, 28, 38 / 28),
|
|
(38, 23, 38 / 23),
|
|
(38, 19, 38 / 19),
|
|
(38, 16, 38 / 16),
|
|
(30, 28, 30 / 28),
|
|
(30, 23, 30 / 23),
|
|
(30, 19, 30 / 19),
|
|
(30, 16, 30 / 16)
|
|
]
|
|
|
|
for ratio in ratios:
|
|
assert ratio in drive_train.gear_combinations_and_ratios
|
|
|
|
|
|
def test_bike_drive_train_ratio(drive_train):
|
|
"""
|
|
If the drivetrain was initialized with the example values above and passed a target_ratio of 1.6
|
|
It should return a data type that contains the information:
|
|
Front: 30, Rear: 19, Ratio: 1.579
|
|
"""
|
|
assert drive_train.get_gear_combination(1.6) == (30, 19, 30 / 19)
|
|
|
|
|
|
def test_bike_drive_train_shift_seq(drive_train):
|
|
"""
|
|
For an example input the same as above plus: initial_gear_combination = [38, 28]
|
|
|
|
1 - F:38 R:28 Ratio 1.357
|
|
2 - F:30 R:28 Ratio 1.071
|
|
3 - F:30 R:23 Ratio 1.304
|
|
4 - F:30 R:19 Ratio 1.579
|
|
"""
|
|
|
|
sequence = drive_train.get_shift_sequence(target_ratio=1.6, initial_gear_combination=[38, 28])
|
|
|
|
assert sequence == [
|
|
(38, 28, 38 / 28),
|
|
(30, 28, 30 / 28),
|
|
(30, 23, 30 / 23),
|
|
(30, 19, 30 / 19)
|
|
]
|
|
|
|
# Test case an downshifting sequence
|
|
sequence = drive_train.get_shift_sequence(target_ratio=1.4, initial_gear_combination=[30, 19])
|
|
|
|
assert sequence == [
|
|
(30, 19, 30 / 19),
|
|
(38, 19, 38 / 19),
|
|
(38, 23, 38 / 23),
|
|
(38, 28, 38 / 28),
|
|
]
|
|
|
|
def test_bike_drive_train_shift_seq_output(drive_train, capsys):
|
|
drive_train.produce_formatted_shift_sequence(target_ratio=1.6, initial_gear_combination=[38, 28])
|
|
out, err = capsys.readouterr()
|
|
assert out == "1 - F:38 R:28 Ratio 1.357\n2 - F:30 R:28 Ratio 1.071\n3 - F:30 R:23 Ratio 1.304\n4 - F:30 R:19 Ratio 1.579\n"
|