Skip to content

Commit

Permalink
use correct rounding function in last biproporz step
Browse files Browse the repository at this point in the history
fix and test edge case bug
  • Loading branch information
polettif committed Mar 13, 2024
1 parent 894203e commit 185d66e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion R/biproportional.R
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ lower_apportionment = function(votes_matrix, seats_cols,
}

# create output
output = round(m.(M, dD, dP))
output = round_func(m.(M, dD, dP))
dimnames(output) <- dimnames(M)
attributes(output)$divisors <- list()
attributes(output)$divisors$districts <- dD
Expand Down
5 changes: 5 additions & 0 deletions tests/testthat/test-biproportional.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ test_that("lower apportionment", {
lower_apportionment(matrix(c(1,0,1,0), 2), c(1,1), c(2,0), method = "harmonic"),
'Lower apportionment is only guaranteed to terminate with the default Sainte-Lagu\u00EB/Webster method (method = "round")',
fixed = TRUE)

# exact 0.5 seats edge case
vm0.5 = matrix(c(10, 10, 20, 10), 2, 2)
sm0.5 = lower_apportionment(vm0.5, c(1, 1), c(1,1))
expect_equal(sum(sm0.5), 2)
})

test_that("biproporz", {
Expand Down

0 comments on commit 185d66e

Please sign in to comment.