Commit 4178a1b9 authored by Alexandre Delanoë's avatar Alexandre Delanoë

more realistic example.

parent 4bc88295
...@@ -69,12 +69,21 @@ ballots3 :: MajorityJudgment ...@@ -69,12 +69,21 @@ ballots3 :: MajorityJudgment
ballots3 = [ Ballot "Dictatorship" (ratedAs [(1, Excellent)])] ballots3 = [ Ballot "Dictatorship" (ratedAs [(1, Excellent)])]
ballots4 :: MajorityJudgment ballots4 :: MajorityJudgment
ballots4 = [ Ballot "Dictatorship" (ratedAs [(100, Excellent)]) ballots4 = [ Ballot "Fascism" (ratedAs [(90, Excellent)])
, Ballot "Democracy" (ratedAs [(1, Excellent)]) , Ballot "Democracy" (ratedAs [(10, Excellent), (90, Poor)])
] ]
------------------------------------------------------------------------ ------------------------------------------------------------------------
-- | Select the Winner
-- TODO: sortBy and intersect according to Result
-- sort then take While equality
winnerIs :: MajorityJudgment -> Either Text (Maybe Ballot)
winnerIs mj = case isFair mj of
False -> Left "Unfair Election"
True -> Right $ (headMay . reverse . sort) mj
-- | Asserts is the Election with Majority Judgment is Fair -- | Asserts is the Election with Majority Judgment is Fair
-- e.g. methodology of vote is respected to collect the ballots -- e.g. methodology of vote is respected to collect the ballots
-- Number of vote per Ballot must be equal -- Number of vote per Ballot must be equal
...@@ -87,15 +96,6 @@ isFair mj = length vs > 2 && all (== head vs) vs ...@@ -87,15 +96,6 @@ isFair mj = length vs > 2 && all (== head vs) vs
data Unfair = NoChoice | NoRepresentativity data Unfair = NoChoice | NoRepresentativity
-- undefined -- all . map (length . votes)
-- | Select the Winner
-- TODO: sortBy and intersect according to Result
-- sort then take While equality
winnerIs :: MajorityJudgment -> Either Text (Maybe Ballot)
winnerIs mj = case isFair mj of
False -> Left "Unfair Election"
True -> Right $ (headMay . reverse . sort) mj
instance Eq Ballot where instance Eq Ballot where
(==) (Ballot _ v1) (Ballot _ v2) = (==) (score v1) (score v2) (==) (Ballot _ v1) (Ballot _ v2) = (==) (score v1) (score v2)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment