Tests that route distance calculations are correct, and that the overall Solution's distance is the sum of the route distances.
(ok_small)
| 407 | |
| 408 | |
| 409 | def test_distance_calculation(ok_small): |
| 410 | """ |
| 411 | Tests that route distance calculations are correct, and that the overall |
| 412 | Solution's distance is the sum of the route distances. |
| 413 | """ |
| 414 | sol = Solution(ok_small, [[1, 2], [3], [4]]) |
| 415 | routes = sol.routes() |
| 416 | |
| 417 | # Solution is feasible, so all its routes should also be feasible. |
| 418 | assert_(sol.is_feasible()) |
| 419 | assert_(all(route.is_feasible() for route in routes)) |
| 420 | |
| 421 | # Solution distance should be equal to all routes' distances. These we |
| 422 | # check separately. |
| 423 | assert_equal(sol.distance(), sum(route.distance() for route in routes)) |
| 424 | |
| 425 | distances = ok_small.distance_matrix(profile=0) |
| 426 | expected = distances[0, 1] + distances[1, 2] + distances[2, 0] |
| 427 | assert_equal(routes[0].distance(), expected) |
| 428 | |
| 429 | expected = distances[0, 3] + distances[3, 0] |
| 430 | assert_equal(routes[1].distance(), expected) |
| 431 | |
| 432 | expected = distances[0, 4] + distances[4, 0] |
| 433 | assert_equal(routes[2].distance(), expected) |
| 434 | |
| 435 | |
| 436 | def test_excess_load_calculation(ok_small): |
nothing calls this directly
no test coverage detected