public void SingleNameElection_3_people_with_3_way_Tie() { new Election { NumberToElect = 1, NumberExtra = 0 }.ForTests(); var ballots = new[] { new Ballot().ForTests() }; var votes = new[] { new Vote { SingleNameElectionCount = 10 }.ForTests(ballots[0], SamplePeople[0]), new Vote { SingleNameElectionCount = 10 }.ForTests(ballots[0], SamplePeople[1]), new Vote { SingleNameElectionCount = 10 }.ForTests(ballots[0], SamplePeople[2]), }; var model = new ElectionAnalyzerSingleName(_fakes); //election, votes, ballots, SamplePeople); model.AnalyzeEverything(); var results = model.Results.OrderBy(r => r.Rank).ToList(); results.Count.ShouldEqual(3); var result1 = results[0]; result1.VoteCount.ShouldEqual(10); result1.Rank.ShouldEqual(1); result1.Section.ShouldEqual(ResultHelper.Section.Top); result1.IsTied.ShouldEqual(true); result1.TieBreakGroup.ShouldEqual(1); var result2 = results[1]; result2.VoteCount.ShouldEqual(10); result2.Rank.ShouldEqual(2); result2.Section.ShouldEqual(ResultHelper.Section.Other); result2.IsTied.ShouldEqual(true); result2.TieBreakGroup.ShouldEqual(1); var result3 = results[2]; result3.VoteCount.ShouldEqual(10); result3.Rank.ShouldEqual(3); result3.Section.ShouldEqual(ResultHelper.Section.Other); result3.IsTied.ShouldEqual(true); result3.TieBreakGroup.ShouldEqual(1); }
public void SingleNameElection_1_person() { new Election { NumberToElect = 1, NumberExtra = 0 }.ForTests(); var ballots = new[] { new Ballot().ForTests() }; var votes = new[] { // all for one person in this test new Vote { SingleNameElectionCount = 33 }.ForTests(ballots[0], SamplePeople[0]), new Vote { SingleNameElectionCount = 5 }.ForTests(ballots[0], SamplePeople[0]), new Vote { SingleNameElectionCount = 2 }.ForTests(ballots[0], SamplePeople[0]), }; var model = new ElectionAnalyzerSingleName(_fakes); //election, votes, ballots, SamplePeople); model.AnalyzeEverything(); var results = model.Results.OrderBy(r => r.Rank).ToList(); results.Count.ShouldEqual(1); var result1 = results[0]; result1.VoteCount.ShouldEqual(33 + 5 + 2); result1.Rank.ShouldEqual(1); result1.Section.ShouldEqual(ResultHelper.Section.Top); result1.CloseToNext.ShouldEqual(false); result1.CloseToPrev.ShouldEqual(false); result1.ForceShowInOther.ShouldEqual(false); result1.IsTieResolved.ShouldEqual(null); result1.IsTied.ShouldEqual(false); result1.RankInExtra.ShouldEqual(null); result1.TieBreakCount.ShouldEqual(null); result1.TieBreakGroup.ShouldEqual(null); result1.TieBreakRequired.ShouldEqual(false); }
public void Election_3_people() { new Election { NumberToElect = 1, NumberExtra = 0 }.ForTests(); var ballots = new[] { new Ballot().ForTests(), new Ballot().ForTests(), new Ballot().ForTests(), }; var votes = new[] { new Vote { SingleNameElectionCount = 33 }.ForTests(ballots[0], SamplePeople[0]), new Vote { SingleNameElectionCount = 5 }.ForTests(ballots[1], SamplePeople[0]), new Vote { SingleNameElectionCount = 2 }.ForTests(ballots[2], SamplePeople[1]), }; var model = new ElectionAnalyzerSingleName(_fakes); //, election, votes, ballots, SamplePeople); model.AnalyzeEverything(); var results = model.Results.OrderBy(r => r.Rank).ToList(); results.Count.ShouldEqual(2); var result1 = results[0]; result1.VoteCount.ShouldEqual(38); result1.Rank.ShouldEqual(1); result1.Section.ShouldEqual(ResultHelper.Section.Top); result1.IsTied.ShouldEqual(false); var result2 = results[1]; result2.VoteCount.ShouldEqual(2); result2.Rank.ShouldEqual(2); result2.Section.ShouldEqual(ResultHelper.Section.Other); result2.IsTied.ShouldEqual(false); }
public void Invalid_People_Do_Not_Affect_Results() { new Election { NumberToElect = 1, NumberExtra = 0 }.ForTests(); var ballots = new[] { new Ballot().ForTests(), new Ballot().ForTests(), new Ballot().ForTests(), }; SamplePeople[5].IneligibleReasonGuid = IneligibleReasonEnum.Ineligible_Deceased; new PeopleModel().ApplyVoteReasonFlags(SamplePeople[5]); var votes = new[] { new Vote { SingleNameElectionCount = 33 }.ForTests(ballots[0], SamplePeople[0]), new Vote { SingleNameElectionCount = 5 }.ForTests(ballots[0], SamplePeople[1]), new Vote { SingleNameElectionCount = 5 }.ForTests(ballots[0], SamplePeople[2]), new Vote { SingleNameElectionCount = 5 }.ForTests(ballots[0], SamplePeople[3]), new Vote { SingleNameElectionCount = 27 }.ForTests(ballots[1], SamplePeople[5]), // spoiled person new Vote { SingleNameElectionCount = 27 }.ForTests(ballots[1], new Person { FirstName = "z2", IneligibleReasonGuid = IneligibleReasonEnum.Ineligible_Other }.ForTests()), // spoiled new Vote { SingleNameElectionCount = 27 }.ForTests(ballots[2], SamplePeople[4]), // #6 - will be Needs Review }; votes[6].PersonCombinedInfo = "different"; // force a Review var model = new ElectionAnalyzerSingleName(_fakes); //election, voteInfos, ballots, SamplePeople); model.AnalyzeEverything(); var results = model.Results.OrderBy(r => r.Rank).ToList(); var resultTies = model.ResultTies.OrderBy(rt => rt.TieBreakGroup).ToList(); resultTies.Count.ShouldEqual(1); resultTies[0].TieBreakRequired.ShouldEqual(false); resultTies[0].NumToElect.ShouldEqual(0); resultTies[0].NumInTie.ShouldEqual(3); var summary = model.ResultSummaryFinal; summary.BallotsNeedingReview.ShouldEqual(1); summary.SpoiledBallots.ShouldEqual(1); summary.SpoiledVotes.ShouldEqual(27 + 27); summary.SumOfEnvelopesCollected.ShouldEqual(1); // sample data has 1 voting method summary.BallotsReceived.ShouldEqual(33 + 5 + 5 + 5 + 27 + 27 + 27); summary.NumBallotsWithManual.ShouldEqual(1 + 33 + 5 + 5 + 5 + 27 + 27 + 27); results.Count.ShouldEqual(4); var result1 = results[0]; result1.VoteCount.ShouldEqual(33); result1.Section.ShouldEqual(ResultHelper.Section.Top); result1.IsTied.ShouldEqual(false); result1.TieBreakRequired = false; var result2 = results[1]; result2.VoteCount.ShouldEqual(5); result2.Section.ShouldEqual(ResultHelper.Section.Other); result2.IsTied.ShouldEqual(true); result2.TieBreakRequired = false; result2.ForceShowInOther = false; var result3 = results[2]; result3.VoteCount.ShouldEqual(5); result3.Section.ShouldEqual(ResultHelper.Section.Other); result3.IsTied.ShouldEqual(true); result3.TieBreakRequired = false; result3.ForceShowInOther = false; }
public void Invalid_Ballots_Affect_Results() { new Election { NumberToElect = 1, NumberExtra = 0 }.ForTests(); var ballots = new[] { new Ballot().ForTests(), new Ballot().ForTests(), new Ballot().ForTests(BallotStatusEnum.TooFew), }; // TODO 2012-03-24 Glen Little: Needs attention... these test are for normal elections, not single name... var votes = new[] { new Vote() { SingleNameElectionCount = 33 }.ForTests(ballots[0], SamplePeople[0]), new Vote() { SingleNameElectionCount = 5 }.ForTests(ballots[0], SamplePeople[1]), new Vote() { SingleNameElectionCount = 2 }.ForTests(ballots[0], SamplePeople[2]), new Vote() { SingleNameElectionCount = 4 }.ForTests(ballots[1], SamplePeople[3]), new Vote() { SingleNameElectionCount = 27 }.ForTests(ballots[0], SamplePeople[4]), new Vote() { SingleNameElectionCount = 27 }.ForTests(ballots[0], SamplePeople[5]), // 5 - will require review new Vote() { SingleNameElectionCount = 27 }.ForTests(ballots[0], new Person { FirstName = "z1", IneligibleReasonGuid = IneligibleReasonEnum.Ineligible_Other }.ForTests()), }; votes[5].PersonCombinedInfo = "different"; // these will be invalid //votes[6].PersonIneligibleReasonGuid = IneligibleReasonEnum.Ineligible_Other; //votes[6].PersonCanReceiveVotes = IneligibleReasonEnum.Ineligible_Other.CanReceiveVotes; var model = new ElectionAnalyzerSingleName(_fakes); //election, voteinfos, ballots, SamplePeople); model.AnalyzeEverything(); var results = model.Results.OrderBy(r => r.Rank).ToList(); ballots[0].StatusCode.ShouldEqual(BallotStatusEnum.Verify); ballots[1].StatusCode.ShouldEqual(BallotStatusEnum.Ok); var summary = model.ResultSummaryFinal; summary.SpoiledBallots.ShouldEqual(1); summary.BallotsNeedingReview.ShouldEqual(1); summary.SpoiledVotes.ShouldEqual(0); // all are on the spoiled ballot results.Count.ShouldEqual(5); }
public void Election_3_people_With_Manual_Results() { new Election { NumberToElect = 1, NumberExtra = 0 }.ForTests(); var ballots = new[] { new Ballot().ForTests(), new Ballot().ForTests(), new Ballot().ForTests(), }; var votes = new[] { new Vote { SingleNameElectionCount = 33 }.ForTests(ballots[0], SamplePeople[0]), new Vote { SingleNameElectionCount = 5 }.ForTests(ballots[1], SamplePeople[0]), new Vote { SingleNameElectionCount = 2 }.ForTests(ballots[2], SamplePeople[1]), }; new ResultSummary { ResultType = ResultType.Manual, SpoiledManualBallots = 1 // override the real count }.ForTests(); var model = new ElectionAnalyzerSingleName(_fakes); //, election, votes, ballots, SamplePeople); model.AnalyzeEverything(); var resultSummaryFinal = model.ResultSummaryFinal; resultSummaryFinal.BallotsNeedingReview.ShouldEqual(0); resultSummaryFinal.NumBallotsWithManual.ShouldEqual(41); resultSummaryFinal.DroppedOffBallots.ShouldEqual(0); resultSummaryFinal.InPersonBallots.ShouldEqual(1); resultSummaryFinal.MailedInBallots.ShouldEqual(0); resultSummaryFinal.CalledInBallots.ShouldEqual(0); resultSummaryFinal.OnlineBallots.ShouldEqual(0); resultSummaryFinal.NumEligibleToVote.ShouldEqual(8); resultSummaryFinal.NumVoters.ShouldEqual(40); resultSummaryFinal.ResultType.ShouldEqual(ResultType.Final); var results = model.Results.OrderBy(r => r.Rank).ToList(); results.Count.ShouldEqual(2); var result1 = results[0]; result1.VoteCount.ShouldEqual(38); result1.Rank.ShouldEqual(1); result1.Section.ShouldEqual(ResultHelper.Section.Top); result1.IsTied.ShouldEqual(false); var result2 = results[1]; result2.VoteCount.ShouldEqual(2); result2.Rank.ShouldEqual(2); result2.Section.ShouldEqual(ResultHelper.Section.Other); result2.IsTied.ShouldEqual(false); }
public void SingleNameElection_1_person() { var electionGuid = Guid.NewGuid(); var election = new Election { ElectionGuid = electionGuid, NumberToElect = 1, NumberExtra = 0 }; var location = new Location { LocationGuid = Guid.NewGuid(), ElectionGuid = electionGuid }; var personGuid = Guid.NewGuid(); var ballotGuid = Guid.NewGuid(); var ballots = new List<Ballot> { new Ballot {LocationGuid = location.LocationGuid, BallotGuid = ballotGuid, StatusCode = BallotStatusEnum.Ok} }; var votes = new List<vVoteInfo> { new vVoteInfo {SingleNameElectionCount = 33}, new vVoteInfo {SingleNameElectionCount = 5}, new vVoteInfo {SingleNameElectionCount = 2}, }; foreach (var vVoteInfo in votes) { vVoteInfo.BallotGuid = ballotGuid; vVoteInfo.PersonGuid = personGuid; // all for one person in this test vVoteInfo.ElectionGuid = electionGuid; vVoteInfo.PersonCombinedInfo = vVoteInfo.PersonCombinedInfoInVote = "zz"; vVoteInfo.BallotStatusCode = BallotStatusEnum.Ok; vVoteInfo.VoteStatusCode = VoteHelper.VoteStatusCode.Ok; } var model = new ElectionAnalyzerSingleName(_fakes, election, votes, ballots, SamplePeople); model.GenerateResults(); var results = model.Results; results.Count.ShouldEqual(1); var result1 = results[0]; result1.VoteCount.ShouldEqual(33 + 5 + 2); result1.Rank.ShouldEqual(1); result1.Section.ShouldEqual(ResultHelper.Section.Top); result1.CloseToNext.ShouldEqual(false); result1.CloseToPrev.ShouldEqual(false); result1.ForceShowInOther.ShouldEqual(false); result1.IsTieResolved.ShouldEqual(null); result1.IsTied.ShouldEqual(false); result1.RankInExtra.ShouldEqual(null); result1.TieBreakCount.ShouldEqual(null); result1.TieBreakGroup.ShouldEqual(null); result1.TieBreakRequired.ShouldEqual(false); }
public void SingleNameElection_3_people_with_3_way_Tie() { var electionGuid = Guid.NewGuid(); var election = new Election { ElectionGuid = electionGuid, NumberToElect = 1, NumberExtra = 0 }; var location = new Location { LocationGuid = Guid.NewGuid(), ElectionGuid = electionGuid }; var ballotGuid = Guid.NewGuid(); var ballots = new List<Ballot> { new Ballot {LocationGuid = location.LocationGuid, BallotGuid = ballotGuid, StatusCode = BallotStatusEnum.Ok} }; var votes = new List<vVoteInfo> { new vVoteInfo {SingleNameElectionCount = 10, PersonGuid = Guid.NewGuid()}, new vVoteInfo {SingleNameElectionCount = 10, PersonGuid = Guid.NewGuid()}, new vVoteInfo {SingleNameElectionCount = 10, PersonGuid = Guid.NewGuid()}, }; foreach (var vVoteInfo in votes) { vVoteInfo.BallotGuid = ballotGuid; vVoteInfo.ElectionGuid = electionGuid; vVoteInfo.PersonCombinedInfo = vVoteInfo.PersonCombinedInfoInVote = "zz"; vVoteInfo.BallotStatusCode = BallotStatusEnum.Ok; vVoteInfo.VoteStatusCode = VoteHelper.VoteStatusCode.Ok; } var model = new ElectionAnalyzerSingleName(_fakes, election, votes, ballots, SamplePeople); model.GenerateResults(); var results = model.Results.OrderByDescending(r => r.VoteCount).ToList(); results.Count.ShouldEqual(3); var result1 = results[0]; result1.VoteCount.ShouldEqual(10); result1.Rank.ShouldEqual(1); result1.Section.ShouldEqual(ResultHelper.Section.Top); result1.IsTied.ShouldEqual(true); result1.TieBreakGroup.ShouldEqual(1); var result2 = results[1]; result2.VoteCount.ShouldEqual(10); result2.Rank.ShouldEqual(2); result2.Section.ShouldEqual(ResultHelper.Section.Other); result2.IsTied.ShouldEqual(true); result2.TieBreakGroup.ShouldEqual(1); var result3 = results[2]; result3.VoteCount.ShouldEqual(10); result3.Rank.ShouldEqual(3); result3.Section.ShouldEqual(ResultHelper.Section.Other); result3.IsTied.ShouldEqual(true); result3.TieBreakGroup.ShouldEqual(1); }
public void Invalid_People_Do_Not_Affect_Results() { var electionGuid = Guid.NewGuid(); var election = new Election { ElectionGuid = electionGuid, NumberToElect = 1, NumberExtra = 0 }; var location = new Location { LocationGuid = Guid.NewGuid(), ElectionGuid = electionGuid }; var ballots = new List<Ballot> { new Ballot {LocationGuid = location.LocationGuid, BallotGuid = Guid.NewGuid(), StatusCode = BallotStatusEnum.Ok}, new Ballot {LocationGuid = location.LocationGuid, BallotGuid = Guid.NewGuid(), StatusCode = BallotStatusEnum.Ok}, }; var voteInfos = new List<vVoteInfo> { new vVoteInfo {SingleNameElectionCount = 33, BallotGuid = ballots[0].BallotGuid}, new vVoteInfo {SingleNameElectionCount = 5, BallotGuid = ballots[0].BallotGuid}, new vVoteInfo {SingleNameElectionCount = 5, BallotGuid = ballots[0].BallotGuid}, new vVoteInfo {SingleNameElectionCount = 5, BallotGuid = ballots[0].BallotGuid}, new vVoteInfo {SingleNameElectionCount = 27, BallotGuid = ballots[1].BallotGuid}, new vVoteInfo {SingleNameElectionCount = 27, BallotGuid = ballots[1].BallotGuid},// spoiled new vVoteInfo {SingleNameElectionCount = 27, BallotGuid = ballots[1].BallotGuid},// spoiled }; var rowId = 1; foreach (var voteInfo in voteInfos) { voteInfo.VoteId = rowId++; voteInfo.ElectionGuid = electionGuid; voteInfo.PersonCombinedInfo = voteInfo.PersonCombinedInfoInVote = "zz"; voteInfo.BallotStatusCode = BallotStatusEnum.Ok; voteInfo.VoteStatusCode = VoteHelper.VoteStatusCode.Ok; voteInfo.PersonGuid = Guid.NewGuid(); } voteInfos[3].VoteStatusCode = VoteHelper.VoteStatusCode.Changed; voteInfos[4].BallotStatusCode = "TooFew"; // will be reset to Okay voteInfos[5].PersonCombinedInfo = "different"; voteInfos[6].PersonIneligibleReasonGuid = Guid.NewGuid(); var model = new ElectionAnalyzerSingleName(_fakes, election, voteInfos, ballots, SamplePeople); model.GenerateResults(); var results = model.Results.OrderByDescending(r => r.VoteCount).ToList(); var resultTies = model.ResultTies.OrderBy(rt => rt.TieBreakGroup).ToList(); resultTies.Count.ShouldEqual(1); resultTies[0].TieBreakRequired.ShouldEqual(false); resultTies[0].NumToElect.ShouldEqual(0); resultTies[0].NumInTie.ShouldEqual(3); var summary = model.ResultSummaryAuto; summary.BallotsNeedingReview.ShouldEqual(1); summary.TotalVotes.ShouldEqual(33 + 5 + 5 + 5 + 27 + 27 + 27); summary.SpoiledBallots.ShouldEqual(0); summary.SpoiledVotes.ShouldEqual(27+27); results.Count.ShouldEqual(5); var result1 = results[0]; result1.VoteCount.ShouldEqual(33); result1.Section.ShouldEqual(ResultHelper.Section.Top); result1.IsTied.ShouldEqual(false); result1.TieBreakRequired = false; var result2 = results[1]; result2.VoteCount.ShouldEqual(27); result2.Section.ShouldEqual(ResultHelper.Section.Other); result2.IsTied.ShouldEqual(false); result2.TieBreakRequired = false; result2.ForceShowInOther = false; var result3 = results[2]; result3.VoteCount.ShouldEqual(5); result3.Section.ShouldEqual(ResultHelper.Section.Other); result3.IsTied.ShouldEqual(true); result3.TieBreakRequired = true; result3.ForceShowInOther = false; }
public void Invalid_Ballots_Affect_Results() { var electionGuid = Guid.NewGuid(); var election = new Election { ElectionGuid = electionGuid, NumberToElect = 1, NumberExtra = 0 }; var location = new Location { LocationGuid = Guid.NewGuid(), ElectionGuid = electionGuid }; var ballot1Guid = Guid.NewGuid(); var ballot2Guid = Guid.NewGuid(); var ballots = new List<Ballot> { new Ballot {LocationGuid = location.LocationGuid, BallotGuid = ballot1Guid, StatusCode = BallotStatusEnum.Ok}, new Ballot {LocationGuid = location.LocationGuid, BallotGuid = ballot2Guid, StatusCode = BallotStatusEnum.Ok} }; var voteinfos = new List<vVoteInfo> { // TODO 2012-03-24 Glen Little: Needs attention... these test are for normal elections, not single name... new vVoteInfo {SingleNameElectionCount = 33}, new vVoteInfo {SingleNameElectionCount = 5}, new vVoteInfo {SingleNameElectionCount = 2}, new vVoteInfo {SingleNameElectionCount = 4}, new vVoteInfo {SingleNameElectionCount = 27}, new vVoteInfo {SingleNameElectionCount = 27}, new vVoteInfo {SingleNameElectionCount = 27}, }; var rowId = 1; foreach (var voteInfo in voteinfos) { voteInfo.VoteId = rowId++; voteInfo.ElectionGuid = electionGuid; voteInfo.PersonCombinedInfo = voteInfo.PersonCombinedInfoInVote = "zz"; voteInfo.BallotStatusCode = BallotStatusEnum.Ok; voteInfo.VoteStatusCode = VoteHelper.VoteStatusCode.Ok; voteInfo.BallotGuid = ballot1Guid; voteInfo.PersonGuid = Guid.NewGuid(); } voteinfos[3].VoteStatusCode = VoteHelper.VoteStatusCode.Changed; voteinfos[4].BallotStatusCode = "TooFew"; voteinfos[5].PersonCombinedInfo = "different"; voteinfos[6].PersonIneligibleReasonGuid = Guid.NewGuid(); var model = new ElectionAnalyzerSingleName(_fakes, election, voteinfos, ballots, SamplePeople); model.GenerateResults(); var results = model.Results.OrderByDescending(r => r.VoteCount).ToList(); ballots[0].StatusCode.ShouldEqual(BallotStatusEnum.Ok); ballots[1].StatusCode.ShouldEqual(BallotStatusEnum.Ok); var summary = model.ResultSummaryAuto; summary.TotalVotes.ShouldEqual(125); summary.SpoiledBallots.ShouldEqual(0); summary.SpoiledVotes.ShouldEqual(54); summary.BallotsNeedingReview.ShouldEqual(1); results.Count.ShouldEqual(5); }