diff options
author | Jed Barber <jjbarber@y7mail.com> | 2017-01-30 15:56:45 +1100 |
---|---|---|
committer | Jed Barber <jjbarber@y7mail.com> | 2017-01-30 15:56:45 +1100 |
commit | 4387327f4c2ce91ecefa7fc45c7b5412aad67d07 (patch) | |
tree | f7ae3fb0afced99ca1b8a1bf6d3414336f71b4e7 /src | |
parent | 64ccf6ef0aa18e898565ff59159dc8165a780f9d (diff) |
Fixed off-by-2 bug with constructing SenateCounter object
Diffstat (limited to 'src')
-rw-r--r-- | src/Counter.hs | 7 | ||||
-rw-r--r-- | src/Election.hs | 1 | ||||
-rw-r--r-- | src/Storage.hs | 8 |
3 files changed, 11 insertions, 5 deletions
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 |