static void Main(string[] args) { IReader reader = new XmlReader(); List <Entry> entries = reader.Read("data.xml"); ConsoleUserInterface ui = new ConsoleUserInterface(); DateTime[] range = ui.init(); List <Entry> entriesInRange = DateOperations.Intersection(entries, range[0], range[1]); List <Entry> sortedEntries = ValueOperations.SortByAscending(entriesInRange); double avgInRange = ValueOperations.FindAverage(entriesInRange); int maxInRange = ValueOperations.FindMax(entriesInRange); IWriter writer = new FileWriter(); writer.AddToWrite("Entries in range " + range[0].ToString("yyyy/MM/dd") + " - " + range[1].ToString("yyyy/MM/dd") + ":"); foreach (Entry entry in entriesInRange) { writer.AddToWrite("Date: " + entry.Date.ToString("yyyy/MM/dd") + " Value: " + entry.Value); } writer.AddToWrite("Sorted by value in ascending order:"); foreach (Entry entry in sortedEntries) { writer.AddToWrite("Date: " + entry.Date.ToString("yyyy/MM/dd") + " Value: " + entry.Value); } writer.AddToWrite("Average value: " + avgInRange); writer.AddToWrite("Max value: " + maxInRange); writer.Write(); }
public void MaxValueTest() { List <Entry> entries = new List <Entry> { new Entry { Date = new DateTime(2019, 10, 1), Value = 3 }, new Entry { Date = new DateTime(2019, 10, 2), Value = 4 }, new Entry { Date = new DateTime(2019, 10, 3), Value = 7 }, new Entry { Date = new DateTime(2019, 10, 4), Value = 2 }, new Entry { Date = new DateTime(2019, 10, 5), Value = 1 }, new Entry { Date = new DateTime(2019, 10, 6), Value = 6 }, new Entry { Date = new DateTime(2019, 10, 7), Value = 10 }, }; int expected = 10; double actual = ValueOperations.FindMax(entries); Assert.AreEqual(expected, actual); }