X-Git-Url: https://git.auder.net/?p=morpheus.git;a=blobdiff_plain;f=pkg%2Ftests%2Ftestthat%2Ftest-hungarianAlgorithm.R;h=591c3c1e673147742b6b0bd8a1c969b464e47d32;hp=90cb02f1356b90a2be75654bbe37d171ef40e37d;hb=6dd5c2acccd10635449230faa824b7e8906911bf;hpb=bbdcfe44da4011574dabb19b4f83e2ab199c667a diff --git a/pkg/tests/testthat/test-hungarianAlgorithm.R b/pkg/tests/testthat/test-hungarianAlgorithm.R index 90cb02f..591c3c1 100644 --- a/pkg/tests/testthat/test-hungarianAlgorithm.R +++ b/pkg/tests/testthat/test-hungarianAlgorithm.R @@ -2,23 +2,23 @@ context("hungarianAlgorithm") test_that("HungarianAlgorithm provides the correct answer on various inputs", { - for (n in c(2,3,10,50)) - { - for (repetition in 1:3) - { - # Generate a random vector, and permute it: - # we expect the algorithm to retrieve the permutation - v = runif(n, min=-1, max=1) - permutation = sample(1:n) - v_p = v[permutation] + for (n in c(2,3,10,50)) + { + for (repetition in 1:3) + { + # Generate a random vector, and permute it: + # we expect the algorithm to retrieve the permutation + v = runif(n, min=-1, max=1) + permutation = sample(1:n) + v_p = v[permutation] - # v is reference, v_p is v after permutation - # distances[i,j] = distance between i-th component of v and j-th component of v_p - # "in rows : reference; in columns: after permutation" - # "permutation" contains order on v to match v_p as closely as possible - distances = sapply(v_p, function(elt) ( abs(elt - v) ) ) - assignment = .hungarianAlgorithm(distances) - expect_equal(assignment, permutation) - } - } + # v is reference, v_p is v after permutation + # distances[i,j] = distance between i-th component of v and j-th component of v_p + # "in rows : reference; in columns: after permutation" + # "permutation" contains order on v to match v_p as closely as possible + distances = sapply(v_p, function(elt) ( abs(elt - v) ) ) + assignment = .hungarianAlgorithm(distances) + expect_equal(assignment, permutation) + } + } })