示例#1
0
文件: carTests.py 项目: bevzuk/cars
    def testCanGetDistanceToPreviousCar(self):
        car = Car(radius=100, alpha=0)
        anotherCar = Car(radius=100, alpha=math.pi / 2)

        car.previous_car = anotherCar

        self.assertAlmostEqual(100 * math.sqrt(2), car.distance_to_previous_car)
示例#2
0
文件: carTests.py 项目: bevzuk/cars
    def testAccelerateWhenDistanceToPreviousCarIsBig(self):
        car = Car(radius=100, alpha=0, speed=1, speed_limit=2)
        anotherCar = Car(radius=100, alpha=math.pi, speed=1)
        car.previous_car = anotherCar

        car.move()

        self.assertAlmostEqual(1.2, car.speed)
示例#3
0
文件: carTests.py 项目: bevzuk/cars
    def testDecelerateWhenDistanceToPreviousCarIsSmall(self):
        car = Car(radius=100, alpha=0, speed=0.1)
        anotherCar = Car(radius=100, alpha=0.5, speed=0.1)
        car.previous_car = anotherCar

        car.move()

        self.assertAlmostEqual(0.08, car.speed)
示例#4
0
文件: carTests.py 项目: bevzuk/cars
    def testStopWhenCrash(self):
        car = Car(radius=100, alpha=0, speed=1)
        anotherCar = Car(radius=100, alpha=0.01, speed=1)
        car.previous_car = anotherCar

        car.move()

        self.assertAlmostEqual(0, car.speed)
示例#5
0
    def testAccelerateWhenDistanceToPreviousCarIsBig(self):
        car = Car(radius=100, alpha=0, speed=1, speed_limit=2)
        anotherCar = Car(radius=100, alpha=math.pi, speed=1)
        car.previous_car = anotherCar

        car.move()

        self.assertAlmostEqual(1.2, car.speed)
示例#6
0
    def testDecelerateWhenDistanceToPreviousCarIsSmall(self):
        car = Car(radius=100, alpha=0, speed=0.1)
        anotherCar = Car(radius=100, alpha=0.5, speed=0.1)
        car.previous_car = anotherCar

        car.move()

        self.assertAlmostEqual(0.08, car.speed)
示例#7
0
    def testCanGetDistanceToPreviousCar(self):
        car = Car(radius=100, alpha=0)
        anotherCar = Car(radius=100, alpha=math.pi / 2)

        car.previous_car = anotherCar

        self.assertAlmostEqual(100 * math.sqrt(2),
                               car.distance_to_previous_car)
示例#8
0
    def testStopWhenCrash(self):
        car = Car(radius=100, alpha=0, speed=1)
        anotherCar = Car(radius=100, alpha=0.01, speed=1)
        car.previous_car = anotherCar

        car.move()

        self.assertAlmostEqual(0, car.speed)