Skip to content

Commit

Permalink
Closes #5: Testing negative weights and profits.
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelmartinelli committed May 27, 2021
1 parent 4940a1f commit 4885965
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/Data.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ function checkConsistency(items::Vector{KnapItem})
negative = false
for item in items
large = large || (abs(item.weight) >= limit)
negative = negative || (item.weight < 0)
negative = negative || (item.weight < 0) || (item.profit < 0)
end

if large @warn "Large numbers may result in an overflow, leading to an undefined behavior." end
if negative @warn "Negative weights are not allowed, leading to an undefined behavior." end
if negative @warn "Negative weights or profits are not allowed, leading to an undefined behavior." end
end
3 changes: 2 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ end
end

@testset "DataNegative" begin
msg = "Negative weights are not allowed, leading to an undefined behavior."
msg = "Negative weights or profits are not allowed, leading to an undefined behavior."
@test_logs (:warn, msg) data = KnapData(1, [ -1 ], [ 1 ])
@test_logs (:warn, msg) data = KnapData(1, [ 1 ], [ -1 ])
end

@testset "DataItEmpty" begin
Expand Down

0 comments on commit 4885965

Please sign in to comment.