コード例 #1
0
def test_pack_updates_cargo() -> None:
    t = Truck(69, 420, "Toronto")
    p = Parcel(5, 186, "Markham", "Toronto")
    p2 = Parcel(6, 13, "Copenhagen", "Barrie")
    t.pack(p)
    t.pack(p2)
    assert t.cargo == [p, p2]
コード例 #2
0
def test_pack_updates_route_if_same_destination() -> None:
    t = Truck(69, 420, "Toronto")
    p = Parcel(5, 186, "Markham", "Oshawa")
    p2 = Parcel(6, 13, "Copenhagen", "Oshawa")
    t.pack(p)
    t.pack(p2)
    assert t.route == ["Toronto", "Oshawa"]
コード例 #3
0
def test_pack_updates_route() -> None:
    t = Truck(69, 420, "Toronto")
    p = Parcel(5, 186, "Markham", "Montreal")
    p2 = Parcel(6, 13, "Copenhagen", "Barrie")
    t.pack(p)
    t.pack(p2)
    assert t.route == ["Toronto", "Montreal", "Barrie"]
コード例 #4
0
def test_pack_same_dest() -> None:
    """Test if pack appends route iff the last city on route is different
    than the new parcel added."""
    t = Truck(1, 20, 'Depot')
    p = Parcel(1, 5, 'City n', 'City A')
    p2 = Parcel(2, 15, 'City n', 'City A')
    t.pack(p)
    t.pack(p2)
    assert t.route[1] == 'City A'
    assert len(t.route) == 2
コード例 #5
0
def test_parcel_allocations_doctest() -> None:
    """Test the doctest provided for Fleet.parcel_allocations"""
    f = Fleet()
    t1 = Truck(1423, 10, 'Toronto')
    p1 = Parcel(27, 5, 'Toronto', 'Hamilton')
    p2 = Parcel(12, 5, 'Toronto', 'Hamilton')
    assert t1.pack(p1) is True
    assert t1.pack(p2) is True
    t2 = Truck(1333, 10, 'Toronto')
    p3 = Parcel(28, 5, 'Toronto', 'Hamilton')
    assert t2.pack(p3) is True
    f.add_truck(t1)
    f.add_truck(t2)
    assert f.parcel_allocations() == {1423: [27, 12], 1333: [28]}
コード例 #6
0
def test_average_distance_travelled_doctest() -> None:
    """Test the doctest provided for Fleet.average_distance_travelled"""
    f = Fleet()
    t1 = Truck(1423, 10, 'Toronto')
    p1 = Parcel(1, 5, 'Toronto', 'Hamilton')
    assert t1.pack(p1) is True

    t2 = Truck(1333, 10, 'Toronto')
    p2 = Parcel(2, 5, 'Toronto', 'Hamilton')
    assert t2.pack(p2) is True

    m = DistanceMap()
    m.add_distance('Toronto', 'Hamilton', 9)
    f.add_truck(t1)
    f.add_truck(t2)
    assert f.average_distance_travelled(m) == 18.0
コード例 #7
0
def test_average_fullness_doctest() -> None:
    """Test the doctest provided for Fleet.average_fullness"""
    f = Fleet()
    t = Truck(1423, 10, 'Toronto')
    p = Parcel(1, 5, 'Buffalo', 'Hamilton')
    assert t.pack(p) is True

    f.add_truck(t)
    assert f.average_fullness() == 50.0
コード例 #8
0
def test_total_unused_space_doctest() -> None:
    """Test the doctest provided for Fleet.total_unused_space"""
    f = Fleet()
    assert f.total_unused_space() == 0

    t = Truck(1423, 1000, 'Toronto')
    p = Parcel(1, 5, 'Buffalo', 'Hamilton')
    assert t.pack(p) is True

    f.add_truck(t)
    assert f.total_unused_space() == 995
コード例 #9
0
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
コード例 #10
0
def test_absolute_fullness() -> None:
    t = Truck(69, 420, "Toronto")
    p = Parcel(1, 60, "Cape Town", "Barrie")
    t.pack(p)
    assert t.capacity - t.absolute_fullness() == 360
コード例 #11
0
def test_fullness() -> None:
    t = Truck(69, 420, "Toronto")
    p = Parcel(4, 42, "Cologne", "Barrie")
    t.pack(p)
    assert t.fullness() == (42 / 420) * 100
コード例 #12
0
def test_pack_underpack() -> None:
    t = Truck(69, 420, "Toronto")
    p = Parcel(3, 419, "Anchorage", "Barrie")
    assert t.pack(p) == True
コード例 #13
0
def test_pack_overpack() -> None:
    t = Truck(69, 420, "Toronto")
    p = Parcel(2, 430, "Rome", "Barrie")
    assert t.pack(p) == False
コード例 #14
0
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