summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJed Barber <jjbarber@y7mail.com>2017-01-30 15:56:45 +1100
committerJed Barber <jjbarber@y7mail.com>2017-01-30 15:56:45 +1100
commit4387327f4c2ce91ecefa7fc45c7b5412aad67d07 (patch)
treef7ae3fb0afced99ca1b8a1bf6d3414336f71b4e7
parent64ccf6ef0aa18e898565ff59159dc8165a780f9d (diff)
Fixed off-by-2 bug with constructing SenateCounter object
-rw-r--r--notes.txt22
-rw-r--r--src/Counter.hs7
-rw-r--r--src/Election.hs1
-rw-r--r--src/Storage.hs8
4 files changed, 11 insertions, 27 deletions
diff --git a/notes.txt b/notes.txt
index e644ad7..ad1c527 100644
--- a/notes.txt
+++ b/notes.txt
@@ -1,27 +1,5 @@
-potential anomaly detected for
-
-Honan, Pat, NT
- AEC count 328
- my count 327
-
-Marshall, Tristan, NT
- AEC count 161
- my count 160
-
-Gallagher, Katy, ACT
- AEC count 95749
- my count 95748
-
-Seselja, Zed, ACT
- AEC count 82932
- my count 82931
-
-it's probably a programming error on my part
-
-
-
future direction
----------------
diff --git a/src/Counter.hs b/src/Counter.hs
index 0f3e0d9..bc23671 100644
--- a/src/Counter.hs
+++ b/src/Counter.hs
@@ -54,12 +54,15 @@ createSenateCounter f a b = do
let prefs = parseRawLine a b t0
result = Maybe.fromJust prefs
if (Maybe.isJust prefs)
- then Vec.setPrefs prefStore n result >> readFunc (n + 1) (p + 1)
+ then Vec.setPrefs prefStore (p + 1) result >> readFunc (n + 1) (p + 1)
else readFunc (n + 1) p
p <- readFunc 1 0
IO.hClose h
- return (SenateCounter prefStore b p)
+ return (SenateCounter
+ { prefData = prefStore
+ , ballotMap = b
+ , numBallots = p })
diff --git a/src/Election.hs b/src/Election.hs
index 582b29e..ff9706b 100644
--- a/src/Election.hs
+++ b/src/Election.hs
@@ -300,7 +300,6 @@ doVoteTransfer e = do
--- needs to properly mark the order that the last candidates were elected
-- needs to be modified to take into account ties
checkNoQuota :: Election -> ET.EitherT Election IO Election
checkNoQuota e = do
diff --git a/src/Storage.hs b/src/Storage.hs
index 295273b..be9b8af 100644
--- a/src/Storage.hs
+++ b/src/Storage.hs
@@ -28,7 +28,9 @@ data Store = Store
createStore :: Int -> Int -> IO Store
createStore maxCapacity ballotSize = do
v <- Vec.replicate (maxCapacity * ballotSize) 0
- return (Store v ballotSize)
+ return (Store
+ { getPointer = v
+ , getBallotSize = ballotSize })
@@ -42,7 +44,9 @@ setPref prefStore ballot (position,rank) = do
setPrefs :: Store -> Int -> [Preference] -> IO ()
-setPrefs prefStore ballot prefList =
+setPrefs prefStore ballot prefList = do
+ let blank = take (getBallotSize prefStore) (zip [1..] (cycle [0]))
+ mapM_ (setPref prefStore ballot) blank
mapM_ (setPref prefStore ballot) prefList