public void TestEmptyCovidDataCollection() { // ReSharper disable once CollectionNeverUpdated.Local var covidCollection = new CovidDataCollection(); var statistics = new CovidDataStatistics(covidCollection); Assert.ThrowsException <InvalidOperationException>(() => statistics.FindDayOfFirstPositiveTest()); }
/// <Summary> /// Initializes a new instance of the /// <a onclick="return false;" href="CovidDataStateSummary" originaltag="see">CovidDataStateSummary</a> class. /// <para>If the stateFilter is empty, then the collection will not be filtered</para> /// <code>Precondition: collection != null</code> /// <code>Postcondition: CovidRecords == collection AND StateFilter == stateFilter </code> /// </Summary> /// <param name="collection">The collection.</param> /// <param name="stateFilter">The state filter for the collection</param> /// <exception cref="ArgumentNullException">collection</exception> public CovidDataSummary(CovidDataCollection collection, string stateFilter) { this.CovidRecords = collection ?? throw new ArgumentNullException(nameof(collection)); this.StateFilter = stateFilter ?? throw new ArgumentNullException(); var filteredCollection = collection.CreateAFilteredCollection(stateFilter); this.CovidRecords.ReplaceAllWithNewCovidCollection(filteredCollection); this.covidStatistics = new CovidDataStatistics(this.CovidRecords); }
public void TestFindThresholdLessThanZero() { // ReSharper disable once CollectionNeverUpdated.Local var covidCollection = new CovidDataCollection(); var covidStatistics = new CovidDataStatistics(covidCollection); Assert.ThrowsException <ArgumentOutOfRangeException>(() => covidStatistics.FindNumberOfDaysForPositiveTestsLessThanThreshold(-1)); }
public void TestFindEmptyCovidDataCollection() { // ReSharper disable once CollectionNeverUpdated.Local var covidCollection = new CovidDataCollection(); var covidStatistics = new CovidDataStatistics(covidCollection); Assert.ThrowsException <InvalidOperationException>(() => covidStatistics.FindNumberOfDaysForPositiveTestsLessThanThreshold(this.threshold)); }
public void TestAverageEmptyCovidDataCollection() { // ReSharper disable once CollectionNeverUpdated.Local var covidCollection = new CovidDataCollection(); var covidStatistics = new CovidDataStatistics(covidCollection); Assert.ThrowsException <InvalidOperationException>(() => covidStatistics.FindAverageTotalTestsSinceSpecifiedDate(this.defaultDate)); }
public void TestEmptyCovidDataCollection() { // ReSharper disable once CollectionNeverUpdated.Local var covidCollection = new CovidDataCollection(); var covidStatistics = new CovidDataStatistics(covidCollection); Assert.ThrowsException <InvalidOperationException>( () => covidStatistics.FindRecordWithHighestPositiveCases()); }
public void TestOneItemCovidDataCollection() { var covidCollection = new CovidDataCollection { this.record1 }; var covidStatistics = new CovidDataStatistics(covidCollection); var record = covidStatistics.FindRecordWithHighestPositiveCases(); Assert.AreEqual(this.record1, record); }
public void TestAverageOneItemCovidDataCollection() { var covidCollection = new CovidDataCollection { this.record1 }; var covidStatistics = new CovidDataStatistics(covidCollection); var result = covidStatistics.FindAveragePositiveTestsSinceFirstPositiveTest(); Assert.AreEqual(30, result); }
public void TestOneItemCovidDataCollectionNoPositiveTest() { var record = new CovidRecord(DateTime.Now, "GA"); var covidCollection = new CovidDataCollection { record }; var statistics = new CovidDataStatistics(covidCollection); Assert.ThrowsException <InvalidOperationException>(() => statistics.FindDayOfFirstPositiveTest()); }
public void TestAverageOneItemCovidDataCollection() { var covidCollection = new CovidDataCollection { this.record1 }; var covidStatistics = new CovidDataStatistics(covidCollection); var result = covidStatistics.FindAverageTotalTestsSinceSpecifiedDate(this.defaultDate); Assert.AreEqual(30, result); }
public void TestFindARecordOnThreshold() { var covidCollection = new CovidDataCollection { this.record2, this.record3 }; var covidStatistics = new CovidDataStatistics(covidCollection); var result = covidStatistics.FindNumberOfDaysForPositiveTestsLessThanThreshold(this.threshold); Assert.AreEqual(0, result); }
public void TestMultipleItemCovidDataCollectionLastPlace() { var covidCollection = new CovidDataCollection { this.record1, this.record2, this.record3 }; var covidStatistics = new CovidDataStatistics(covidCollection); var record = covidStatistics.FindRecordWithHighestPositiveCases(); Assert.AreEqual(this.record3, record); }
public void TestAverageMultiItemCovidDataCollection() { var covidCollection = new CovidDataCollection { this.record1, this.record2, this.record3 }; var covidStatistics = new CovidDataStatistics(covidCollection); var result = covidStatistics.FindAveragePositiveTestsSinceSpecifiedDate(this.defaultDate); Assert.AreEqual(40, result); }
public void TestOverallPositivityOneItemCovidDataCollection() { var covidCollection = new CovidDataCollection { this.record1 }; var covidStatistics = new CovidDataStatistics(covidCollection); var positiveTestAverage = covidStatistics.FindAveragePositiveTestsSinceSpecifiedDate(this.defaultDate); var totalTestAverage = covidStatistics.FindAverageTotalTestsSinceSpecifiedDate(this.defaultDate); var expected = positiveTestAverage / totalTestAverage; var actual = covidStatistics.FindOverallPositivityRateSinceFirstPositiveTest(); Assert.AreEqual(expected, actual, Delta); }
public void TestOneItemCovidDataCollectionOnePositiveTest() { var record = new CovidRecord(this.inputDate1, "GA") { PositiveTests = 1 }; var covidCollection = new CovidDataCollection { record }; var statistics = new CovidDataStatistics(covidCollection); var result = statistics.FindDayOfFirstPositiveTest(); Assert.AreEqual(this.inputDate1, result.Date); }
private string getDataForTheMonthGroup(IGrouping <DateTime, CovidRecord> monthGroup) { var reportOfTheMonth = string.Empty; var monthGroupKey = Format.GetMonthAndYearFromDateTime(monthGroup.Key); var monthHeading = $"{Environment.NewLine}{monthGroupKey} ({monthGroup.Count()} {Assets.DaysOfDataLabel}):{Environment.NewLine}"; this.covidStatistics = new CovidDataStatistics(monthGroup); reportOfTheMonth += monthHeading; reportOfTheMonth += this.getHighestPositiveTestWithDays(monthGroup); reportOfTheMonth += this.getLowestPositiveTestWithDays(monthGroup); reportOfTheMonth += this.getHighestTotalTestsWithDays(monthGroup); reportOfTheMonth += this.getLowestTotalTestsWithDays(monthGroup); reportOfTheMonth += this.getHighestCurrentlyHospitalizedWithDays(monthGroup); reportOfTheMonth += this.getLowestCurrentlyHospitalizedWithDays(monthGroup); reportOfTheMonth += this.getAveragePositiveTests(); reportOfTheMonth += this.getAverageTotalTests(); return($"{reportOfTheMonth}"); }
/// <Summary>Gets the highest percentage of positive tests with date.</Summary> /// <returns>A formatted string with the highest percentage of positive test and date</returns> public string GetHighestPercentageOfTestsPerDayWithDate() { string highestPercentage; var date = string.Empty; try { var highestPercentageRecord = this.covidStatistics.FindRecordWithHighestPercentageOfPositiveTests(); var positivePercentage = CovidDataStatistics.FindPositivePercentageForRecord(highestPercentageRecord); highestPercentage = Format.FormatNumericValueAsPercentage(positivePercentage); date = highestPercentageRecord.Date.ToString(Assets.DateStringFormatted); } catch (Exception) { highestPercentage = Assets.NoPositiveData; } return(CovidDataLines.GetCovidLineForValueAndDate(Assets.HighestPercentageOfPositiveCasesLabel, highestPercentage, date)); }
public void TestMultipleItemCovidDataCollectionLastPlace() { var record1 = new CovidRecord(this.inputDate1, "GA"); var record2 = new CovidRecord(this.inputDate2, "GA"); var record3 = new CovidRecord(this.inputDate3, "GA") { PositiveTests = 1 }; var covidCollection = new CovidDataCollection { record1, record2, record3 }; var statistics = new CovidDataStatistics(covidCollection); var result = statistics.FindDayOfFirstPositiveTest(); Assert.AreEqual(this.inputDate3, result.Date); }
public void TestZeroPositives() { var result = CovidDataStatistics.FindPositivePercentageForRecord(this.record1); Assert.AreEqual(double.NaN, result); }
public void TestFiftyPercentPositive() { var result = CovidDataStatistics.FindPositivePercentageForRecord(this.record3); Assert.AreEqual(0.5, result, Delta); }
public void TestOneHundredPercentPositive() { var result = CovidDataStatistics.FindPositivePercentageForRecord(this.record4); Assert.AreEqual(1.0, result, Delta); }