コード例 #1
0
 def drive(self, destination: Point) -> None:
     distance: float = destination.distance(self.location)
     fuel_needed: float = distance * self.fuel_consumption
     if fuel_needed > self.fuel_amount:
         raise OutOfFuel
     self.location = destination
     self.fuel_amount -= fuel_needed
コード例 #2
0
    def test_point_distance(self):
        p1 = Point(2, 5)
        p2 = Point(2, 5)
        p3 = Point(10, 9)

        self.assertEqual(p1.distance(p2), 0.0)
        self.assertEqual(p1.distance(p3), round(8.94427190999916, 2))
コード例 #3
0
def test_point_distance():
    a = Point()
    b = Point(10, 10)

    distance = a.distance(b)

    assert distance == 14.142135623730951
コード例 #4
0
def test_point_exception():
    with pytest.raises(TypeError):
        p1 = Point()
        p1.distance(dir)
コード例 #5
0
def test_point_distance():
    p1 = Point()
    p2 = Point(2, 4)

    assert p1.distance(p2) == 4.47213595499958
コード例 #6
0
def test_distance():
    p1 = Point()
    p2 = Point(2.0, 4.0)

    assert p1.distance(p2) == 3.1622776601683795
コード例 #7
0
    def test_raises(self):
        point = Point()

        with self.assertRaises(TypeError):
            point.distance(10)