本文整理汇总了Python中car.Car.speed方法的典型用法代码示例。如果您正苦于以下问题:Python Car.speed方法的具体用法?Python Car.speed怎么用?Python Car.speed使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类car.Car
的用法示例。
在下文中一共展示了Car.speed方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_car_matches_front_car
# 需要导入模块: from car import Car [as 别名]
# 或者: from car.Car import speed [as 别名]
def test_car_matches_front_car():
my_car = Car()
my_car.speed = 30
front_car = Car()
front_car.speed = 24
my_car.slow_down(front_car)
assert my_car.speed == 24
示例2: test_car_matches_speed_car_in_front
# 需要导入模块: from car import Car [as 别名]
# 或者: from car.Car import speed [as 别名]
def test_car_matches_speed_car_in_front():
car1 = Car()
car1.speed = 24
car2 = Car()
car2.speed = 20
car1.slow_down(car2)
assert car1.speed == 20
示例3: test_car_that_has_looped_does_not_make_car_behind_slow_down
# 需要导入模块: from car import Car [as 别名]
# 或者: from car.Car import speed [as 别名]
def test_car_that_has_looped_does_not_make_car_behind_slow_down():
car1 = Car()
car2 = Car()
car1.speed = 25
car2.speed = 27
car1.location = 15
car2.location = 980
assert car2.calculate_slowdown(car1) == False
示例4: test_car_that_has_looped_still_makes_car_behind_slow_down
# 需要导入模块: from car import Car [as 别名]
# 或者: from car.Car import speed [as 别名]
def test_car_that_has_looped_still_makes_car_behind_slow_down():
car1 = Car()
car2 = Car()
car1.speed = 25
car2.speed = 27
car1.location = 2
car2.location = 980
assert car2.calculate_slowdown(car1) == True
示例5: test_car_does_not_slow_down
# 需要导入模块: from car import Car [as 别名]
# 或者: from car.Car import speed [as 别名]
def test_car_does_not_slow_down():
car1 = Car()
car2 = Car()
car1.speed = 25
car2.speed = 27
car1.location = 115
car2.location = 80
assert car2.calculate_slowdown(car1) == False
示例6: test_car_decides_to_slow_down
# 需要导入模块: from car import Car [as 别名]
# 或者: from car.Car import speed [as 别名]
def test_car_decides_to_slow_down():
car1 = Car()
car2 = Car()
car1.speed = 25
car2.speed = 27
car1.location = 100
car2.location = 80
assert car2.calculate_slowdown(car1) == True
示例7: test_calculate_slow_down
# 需要导入模块: from car import Car [as 别名]
# 或者: from car.Car import speed [as 别名]
def test_calculate_slow_down():
my_car = Car()
car_in_front = Car()
my_car.speed = 30
my_car.location = 80
car_in_front.speed = 25
car_in_front.location = 100
assert my_car.calculate_slow_down(car_in_front) == True
示例8: test_calculate_not_slow_down_when_circling_the_road
# 需要导入模块: from car import Car [as 别名]
# 或者: from car.Car import speed [as 别名]
def test_calculate_not_slow_down_when_circling_the_road():
my_car = Car()
car_in_front = Car()
my_car.speed = 30
my_car.location = 980
car_in_front.speed = 25
car_in_front.location = 20
assert my_car.calculate_slow_down(car_in_front) == False
示例9: test_choose_speed_stop_please
# 需要导入模块: from car import Car [as 别名]
# 或者: from car.Car import speed [as 别名]
def test_choose_speed_stop_please():
test_road = Road(2)
test_car = Car(75)
test_car.speed = 12
test_car_two = Car(80)
test_car_two.speed = 2
td = test_road.set_tail_distance(test_car, test_car_two)
test_car.set_new_speed(test_car_two, td)
test_car.change_position()
test_road.check_end_of_lap(test_car)
test_car.check_position(test_car_two)
test_road.check_end_of_lap(test_car)
assert test_car.speed == 0
示例10: test_choose_speed_steady_fast
# 需要导入模块: from car import Car [as 别名]
# 或者: from car.Car import speed [as 别名]
def test_choose_speed_steady_fast():
test_road = Road(2)
test_car = Car()
test_car.speed = 10
test_car_two = Car(14)
test_car_two.speed = 12
td = test_road.set_tail_distance(test_car, test_car_two)
test_car.set_new_speed(test_car_two, td)
test_car.change_position()
test_road.check_end_of_lap(test_car)
test_car.check_position(test_car_two)
test_road.check_end_of_lap(test_car)
assert test_car.speed == 12
示例11: test_check_position_good
# 需要导入模块: from car import Car [as 别名]
# 或者: from car.Car import speed [as 别名]
def test_check_position_good():
test_car = Car(1)
test_car.speed = 5
test_car_two = Car(30)
assert test_car.car_coordinates[-1] == 5
assert test_car.speed == 5
test_car.check_position(test_car_two)
assert test_car.car_coordinates[-1] == 5
assert test_car.speed == 5
示例12: test_car_decelerate
# 需要导入模块: from car import Car [as 别名]
# 或者: from car.Car import speed [as 别名]
def test_car_decelerate():
road = Road()
car = Car(road)
assert car.speed == 15
car.decelerate()
assert car.speed == 13
car.speed = 1
car.decelerate()
assert car.speed == 0
示例13: test_check_position_bad
# 需要导入模块: from car import Car [as 别名]
# 或者: from car.Car import speed [as 别名]
def test_check_position_bad():
test_car = Car(27)
test_car.speed = 5
test_car_two = Car(30)
print(test_car_two.car_coordinates[0] - test_car.car_coordinates[-1] < 0)
print(test_car.car_coordinates[-1])
assert test_car.car_coordinates[-1] == 31
assert test_car.speed == 5
test_car.check_position(test_car_two)
assert test_car.car_coordinates[-1] == 29
assert test_car.speed == 0
示例14: test_road_curve
# 需要导入模块: from car import Car [as 别名]
# 或者: from car.Car import speed [as 别名]
def test_road_curve():
test_road = Road(2)
test_car = Car()
test_car.speed = 8
test_car_two = Car(20)
td = test_road.set_tail_distance(test_car, test_car_two)
test_car.set_new_speed(test_car_two, td)
test_car.change_position()
test_road.check_end_of_lap(test_car)
test_car.check_position(test_car_two)
test_road.check_end_of_lap(test_car)
assert test_car.speed == 10
示例15: test_car_slows_if_over_desired_speed
# 需要导入模块: from car import Car [as 别名]
# 或者: from car.Car import speed [as 别名]
def test_car_slows_if_over_desired_speed():
road = Road()
car1 = Car(road, init_speed=100, desired_speed=30)
car2 = Car(road, position=900)
with mock.patch("random.random", return_value=1):
# disable random braking
car1.brake_if_needed(leading_car=car2)
assert car1.speed == 30
with mock.patch("random.random", return_value=0.05):
# force random braking
car1.brake_if_needed(leading_car=car2)
assert car1.speed == 28
car1.speed = 100
car1.accelerate()
assert car1.speed == 30