MCPcopy Index your code
hub / github.com/PyVRP/PyVRP / test_problem_data_replace_with_changes

Function test_problem_data_replace_with_changes

tests/test_ProblemData.py:325–366  ·  view source on GitHub ↗

Tests that when calling ``ProblemData.replace()`` indeed replaces the data values with those passed to the method.

()

Source from the content-addressed store, hash-verified

323
324
325def test_problem_data_replace_with_changes():
326 """
327 Tests that when calling ``ProblemData.replace()`` indeed replaces the
328 data values with those passed to the method.
329 """
330 clients = [Client(x=0, y=0, delivery=[0])]
331 depots = [Depot(x=0, y=0)]
332 vehicle_types = [VehicleType(2, capacity=[1])]
333 mat = np.zeros((2, 2), dtype=int)
334 original = ProblemData(clients, depots, vehicle_types, [mat], [mat])
335
336 # Let's replace the clients, vehicle types, and the distance matrix, each
337 # with different values than in the original data. The duration matrix
338 # is left unchanged.
339 new = original.replace(
340 clients=[Client(x=1, y=1, delivery=[0])],
341 vehicle_types=[VehicleType(3, [4]), VehicleType(5, [6])],
342 distance_matrices=[np.where(np.eye(2), 0, 2)],
343 )
344
345 assert_(new is not original)
346 assert_(new.location(1) is not original.location(1))
347 assert_(new.location(1).x != original.location(1).x)
348 assert_(new.location(1).y != original.location(1).y)
349
350 for idx in range(original.num_vehicle_types): # only compare first type
351 new_veh_type = new.vehicle_type(idx)
352 orig_veh_type = original.vehicle_type(idx)
353
354 assert_(new_veh_type is not orig_veh_type)
355 assert_(new_veh_type.capacity != orig_veh_type.capacity)
356 assert_(new_veh_type.num_available != orig_veh_type.num_available)
357
358 assert_(new.distance_matrix(0) is not original.distance_matrix(0))
359 with assert_raises(AssertionError):
360 assert_equal(new.distance_matrix(0), original.distance_matrix(0))
361
362 assert_(new.duration_matrix(0) is not original.duration_matrix(0))
363 assert_equal(new.duration_matrix(0), original.duration_matrix(0))
364
365 assert_equal(new.num_clients, original.num_clients)
366 assert_(new.num_vehicle_types != original.num_vehicle_types)
367
368
369def test_problem_data_replace_raises_mismatched_argument_shapes():

Callers

nothing calls this directly

Calls 6

locationMethod · 0.95
ClientClass · 0.90
DepotClass · 0.90
VehicleTypeClass · 0.90
ProblemDataClass · 0.90
replaceMethod · 0.80

Tested by

no test coverage detected