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

Function test_matrices_are_not_writeable

tests/test_ProblemData.py:434–458  ·  view source on GitHub ↗

Tests that the data matrices provided by ``distance_matrix()`` and ``duration_matrix()`` are not writeable. They can be read from, but assigning new values should raise an error. We require this because they're constant on the C++ side, and allowing changes from Python causes u

()

Source from the content-addressed store, hash-verified

432
433
434def test_matrices_are_not_writeable():
435 """
436 Tests that the data matrices provided by ``distance_matrix()`` and
437 ``duration_matrix()`` are not writeable. They can be read from, but
438 assigning new values should raise an error.
439
440 We require this because they're constant on the C++ side, and allowing
441 changes from Python causes undefined behaviour on the C++ side.
442 """
443 data = ProblemData(
444 clients=[],
445 depots=[Depot(x=0, y=0)],
446 vehicle_types=[VehicleType(2)],
447 distance_matrices=[np.array([[0]])],
448 duration_matrices=[np.array([[0]])],
449 )
450
451 dist_mat = data.distance_matrix(profile=0)
452 dur_mat = data.duration_matrix(profile=0)
453
454 with assert_raises(ValueError):
455 dist_mat[0, 0] = 1_000
456
457 with assert_raises(ValueError):
458 dur_mat[0, 0] = 1_000
459
460
461def test_matrices_are_not_copies():

Callers

nothing calls this directly

Calls 3

ProblemDataClass · 0.90
DepotClass · 0.90
VehicleTypeClass · 0.90

Tested by

no test coverage detected