// [Test, TestCaseSource(typeof(TestCaseFactory), "ScheduleCases")] public void CanLoadJobs(string inputFile, string outputFile) { (var info, var jobs) = ScheduleLoader.LoadData(inputFile); var count = File.ReadAllLines(inputFile).Count(); Assert.AreEqual(count, jobs.Count + 1); }
// [Test, TestCaseSource(typeof(TestCaseFactory), "ScheduleCases")] public void CanCalculateCompletionTimes(string inputFile, string outputFile) { var times = ScheduleLoader.CalculateWeightedCompletionTime(inputFile); var actual = File.ReadLines(outputFile).WhereNotNull().Select(long.Parse); Assert.AreEqual(actual.Last(), times.optimal, message: "optimal check failed"); Assert.AreEqual(actual.First(), times.poor, message: "poor check failed"); }
public void TestParseSuccess() { const string testData = "928;Y009OT;02/06/2020T04:55:00Z+03:00;02/06/2020T06:00:00Z+03:00"; var schedule = ScheduleLoader.Parse(testData); if (schedule.Route != "928" || schedule.Transport != "Y009OT" || schedule.Begin != new DateTime(2020, 06, 02, 01, 55, 00, DateTimeKind.Utc).ToLocalTime() || schedule.End != new DateTime(2020, 06, 02, 3, 00, 00, DateTimeKind.Utc).ToLocalTime()) { throw new Exception($"Parse schedule."); } }
private ScheduleLoader InitialiseLoader(SqlConnection connection) { var sequence = new Sequence(); var lookup = Substitute.For <IDatabaseIdLookup>(); lookup.Find(Arg.Any <string>()).Returns(c => sequence.GetNext()); _schedules = new ScheduleHeaderLoader(connection, new Sequence(), Substitute.For <ILogger>()); _locations = new ScheduleLocationLoader(connection, new Sequence(), lookup, Substitute.For <ILogger>()); _changes = new ScheduleChangeLoader(connection, new Sequence(), Substitute.For <ILogger>()); var loader = new ScheduleLoader(_schedules, _locations, _changes, Substitute.For <ILogger>()); loader.Initialise(); return(loader); }
public void TestParseFailed() { const string testData = "53173067906170E111OK;bus"; try { _ = ScheduleLoader.Parse(testData); } catch (FormatException) { return; } throw new Exception($"An exception was expected `FormatException`."); }
public void TestParseEmptyStringFailed() { const string testData = ""; try { _ = ScheduleLoader.Parse(testData); } catch (FormatException) { return; } throw new Exception($"An exception was expected `FormatException`."); }
public void TestParseFailed() { const string testData = "928;Y009OT;02/06/2020T04:65:00Z+03:00;02/06/2020T06:00:00Z+03:00"; try { _ = ScheduleLoader.Parse(testData); } catch (FormatException) { return; } throw new Exception($"An exception was expected `FormatException`."); }
public void TestParseStreamSkipeEmptySuccess() { const string testData = @" 928;Y009OT;02/06/2020T04:55:00Z+03:00;02/06/2020T06:00:00Z+03:00 928;A590OM;02/06/2020T15:50:00Z+03:00;02/06/2020T16:55:00Z+03:00 102;Y009OT;02/06/2020T06:30:00Z+03:00;02/06/2020T13:30:00Z+03:00 102;A590OM;02/06/2020T05:25:00Z+03:00;02/06/2020T12:30:00Z+03:00 "; byte[] byteArray = Encoding.ASCII.GetBytes(testData); using var ms = new MemoryStream(byteArray); using var sr = new StreamReader(ms); var schedules = ScheduleLoader.Read(sr); if (schedules.Count != 4) { throw new Exception($"4 routes were expected, {schedules.Count} were considered."); } }
static void Main(string[] args) { var times = ScheduleLoader.CalculateWeightedCompletionTime("schedule_data.txt"); Console.WriteLine($"poor: {times.poor}, optimal: {times.optimal}"); }
public void SetUp() { fixture = new Fixture().Customize(new AutoMoqCustomization()); fileReaderMock = fixture.Freeze <Mock <IFileReader> >(); scheduleLoader = fixture.Create <ScheduleLoader>(); }