def test_num_nonempty_trucks_doctest() -> None: """Test the doctest provided for Fleet.num_nonempty_trucks""" f = Fleet() t1 = Truck(1423, 10, 'Toronto') f.add_truck(t1) p1 = Parcel(1, 5, 'Buffalo', 'Hamilton') assert t1.pack(p1) is True p2 = Parcel(2, 4, 'Toronto', 'Montreal') assert t1.pack(p2) is True assert t1.fullness() == 90.0 t2 = Truck(5912, 20, 'Toronto') f.add_truck(t2) p3 = Parcel(3, 2, 'New York', 'Windsor') assert t2.pack(p3) is True assert t2.fullness() == 10.0 t3 = Truck(1111, 50, 'Toronto') f.add_truck(t3) assert f.num_nonempty_trucks() == 2
def test_fullness() -> None: t = Truck(69, 420, "Toronto") p = Parcel(4, 42, "Cologne", "Barrie") t.pack(p) assert t.fullness() == (42 / 420) * 100
def test_rational_float() -> None: """Test if fullness round to one decimal place.""" t = Truck(1, 3, 'Depot') p = Parcel(1, 1, 'City n', 'aCity A') t.pack(p) assert t.fullness() == 33.3