MCPcopy Create free account
hub / github.com/PyVRP/PyVRP / test_route_constructor_raises_too_many_vehicles

Function test_route_constructor_raises_too_many_vehicles

tests/test_Solution.py:141–188  ·  view source on GitHub ↗

Tests that constructing a solution with more routes than available in the data instance raises.

(ok_small)

Source from the content-addressed store, hash-verified

139
140
141def test_route_constructor_raises_too_many_vehicles(ok_small):
142 """
143 Tests that constructing a solution with more routes than available in the
144 data instance raises.
145 """
146 assert_equal(ok_small.num_vehicles, 3)
147
148 # Only two routes should not raise.
149 sol = Solution(ok_small, [[1, 2], [4, 3]])
150 assert_equal(len(sol.routes()), 2)
151
152 # Three routes should not raise.
153 Solution(ok_small, [[1, 2], [4], [3]])
154
155 # More than three routes should raise, since we only have three vehicles.
156 with assert_raises(RuntimeError):
157 Solution(ok_small, [[1], [2], [3], [4]])
158
159 # Now test the case with multiple vehicle types.
160 data = ok_small.replace(
161 vehicle_types=[
162 VehicleType(2, capacity=[10]),
163 VehicleType(capacity=[20]),
164 ]
165 )
166
167 # Only two routes (of type 0) should not raise.
168 sol = Solution(data, [[1, 2], [4, 3]])
169 assert_equal(len(sol.routes()), 2)
170
171 # One route of both vehicle types should not raise.
172 sol = Solution(data, [Route(data, [1, 2], 0), Route(data, [4, 3], 1)])
173 assert_equal(len(sol.routes()), 2)
174
175 # Two routes of type 1 and one of type 2 should not raise as we have those.
176 sol = Solution(
177 data,
178 [Route(data, [1], 0), Route(data, [2], 0), Route(data, [4, 3], 1)],
179 )
180 assert_equal(len(sol.routes()), 3)
181
182 # Two routes of vehicle type 1 should raise since we have only one.
183 with assert_raises(RuntimeError):
184 sol = Solution(data, [Route(data, [1, 2], 1), Route(data, [4, 3], 1)])
185
186 # Three routes should raise since they are considered to be type 0.
187 with assert_raises(RuntimeError):
188 Solution(data, [[1, 2], [4], [3]])
189
190
191def test_route_constructor_raises_for_multiple_visits(ok_small):

Callers

nothing calls this directly

Calls 4

SolutionClass · 0.90
VehicleTypeClass · 0.90
RouteClass · 0.90
replaceMethod · 0.80

Tested by

no test coverage detected