Skip to content

Commit

Permalink
Fix: assert handles empty quantity units correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
senhalil committed Oct 18, 2021
1 parent e94ee9b commit b8a8ff9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
17 changes: 17 additions & 0 deletions test/wrapper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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] = [{
Expand Down
2 changes: 1 addition & 1 deletion wrappers/wrapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,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
Expand Down

0 comments on commit b8a8ff9

Please sign in to comment.