Commit 5ced3c2d authored by Alexandre Delanoë's avatar Alexandre Delanoë

[FIX] Error Messages.

parent 4178a1b9
......@@ -78,23 +78,28 @@ ballots4 = [ Ballot "Fascism" (ratedAs [(90, Excellent)])
-- | Select the Winner
-- TODO: sortBy and intersect according to Result
-- sort then take While equality
winnerIs :: MajorityJudgment -> Either Text (Maybe Ballot)
winnerIs :: MajorityJudgment -> Either Unfair (Maybe Ballot)
winnerIs mj = case isFair mj of
False -> Left "Unfair Election"
True -> Right $ (headMay . reverse . sort) mj
Just unfair -> Left unfair
Nothing -> Right $ (headMay . reverse . sort) mj
data Unfair = NoChoice | NoRepresentativity
deriving (Show)
-- | Asserts is the Election with Majority Judgment is Fair
-- e.g. methodology of vote is respected to collect the ballots
-- Number of vote per Ballot must be equal
-- add an axiom: must not be Poor at least by one voter ?
-- TODO: be more explicit why election is not fair
isFair :: MajorityJudgment -> Bool
isFair mj = length vs > 2 && all (== head vs) vs
isFair :: MajorityJudgment -> Maybe Unfair
isFair mj = case length vs < 2 of
True -> Just NoChoice
False -> case all (== head vs) vs of
False -> Just NoRepresentativity
True -> Nothing
where
vs = map (length . votes) mj
data Unfair = NoChoice | NoRepresentativity
instance Eq Ballot where
......
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