Skip to content

Commit

Permalink
Test against Munkres.jl
Browse files Browse the repository at this point in the history
  • Loading branch information
Gnimuc committed Mar 5, 2020
1 parent 599b176 commit 73b70bc
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 11 deletions.
5 changes: 3 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
julia = "1.0.0"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Munkres = "4cefb923-2b6f-58c4-9e65-6821f26b7b51"
DelimitedFiles = "8bb1440f-4735-579b-a4ab-409b98df4dab"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Test", "DelimitedFiles"]
test = ["Test", "DelimitedFiles", "Munkres"]
41 changes: 32 additions & 9 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Hungarian
using Munkres
using Test
using LinearAlgebra
using DelimitedFiles
Expand All @@ -23,7 +24,7 @@ using DelimitedFiles
@test assign == [2, 1, 0, 0, 3]
@test cost == 8

assign, cost = hungarian(B')
assign, cost = hungarian(transpose(B))
@test assign == [2, 1, 5]
@test cost == 8

Expand Down Expand Up @@ -56,23 +57,45 @@ end
end

@testset "UInt16" begin
M=UInt16[28092 44837 19882 39481 59139;
26039 46258 38932 51057 9;
11527 59487 61993 29072 8734;
10691 16977 12796 16370 14266;
M=UInt16[28092 44837 19882 39481 59139;
26039 46258 38932 51057 9;
11527 59487 61993 29072 8734;
10691 16977 12796 16370 14266;
5199 42319 34194 41332 16472]
assign,cost=hungarian(M)
@test assign == [3, 5, 4, 2, 1]
@test cost == 71139
end

@testset "UInt8" begin
M=UInt8[67 228 135 197 244;
112 44 84 206 31;
225 103 231 225 227;
170 37 135 9 130;
M=UInt8[67 228 135 197 244;
112 44 84 206 31;
225 103 231 225 227;
170 37 135 9 130;
110 22 133 77 96]
assign,cost=hungarian(M)
@test assign == [1, 5, 2, 4, 3]
@test cost == 343
end

@testset "Munkres.jl" begin
A = rand(300, 300)
assignH, costH = hungarian(A)
assignM = munkres(A)

for i = 1:100
A = rand(50, 50)
assignH, costH = hungarian(A)
assignM = munkres(A)

costM = 0
for i in zip(1:size(A, 1), assignM)
if i[2] != 0
costM += A[i...]
end
end

@test assignH == assignM
@test costH == costM
end
end

0 comments on commit 73b70bc

Please sign in to comment.