public async Task TestSimpleStepRuturnNoCandidates() { var step = new ElectionDriver.Fakes.StubIElectionStep(); CandiateRanking[] rankings = new CandiateRanking[0]; step.RunStepPersonArrayCandiateRankingArrayArray = (people, prev) => { return rankings; }; var e = new Election(); e.AddStep(step); var result = await e.RunSingleElection(); }
public async Task TestSimpleStepNullFail() { var step = new ElectionDriver.Fakes.StubIElectionStep(); step.RunStepPersonArrayCandiateRankingArrayArray = (people, prev) => { return null; }; var e = new Election(); e.NumberOfCandidates = 15; e.NumberOfPeople = 350; e.AddStep(step); await e.RunSingleElection(); }
public async void TestSimpleReturn() { var step = new ElectionDriver.Fakes.StubIElectionStep(); int numPeople = 0; int numCandidates = 0; CandiateRanking[] r = new CandiateRanking[] { new CandiateRanking(0, 1) }; step.RunStepPersonArrayCandiateRankingArrayArray = (people, prev) => { numPeople = people.Length; numCandidates = people[0].FullRanking().Count(); return r; }; var e = new Election(); e.NumberOfCandidates = 15; e.NumberOfPeople = 350; e.AddStep(step); var result = await e.RunSingleElection(); Assert.AreEqual(350, numPeople, "# of people"); Assert.AreEqual(15, numCandidates, "# of candidates"); Assert.AreEqual(r, result, "Candidate ranking that came back isn't right"); }
public async void TestElectionReturnOrder() { var step = new ElectionDriver.Fakes.StubIElectionStep(); CandiateRanking[] r = new CandiateRanking[] { new CandiateRanking(0, 1), new CandiateRanking(1, 10) }; step.RunStepPersonArrayCandiateRankingArrayArray = (people, prev) => { return r; }; var e = new Election(); e.NumberOfCandidates = 15; e.NumberOfPeople = 350; e.AddStep(step); var result = await e.RunSingleElection(); Assert.AreEqual(1, result[0].candidate, "Winner was not listed first"); }
public async Task TestFixPeopleImpossibleRequirement() { var e = new Election() { NumberOfCandidates = 2, NumberOfPeople = 10 }; e.AddPeopleConstraint(0.7, p => p.Ranking(0) == 1); e.AddPeopleConstraint(0.7, p => p.Ranking(1) == 1); var step1 = new ElectionDriver.Fakes.StubIElectionStep(); int countOfNumber1 = 0; int countOfNumber2 = 0; step1.RunStepPersonArrayCandiateRankingArrayArray = (people, prev) => { countOfNumber1 = people.Where(p => p.Ranking(0) == 1).Count(); countOfNumber2 = people.Where(p => p.Ranking(1) == 0).Count(); return new CandiateRanking[] { new CandiateRanking(0, 1) }; }; e.AddStep(step1); var flips = await e.RunSingleElection(); }
public async Task TestFixPeople2Requirement() { var e = new Election() { NumberOfCandidates = 3, NumberOfPeople = 10 }; e.AddPeopleConstraint(0.3, p => p.Ranking(0) == 1); e.AddPeopleConstraint(0.5, p => p.Ranking(1) == 1); var step1 = new ElectionDriver.Fakes.StubIElectionStep(); int countOfNumber1 = 0; int countOfNumber2 = 0; step1.RunStepPersonArrayCandiateRankingArrayArray = (people, prev) => { countOfNumber1 = people.Where(p => p.Ranking(0) == 1).Count(); countOfNumber2 = people.Where(p => p.Ranking(1) == 1).Count(); return new CandiateRanking[] { new CandiateRanking(0, 1) }; }; e.AddStep(step1); var flips = await e.RunSingleElection(); Assert.AreEqual(3, countOfNumber1, "# of times the zero candidate is 1 shoudl be 3!"); Assert.AreEqual(5, countOfNumber2, "# of times the zero candidate is 2 shoudl be 5!"); }
public void TestSimpleRun() { var e = new Election(); e.AddStep(new ESOnlyBestCounts()); var r = e.RunSingleElection(); }
public async void TestElectionWindowing() { var step1 = new ElectionDriver.Fakes.StubIElectionStep(); CandiateRanking[] ranking1 = new CandiateRanking[] { new CandiateRanking(0, 1), new CandiateRanking(1, 2), new CandiateRanking(2, 3) }; step1.RunStepPersonArrayCandiateRankingArrayArray = (people, prev) => { Assert.IsTrue(people.All(p => p.FullRanking().Count() == 4), "Not always three candidates"); return ranking1; }; var step2 = new ElectionDriver.Fakes.StubIElectionStep(); CandiateRanking[] ranking2 = new CandiateRanking[] { new CandiateRanking(1, 1), new CandiateRanking(0, 1) }; step2.RunStepPersonArrayCandiateRankingArrayArray = (people, prev) => { Assert.IsTrue(people.All(p => p.FullRanking().Count() == 3), "Not always two candidates"); return ranking2; }; var step3 = new ElectionDriver.Fakes.StubIElectionStep(); CandiateRanking[] ranking3 = new CandiateRanking[] { new CandiateRanking(1, 1)}; step3.RunStepPersonArrayCandiateRankingArrayArray = (people, prev) => { Assert.IsTrue(people.All(p => p.FullRanking().Count() == 2), "Not always two candidates"); return ranking3; }; var e = new Election(); e.NumberOfCandidates = 4; e.AddStep(step1); e.AddStep(step2); e.AddStep(step3); var result = await e.RunSingleElection(); Assert.AreEqual(ranking3, result, "Candidate ranking should be what came out of step 1"); }
public async void TestTwoStepElectionSimple() { var step1 = new ElectionDriver.Fakes.StubIElectionStep(); CandiateRanking[] ranking1 = new CandiateRanking[] { new CandiateRanking(0, 1), new CandiateRanking(1, 2) }; step1.RunStepPersonArrayCandiateRankingArrayArray = (people, prev) => ranking1; var step2 = new ElectionDriver.Fakes.StubIElectionStep(); CandiateRanking[] ranking2 = new CandiateRanking[] { new CandiateRanking(1, 1) }; step2.RunStepPersonArrayCandiateRankingArrayArray = (people, prev) => ranking2; var e = new Election(); e.AddStep(step1); e.AddStep(step2); var result = await e.RunSingleElection(); Assert.AreEqual(ranking2, result, "Candidate ranking should be what came out of step 1"); }
public async Task TestBlankRun() { var e = new Election(); await e.RunSingleElection(); }