public void TestMassiveRandomSpamUseCaseWithMultipleSubmissions2() { TwoThirdAverageGame.Reset(); TwoThirdAverageGame.Submit("Adrian", 5.61421187); TwoThirdAverageGame.Submit("Adrian", 26.5127862031807); TwoThirdAverageGame.Submit("Eileen", 16.4589434350589); TwoThirdAverageGame.Submit("Eileen", 16.676945631089); TwoThirdAverageGame.Submit("Lui Hock", 44.4681713840666); TwoThirdAverageGame.Submit("Lui Hock", 0.0136052735450553); TwoThirdAverageGame.Submit("Yee Pey", 10.9343697038424); TwoThirdAverageGame.Submit("Yee Pey", 11.4773266861916); TwoThirdAverageGame.Submit("Jia Sin", 42.7877380582701); TwoThirdAverageGame.Submit("Jia Sin", 29.7159126976324); TwoThirdAverageGame.Submit("Hao Quan", 9.80453411680249); TwoThirdAverageGame.Submit("Hao Quan", 27.34914372); TwoThirdAverageGame.Submit("Jing Yuan", 3.58524387180597); TwoThirdAverageGame.Submit("Jing Yuan", 2.34656529207177); TwoThirdAverageGame.Submit("Allen", 42.0112601247103); TwoThirdAverageGame.Submit("Allen", 0); TwoThirdAverageGame.Submit("Alice", 19.1769405479078); TwoThirdAverageGame.Submit("Alice", 0.524429878832385); TwoThirdAverageGame.Submit("Eunice", 21.8216342839915); TwoThirdAverageGame.Submit("Eunice", 1.41720055445581); TwoThirdAverageGame.Submit("Qi Yang", 46.0901205266567); TwoThirdAverageGame.Submit("Qi Yang", 4.83219247256449); TwoThirdAverageGame.ReleaseResults(); Assert.Equal(11, TwoThirdAverageGame.GetNumberOfSubmissions()); Assert.Equal(7.32521869, TwoThirdAverageGame.GetTwoThirdOfAverage(), 8); Assert.Equal("Qi Yang", TwoThirdAverageGame.GetWinner()); }
public void Post([FromBody] Submission value) { if (value != null) { TwoThirdAverageGame.Submit(value.Name, value.Number); } }
public IActionResult Results() { ViewData["Results"] = Math.Round(TwoThirdAverageGame.GetTwoThirdOfAverage(), 2); ViewData["Winner"] = TwoThirdAverageGame.GetWinner(); ViewData["Count"] = TwoThirdAverageGame.GetNumberOfSubmissions(); return(View()); }
public void TestNegativeZeroDoubleShouldBeAllowed() { TwoThirdAverageGame.Reset(); TwoThirdAverageGame.Submit("Adrian", -0.0); TwoThirdAverageGame.ReleaseResults(); Assert.Equal(1, TwoThirdAverageGame.GetNumberOfSubmissions()); Assert.Equal(0, TwoThirdAverageGame.GetTwoThirdOfAverage()); Assert.Equal("Adrian", TwoThirdAverageGame.GetWinner()); }
public void PlayersDoingStupidThingsShouldBeIgnored(string name, double number) { TwoThirdAverageGame.Reset(); TwoThirdAverageGame.Submit(name, number); Assert.Equal(0, TwoThirdAverageGame.GetNumberOfSubmissions()); Assert.Equal(0, TwoThirdAverageGame.GetTwoThirdOfAverage()); Assert.Equal("No one", TwoThirdAverageGame.GetWinner()); }
private void execute1000RandomSubmissions() { int submissions = 1100; for (int i = 0; i < submissions; i++) { string name = RandomString(8); TwoThirdAverageGame.Submit(name, new Random().NextDouble()); } }
public void PlayersDoingStupidThingsShouldBeIgnoredWhenTheGameHasAlreadyBegun(string stupidName, double stupidNumber) { TwoThirdAverageGame.Reset(); TwoThirdAverageGame.Submit("Proper Person", 24); TwoThirdAverageGame.Submit(stupidName, stupidNumber); TwoThirdAverageGame.ReleaseResults(); Assert.Equal(1, TwoThirdAverageGame.GetNumberOfSubmissions()); Assert.Equal(16, TwoThirdAverageGame.GetTwoThirdOfAverage()); Assert.Equal("Proper Person", TwoThirdAverageGame.GetWinner()); }
public void SamePlayerSubmittingShouldHaveHisValueUpdated5() { TwoThirdAverageGame.Reset(); TwoThirdAverageGame.Submit("Adrian", 25); TwoThirdAverageGame.Submit("Adrian", 15); TwoThirdAverageGame.Submit("Adrian", 10); double actual = TwoThirdAverageGame.GetValueThisPersonSubmitted("Adrian"); Assert.Equal(10, actual); }
public void SamePlayerSubmittingShouldHaveHisValueUpdated() { double expected = 21; TwoThirdAverageGame.Reset(); TwoThirdAverageGame.Submit("Adrian", 25); TwoThirdAverageGame.Submit("Adrian", expected); double actual = TwoThirdAverageGame.GetValueThisPersonSubmitted("Adrian"); Assert.Equal(expected, actual); }
public void PlayerNamesShouldBeTrimmedOnSubmission2(string name) { string expected = "Adrian Cheong"; TwoThirdAverageGame.Reset(); TwoThirdAverageGame.Submit(name, 25); List <string> players = TwoThirdAverageGame.GetPlayerList(); var actual = players[0]; Assert.Equal(expected, actual); }
public void SamePlayerSubmittingShouldNotIncreaseTotalCount() { double expected = 1; TwoThirdAverageGame.Reset(); TwoThirdAverageGame.Submit("Adrian", 25); TwoThirdAverageGame.Submit("Adrian", 21); double actual = TwoThirdAverageGame.GetNumberOfSubmissions(); Assert.Equal(expected, actual); }
public void GameCanHandleAtLeast1000SubmissionsMultipleTimes() { int noOfRuns = 10; for (int i = 0; i < noOfRuns; i++) { TwoThirdAverageGame.Reset(); Assert.Equal(0, TwoThirdAverageGame.GetNumberOfSubmissions()); execute1000RandomSubmissions(); TwoThirdAverageGame.ReleaseResults(); Assert.True(TwoThirdAverageGame.GetNumberOfSubmissions() > 1000); } }
public void ResultsShouldStayTheSameWhenGameResultsAreReleasedAndPeopleContinueToSubmitAfterThat() { TwoThirdAverageGame.Reset(); TwoThirdAverageGame.Submit("Adrian", 73.43242379); TwoThirdAverageGame.Submit("Eileen", 24.1992526401822); TwoThirdAverageGame.Submit("Lui Hock", 12.562050468151); TwoThirdAverageGame.Submit("Yee Pey", 6.54877570622227); TwoThirdAverageGame.Submit("Jia Sin", 42.2141806342241); TwoThirdAverageGame.Submit("Hao Quan", 19.7893892710047); TwoThirdAverageGame.Submit("Jing Yuan", 88.8368410869358); TwoThirdAverageGame.Submit("Allen", 3.55457923765942); TwoThirdAverageGame.Submit("Alice", 14.3036154114645); TwoThirdAverageGame.Submit("Eunice", 0); TwoThirdAverageGame.Submit("Qi Yang", 5.19015232061224); TwoThirdAverageGame.Submit("Adrian", 46.85738196); TwoThirdAverageGame.Submit("Eileen", 3.6763183989933); TwoThirdAverageGame.Submit("Lui Hock", 43.2801036536813); TwoThirdAverageGame.Submit("Jing Yuan", 81.1472941516023); TwoThirdAverageGame.Submit("Allen", 19.5144175092296); TwoThirdAverageGame.Submit("Alice", 4.75170298386008); TwoThirdAverageGame.Submit("Eunice", 59.4291471599364); TwoThirdAverageGame.Submit("Adrian", 14.528706916404); TwoThirdAverageGame.Submit("Yee Pey", 2.88842300573672); TwoThirdAverageGame.Submit("Allen", 67.2416185679742); TwoThirdAverageGame.Submit("Alice", 31.042886259302); TwoThirdAverageGame.Submit("Eunice", 4.64297851); TwoThirdAverageGame.Submit("Jia Sin", 23.7674621195047); TwoThirdAverageGame.Submit("Jing Yuan", 58.6840246285958); TwoThirdAverageGame.Submit("Alice", 48.4684162480857); TwoThirdAverageGame.Submit("Qi Yang", 5.89387287022391); TwoThirdAverageGame.Submit("Adrian", 6.59055132251411); TwoThirdAverageGame.Submit("Yee Pey", 2.43624612573545); TwoThirdAverageGame.Submit("Adrian", 50.040706675074); TwoThirdAverageGame.Submit("Yee Pey", 63.9921404584476); TwoThirdAverageGame.Submit("Adrian", 13.4814486122107); TwoThirdAverageGame.Submit("Yee Pey", 37.0459822944279); TwoThirdAverageGame.ReleaseResults(); Assert.Equal(11, TwoThirdAverageGame.GetNumberOfSubmissions()); Assert.Equal(19.75585547, TwoThirdAverageGame.GetTwoThirdOfAverage(), 8); Assert.Equal("Hao Quan", TwoThirdAverageGame.GetWinner()); TwoThirdAverageGame.Submit("New Person 1", 0); TwoThirdAverageGame.Submit("New Person 2", 25); TwoThirdAverageGame.Submit("New Person 3", 50); TwoThirdAverageGame.Submit("New Person 4", 75); TwoThirdAverageGame.Submit("New Person 5", 100); Assert.Equal(11, TwoThirdAverageGame.GetNumberOfSubmissions()); Assert.Equal(19.75585547, TwoThirdAverageGame.GetTwoThirdOfAverage(), 8); Assert.Equal("Hao Quan", TwoThirdAverageGame.GetWinner()); }
public void IfThereAreTwoWinnersTheFirstPersonWhoSubmittedShouldWin(double value) { string firstPerson = "First Person"; string secondPerson = "Second Person"; TwoThirdAverageGame.Reset(); TwoThirdAverageGame.Submit(firstPerson, value); TwoThirdAverageGame.Submit(secondPerson, value); TwoThirdAverageGame.ReleaseResults(); string actual = TwoThirdAverageGame.GetWinner(); Assert.Equal(firstPerson, actual); }
public void TestMassiveRandomSpamUseCaseWithMultipleSubmissionsWithInvalidSubmissionsInBetween() { TwoThirdAverageGame.Reset(); TwoThirdAverageGame.Submit("Punk", -0.01); TwoThirdAverageGame.Submit("Adrian", 73.43242379); TwoThirdAverageGame.Submit("Eileen", 24.1992526401822); TwoThirdAverageGame.Submit("Lui Hock", 12.562050468151); TwoThirdAverageGame.Submit("Yee Pey", 6.54877570622227); TwoThirdAverageGame.Submit("Punk", 100.01); TwoThirdAverageGame.Submit("Jia Sin", 42.2141806342241); TwoThirdAverageGame.Submit("Hao Quan", 19.7893892710047); TwoThirdAverageGame.Submit("Jing Yuan", 88.8368410869358); TwoThirdAverageGame.Submit("Allen", 3.55457923765942); TwoThirdAverageGame.Submit("Alice", 14.3036154114645); TwoThirdAverageGame.Submit("Punk", int.MinValue); TwoThirdAverageGame.Submit("Eunice", 0); TwoThirdAverageGame.Submit("Qi Yang", 5.19015232061224); TwoThirdAverageGame.Submit("Adrian", 46.85738196); TwoThirdAverageGame.Submit("Eileen", 3.6763183989933); TwoThirdAverageGame.Submit("Lui Hock", 43.2801036536813); TwoThirdAverageGame.Submit("Punk", int.MaxValue); TwoThirdAverageGame.Submit("Jing Yuan", 81.1472941516023); TwoThirdAverageGame.Submit("Allen", 19.5144175092296); TwoThirdAverageGame.Submit("Alice", 4.75170298386008); TwoThirdAverageGame.Submit("Eunice", 59.4291471599364); TwoThirdAverageGame.Submit("Adrian", 14.528706916404); TwoThirdAverageGame.Submit("Yee Pey", 2.88842300573672); TwoThirdAverageGame.Submit("Allen", 67.2416185679742); TwoThirdAverageGame.Submit("Punk", Double.MinValue); TwoThirdAverageGame.Submit("Alice", 31.042886259302); TwoThirdAverageGame.Submit("Eunice", 4.64297851); TwoThirdAverageGame.Submit("Jia Sin", 23.7674621195047); TwoThirdAverageGame.Submit("Jing Yuan", 58.6840246285958); TwoThirdAverageGame.Submit("Alice", 48.4684162480857); TwoThirdAverageGame.Submit("Qi Yang", 5.89387287022391); TwoThirdAverageGame.Submit("Adrian", 6.59055132251411); TwoThirdAverageGame.Submit("Punk", Double.MaxValue); TwoThirdAverageGame.Submit("Yee Pey", 2.43624612573545); TwoThirdAverageGame.Submit("Adrian", 50.040706675074); TwoThirdAverageGame.Submit("Yee Pey", 63.9921404584476); TwoThirdAverageGame.Submit(null, 50); TwoThirdAverageGame.Submit("Adrian", 13.4814486122107); TwoThirdAverageGame.Submit("Yee Pey", 37.0459822944279); TwoThirdAverageGame.Submit("", 50); TwoThirdAverageGame.ReleaseResults(); Assert.Equal(11, TwoThirdAverageGame.GetNumberOfSubmissions()); Assert.Equal(19.75585547, TwoThirdAverageGame.GetTwoThirdOfAverage(), 8); Assert.Equal("Hao Quan", TwoThirdAverageGame.GetWinner()); }
public void IfAPersonChangesHisValueHeShouldBeConsideredLastOfQueue() { string firstPerson = "First Person"; string secondPerson = "Second Person"; double winningValue = 25; TwoThirdAverageGame.Reset(); TwoThirdAverageGame.Submit(firstPerson, 50); TwoThirdAverageGame.Submit(secondPerson, winningValue); TwoThirdAverageGame.Submit(firstPerson, winningValue); TwoThirdAverageGame.ReleaseResults(); string actual = TwoThirdAverageGame.GetWinner(); Assert.Equal(secondPerson, actual); }
public void FirstSecondThirdPlaceShouldBeInThatOrderOfSubmissionIfTheyAllTie() { string firstPerson = "First Person"; string secondPerson = "Second Person"; string thirdPerson = "Third Person"; TwoThirdAverageGame.Reset(); TwoThirdAverageGame.Submit(firstPerson, 25); TwoThirdAverageGame.Submit(secondPerson, 25); TwoThirdAverageGame.Submit(thirdPerson, 25); TwoThirdAverageGame.ReleaseResults(); Assert.Equal(firstPerson, TwoThirdAverageGame.GetWinner()); Assert.Equal(secondPerson, TwoThirdAverageGame.GetSecond()); Assert.Equal(thirdPerson, TwoThirdAverageGame.GetThird()); }
public void FirstPersonShouldBecomeLastPlaceIfHeReSubmittedInTheCaseOfAllTie() { string firstPerson = "First Person"; string secondPerson = "Second Person"; string thirdPerson = "Third Person"; TwoThirdAverageGame.Reset(); TwoThirdAverageGame.Submit(firstPerson, 25); TwoThirdAverageGame.Submit(secondPerson, 25); TwoThirdAverageGame.Submit(thirdPerson, 25); TwoThirdAverageGame.Submit(firstPerson, 25); TwoThirdAverageGame.ReleaseResults(); Assert.Equal(secondPerson, TwoThirdAverageGame.GetWinner()); Assert.Equal(thirdPerson, TwoThirdAverageGame.GetSecond()); Assert.Equal(firstPerson, TwoThirdAverageGame.GetThird()); }
public void AdminCanGetResultsEvenWhenGameResultsIsNotReleasedYet() { TwoThirdAverageGame.Reset(); TwoThirdAverageGame.Submit("Adrian", 73.43242379); TwoThirdAverageGame.Submit("Eileen", 24.1992526401822); TwoThirdAverageGame.Submit("Lui Hock", 12.562050468151); TwoThirdAverageGame.Submit("Yee Pey", 6.54877570622227); TwoThirdAverageGame.Submit("Jia Sin", 42.2141806342241); TwoThirdAverageGame.Submit("Hao Quan", 19.7893892710047); TwoThirdAverageGame.Submit("Jing Yuan", 88.8368410869358); TwoThirdAverageGame.Submit("Allen", 3.55457923765942); TwoThirdAverageGame.Submit("Alice", 14.3036154114645); TwoThirdAverageGame.Submit("Eunice", 0); TwoThirdAverageGame.Submit("Qi Yang", 5.19015232061224); Assert.Equal(0, TwoThirdAverageGame.GetSubmissions().Count); Assert.Equal(11, TwoThirdAverageGame.GetSubmissionsAsAdmin().Count); }
public void ResetWorks() { TwoThirdAverageGame.Reset(); Assert.Equal(0, TwoThirdAverageGame.GetNumberOfSubmissions()); Assert.Equal(0, TwoThirdAverageGame.GetTwoThirdOfAverage()); Assert.Equal("No one", TwoThirdAverageGame.GetWinner()); TwoThirdAverageGame.Submit("Adrian", 25); TwoThirdAverageGame.ReleaseResults(); Assert.Equal(1, TwoThirdAverageGame.GetNumberOfSubmissions()); Assert.True(TwoThirdAverageGame.GetTwoThirdOfAverage() > 0); Assert.Equal("Adrian", TwoThirdAverageGame.GetWinner()); TwoThirdAverageGame.Reset(); Assert.Equal(0, TwoThirdAverageGame.GetNumberOfSubmissions()); Assert.Equal(0, TwoThirdAverageGame.GetTwoThirdOfAverage()); Assert.Equal("No one", TwoThirdAverageGame.GetWinner()); }
public void NoMoreSubmissionsShouldBeAllowedAfterGameResultsIsReleased() { TwoThirdAverageGame.Reset(); TwoThirdAverageGame.Submit("Adrian", 73.43242379); TwoThirdAverageGame.Submit("Eileen", 24.1992526401822); TwoThirdAverageGame.Submit("Lui Hock", 12.562050468151); TwoThirdAverageGame.Submit("Yee Pey", 6.54877570622227); TwoThirdAverageGame.Submit("Jia Sin", 42.2141806342241); TwoThirdAverageGame.ReleaseResults(); Assert.Equal(5, TwoThirdAverageGame.GetNumberOfSubmissions()); var expectedWinner = TwoThirdAverageGame.GetWinner(); var expectedAnswer = TwoThirdAverageGame.GetTwoThirdOfAverage(); TwoThirdAverageGame.Submit("Hao Quan", 19.7893892710047); TwoThirdAverageGame.Submit("Jing Yuan", 88.8368410869358); TwoThirdAverageGame.Submit("Allen", 3.55457923765942); TwoThirdAverageGame.Submit("Alice", 14.3036154114645); TwoThirdAverageGame.Submit("Eunice", 0); TwoThirdAverageGame.Submit("Qi Yang", 5.19015232061224); Assert.Equal(5, TwoThirdAverageGame.GetNumberOfSubmissions()); Assert.Equal(expectedWinner, TwoThirdAverageGame.GetWinner()); Assert.Equal(expectedAnswer, TwoThirdAverageGame.GetTwoThirdOfAverage()); }
public object AdminSubmissions() { return(TwoThirdAverageGame.GetSubmissionsAsAdmin()); }
public int Count() { return(TwoThirdAverageGame.GetNumberOfSubmissions()); }
public double Result() { return(Math.Round(TwoThirdAverageGame.GetTwoThirdOfAverage(), 8)); }
public string Winner() { return(TwoThirdAverageGame.GetWinner()); }
public void Reset() { TwoThirdAverageGame.Reset(); }
public void Release() { TwoThirdAverageGame.ReleaseResults(); }