public void TestAverageNumberOfKilledAlotOfPersons() { var killedPersons = new List <Person>() { new Person() { AgeOfDeath = 10, YearOfDeath = 11 }, new Person() { AgeOfDeath = 10, YearOfDeath = 12 }, new Person() { AgeOfDeath = 10, YearOfDeath = 13 }, new Person() { AgeOfDeath = 10, YearOfDeath = 14 }, new Person() { AgeOfDeath = 10, YearOfDeath = 15 }, new Person() { AgeOfDeath = 10, YearOfDeath = 16 }, }; var deathCalculator = new DeathCalculator(); Assert.AreEqual(46 / (double)killedPersons.Count, deathCalculator.CalculateAveragePeopleKilledOnYearOfBirth(killedPersons)); }
public void TestAverageNumberOfKilled0Persons_ShouldReturn0() { var killedPersons = new List <Person>(); var deathCalculator = new DeathCalculator(); Assert.AreEqual(0, deathCalculator.CalculateAveragePeopleKilledOnYearOfBirth(killedPersons)); }
public void TestInvalidDataSinglePerson_ShouldReturnNegativeOne() { var killedPersons = new List <Person>() { new Person() { AgeOfDeath = 11, YearOfDeath = 10 } }; var deathCalculator = new DeathCalculator(); Assert.AreEqual(-1, deathCalculator.CalculateAveragePeopleKilledOnYearOfBirth(killedPersons)); }
public void TestAverageNumberOfKilledSinglePersons() { var killedPersons = new List <Person>() { new Person() { AgeOfDeath = 10, YearOfDeath = 16 } }; var deathCalculator = new DeathCalculator(); Assert.AreEqual(20, deathCalculator.CalculateAveragePeopleKilledOnYearOfBirth(killedPersons)); }
public void TestAverageNumberOfKilledTwoPersons() { var killedPersons = new List <Person>() { new Person() { AgeOfDeath = 10, YearOfDeath = 12 }, new Person() { AgeOfDeath = 13, YearOfDeath = 17 } }; var deathCalculator = new DeathCalculator(); Assert.AreEqual <double>(4.5d, deathCalculator.CalculateAveragePeopleKilledOnYearOfBirth(killedPersons)); }
public IActionResult Index(PersonsViewModel personsViewParam) { PersonsViewModel personsViewModel; if (personsViewParam.NumberOfVictims > 0) { personsViewModel = personsViewParam; } else { personsViewModel = new PersonsViewModel() { NumberOfVictims = 2 } }; if (!personsViewModel.Calculate) { personsViewModel.Persons.Clear(); for (int i = 0; i < personsViewModel.NumberOfVictims; i++) { personsViewModel.Persons.Add(new PersonViewModel() { AgeOfDeath = 10, YearOfDeath = 12 }); } } else { var deathCalculator = new DeathCalculator(); personsViewModel.Result = deathCalculator.CalculateAveragePeopleKilledOnYearOfBirth(personsViewModel.Persons. Select(x => new Person() { AgeOfDeath = x.AgeOfDeath, YearOfDeath = x.YearOfDeath }).ToList()); } return(View(personsViewModel)); } }