From 4b1b4e8f05444f60bbd4e12392a6c921a7f21885 Mon Sep 17 00:00:00 2001 From: halilsen Date: Mon, 18 Oct 2021 11:34:19 +0200 Subject: [PATCH] Fix: assert handles empty quantity units correctly --- test/wrapper_test.rb | 17 +++++++++++++++++ wrappers/wrapper.rb | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/test/wrapper_test.rb b/test/wrapper_test.rb index c7b013775..5f168b011 100644 --- a/test/wrapper_test.rb +++ b/test/wrapper_test.rb @@ -3042,6 +3042,23 @@ def test_assert_applicable_for_vroom_if_initial_routes assert_empty OptimizerWrapper.config[:services][:vroom].inapplicable_solve?(vrp) end + def test_assert_can_handle_empty_quantities + problem = VRP.basic + problem[:relations] = [{ + type: :shipment, + linked_ids: ['service_1', 'service_2'] + }] + problem[:units] << { id: 'vol' } + problem[:vehicles].first[:capacities] = [{ unit_id: 'kg', limit: 2 }, { unit_id: 'vol', limit: 1 }] + problem[:services][0][:quantities] = [{ unit_id: 'kg', value: 1 }] + problem[:services][1][:quantities] = [{ unit_id: 'kg', value: -1 }] + problem[:services][2][:quantities] = [{ unit_id: 'vol', value: 1 }] + vrp = TestHelper.create(problem) + + OptimizerWrapper.config[:services][:vroom].inapplicable_solve?(vrp) + OptimizerWrapper.config[:services][:ortools].inapplicable_solve?(vrp) + end + def test_assert_inapplicable_relations problem = VRP.basic problem[:relations] = [{ diff --git a/wrappers/wrapper.rb b/wrappers/wrapper.rb index 6d71b5f10..7f41d42f0 100644 --- a/wrappers/wrapper.rb +++ b/wrappers/wrapper.rb @@ -155,7 +155,7 @@ def assert_no_relations_except_simple_shipments(vrp) r.linked_services.first.quantities.each{ |q| quantities[q.unit.id] << q.value } r.linked_services.last.quantities.each{ |q| quantities[q.unit.id] << q.value } quantities.all?{ |_unit, values| - [0, 2].include?(values.size) && values.first >= 0 && values.first == -values.last + values.empty? || (values.size == 2 && values.first >= 0 && values.first == -values.last) } } end