public void TestOneDayWeekend() { DateTime startDate = new DateTime(2019, 3, 27); int count = 1; WeekEnd[] weekends = new WeekEnd[1] { new WeekEnd(new DateTime(2019, 3, 28), new DateTime(2019, 3, 29)) }; DateTime result = new WorkDayCalculator().Calculate(startDate, count, weekends); Assert.IsTrue(result.Equals(new DateTime(2019, 3, 27))); }
public void TestWeekendBeforeStart() { DateTime startDate = new DateTime(2017, 4, 21); int count = 5; WeekEnd[] weekends = new WeekEnd[2] { new WeekEnd(new DateTime(2017, 4, 15), new DateTime(2017, 4, 16)), new WeekEnd(new DateTime(2017, 4, 19), new DateTime(2017, 4, 22)) }; DateTime result = new WorkDayCalculator().Calculate(startDate, count, weekends); Assert.IsTrue(result.Equals(new DateTime(2017, 4, 27))); }
public void TestWeekendAfterEnd() { DateTime startDate = new DateTime(2017, 4, 21); int count = 5; WeekEnd[] weekends = new WeekEnd[2] { new WeekEnd(new DateTime(2017, 4, 23), new DateTime(2017, 4, 25)), new WeekEnd(new DateTime(2017, 4, 29), new DateTime(2017, 4, 29)) }; DateTime result = new WorkDayCalculator().Calculate(startDate, count, weekends); Assert.IsTrue(result.Equals(new DateTime(2017, 4, 28))); }
public void TestConsecutiveWeekends() { DateTime startDate = new DateTime(2017, 4, 10); int count = 7; WeekEnd[] weekends = new WeekEnd[2] { new WeekEnd(new DateTime(2017, 4, 13), new DateTime(2017, 4, 15)), new WeekEnd(new DateTime(2017, 4, 16), new DateTime(2017, 4, 17)) }; DateTime result = new WorkDayCalculator().Calculate(startDate, count, weekends); Assert.IsTrue(result.Equals(new DateTime(2017, 4, 21))); }
public void TestStartOnWeekend() { DateTime startDate = new DateTime(2017, 4, 10); int count = 7; WeekEnd[] weekends = new WeekEnd[2] { new WeekEnd(new DateTime(2017, 4, 8), new DateTime(2017, 4, 12)), new WeekEnd(new DateTime(2017, 4, 17), new DateTime(2017, 4, 18)) }; DateTime result = new WorkDayCalculator().Calculate(startDate, count, weekends); Assert.IsTrue(result.Equals(new DateTime(2017, 4, 21))); }
public void TestDoubleWeekends() { DateTime startDate = new DateTime(2017, 4, 1); int count = 10; WeekEnd[] weekends = new WeekEnd[2] { new WeekEnd(new DateTime(2017, 4, 2), new DateTime(2017, 4, 4)), new WeekEnd(new DateTime(2017, 4, 6), new DateTime(2017, 4, 7)) }; DateTime result = new WorkDayCalculator().Calculate(startDate, count, weekends); Assert.IsTrue(result.Equals(new DateTime(2017, 4, 15))); }
public void TestBeginAndEndIn1dayWeekends() { DateTime startDate = new DateTime(2017, 4, 13); int count = 3; WeekEnd[] weekends = new WeekEnd[2] { new WeekEnd(new DateTime(2017, 4, 13), new DateTime(2017, 4, 13)), new WeekEnd(new DateTime(2017, 4, 18), new DateTime(2017, 4, 18)) }; DateTime result = WorkDayCalculator.Calculate(startDate, count, weekends); Assert.IsTrue(result.Equals(new DateTime(2017, 4, 16))); }
public void TestNormalPathMultiplyWeekends() { DateTime startDate = new DateTime(2017, 4, 21); int count = 6; WeekEnd[] weekends = new WeekEnd[2] { new WeekEnd(new DateTime(2017, 4, 23), new DateTime(2017, 4, 25)), new WeekEnd(new DateTime(2017, 4, 29), new DateTime(2017, 4, 29)) }; DateTime result = new WorkDayCalculator().Calculate(startDate, count, weekends); Assert.IsTrue(result.Equals(new DateTime(2017, 4, 30))); }
public void TestBetweenWeekends() { DateTime startDate = new DateTime(2017, 4, 20); int count = 5; WeekEnd[] weekends = new WeekEnd[2] { new WeekEnd(new DateTime(2017, 4, 10), new DateTime(2017, 4, 15)), new WeekEnd(new DateTime(2017, 4, 25), new DateTime(2017, 4, 29)) }; DateTime result = WorkDayCalculator.Calculate(startDate, count, weekends); Assert.IsTrue(result.Equals(new DateTime(2017, 4, 24))); }
public void TestHighLoad() { DateTime startDate = new DateTime(2017, 4, 1); int count = 5; WeekEnd[] weekends = new WeekEnd[100]; for (int i = 0; i < 100; i++) { weekends[i] = new WeekEnd(startDate.AddDays(i), startDate.AddDays(i)); } DateTime result = new WorkDayCalculator().Calculate(startDate, count, weekends); Assert.AreEqual(new DateTime(2017, 7, 14), result); }
public void TestZeroDaysCount() { DateTime startDate = new DateTime(2017, 4, 10); int count = 0; WeekEnd[] weekends = new WeekEnd[2] { new WeekEnd(new DateTime(2017, 4, 13), new DateTime(2017, 4, 15)), new WeekEnd(new DateTime(2017, 4, 16), new DateTime(2017, 4, 17)) }; DateTime result = new WorkDayCalculator().Calculate(startDate, count, weekends); Assert.IsTrue(result.Equals(startDate)); }
public void TestWeekendBeforeStart() { DateTime startDate = new DateTime(2017, 4, 10); int count = 7; WeekEnd[] weekends = new WeekEnd[2] { new WeekEnd(new DateTime(2017, 4, 7), new DateTime(2017, 4, 9)), new WeekEnd(new DateTime(2017, 4, 13), new DateTime(2017, 4, 14)) }; DateTime result = new WorkDayCalculator().Calculate(startDate, count, weekends); Assert.IsTrue(result.Equals(new DateTime(2017, 4, 18))); }
public void TestStartDateInAnotherMonth() { DateTime startDate = new DateTime(2017, 4, 21); int count = 20; WeekEnd[] weekends = new WeekEnd[2] { new WeekEnd(new DateTime(2017, 5, 1), new DateTime(2017, 5, 2)), new WeekEnd(new DateTime(2017, 5, 8), new DateTime(2017, 5, 10)) }; DateTime result = new WorkDayCalculator().Calculate(startDate, count, weekends); Assert.IsTrue(result.Equals(new DateTime(2017, 5, 12))); }
public void Test_Weekends_Start_And_Finish_Date() { DateTime startDate = new DateTime(2019, 9, 1); int count = 5; DateTime expected = new DateTime(2019, 9, 10); WeekEnd[] weekends = new WeekEnd[] { new WeekEnd(new DateTime(2019, 9, 1), new DateTime(2019, 9, 5)) }; DateTime result = new WorkDayCalculator().Calculate(startDate, count, weekends); Assert.AreEqual(expected, result); }
public void TestImposedWeekends() { DateTime startDate = new DateTime(2017, 4, 21); int count = 6; WeekEnd[] weekends = new [] { new WeekEnd(new DateTime(2017, 4, 23), new DateTime(2017, 4, 24)), new WeekEnd(new DateTime(2017, 4, 24), new DateTime(2017, 4, 25)) }; DateTime result = new WorkDayCalculator().Calculate(startDate, count, weekends); Assert.AreEqual(result, new DateTime(2017, 4, 29)); }
public void TestNoWeekEnd() { WeekEnd[] weekends = new WeekEnd[3] { new WeekEnd(new DateTime(2017, 4, 23), new DateTime(2017, 4, 25)), new WeekEnd(new DateTime(2018, 4, 29), new DateTime(2019, 4, 29)), new WeekEnd(new DateTime(2017, 4, 29), new DateTime(2017, 4, 29)) }; DateTime startDate = new DateTime(2014, 12, 1); int count = 10; DateTime result = new WorkDayCalculator().Calculate(startDate, count, weekends); Assert.AreEqual(startDate.AddDays(count - 1), result); }
public void Test3Weekends() { DateTime startDate = new DateTime(2017, 4, 20); int count = 5; WeekEnd[] weekends = new WeekEnd[3] { new WeekEnd(new DateTime(2017, 4, 21), new DateTime(2017, 4, 21)), new WeekEnd(new DateTime(2017, 4, 23), new DateTime(2017, 4, 25)), new WeekEnd(new DateTime(2017, 4, 26), new DateTime(2017, 4, 29)) }; DateTime result = WorkDayCalculator.Calculate(startDate, count, weekends); Assert.IsTrue(result.Equals(new DateTime(2017, 5, 2))); }
public void TestOneDay_No_Weekends() { //Arrange. DateTime startDate = new DateTime(2020, 2, 4); int count = 1; WeekEnd[] weekends = new WeekEnd[0]; //Act. DateTime result = new WorkDayCalculator().Calculate(startDate, count, weekends); //Assert. DateTime expected = new DateTime(2020, 2, 4); Assert.AreEqual(expected, result); }
public void TestWithFewWeekend1() { DateTime startDate = new DateTime(2017, 4, 21); int count = 8; WeekEnd[] weekends = new WeekEnd[3] { new WeekEnd(new DateTime(2017, 4, 23), new DateTime(2017, 4, 25)), new WeekEnd(new DateTime(2017, 4, 29), new DateTime(2017, 4, 29)), new WeekEnd(new DateTime(2017, 5, 1), new DateTime(2017, 5, 2)) }; DateTime result = new WorkDayCalculator().Calculate(startDate, count, weekends); Assert.IsTrue(result.Equals(new DateTime(2017, 5, 4))); }
public void TestWeekendBeforeAndInsideAndAfter()//In this case the period is extended to the third weekend { DateTime startDate = new DateTime(2017, 4, 21); int count = 5; WeekEnd[] weekends = new WeekEnd[3] { new WeekEnd(new DateTime(2017, 4, 20), new DateTime(2017, 4, 22)), new WeekEnd(new DateTime(2017, 4, 25), new DateTime(2017, 4, 25)), new WeekEnd(new DateTime(2017, 4, 28), new DateTime(2017, 4, 29)) }; DateTime result = new WorkDayCalculator().Calculate(startDate, count, weekends); Assert.IsTrue(result.Equals(new DateTime(2017, 4, 30))); }
static void Main(string[] args) { DateTime startDate = new DateTime(2017, 4, 21); int dayCount = 7; WeekEnd[] weekends = new WeekEnd[2] { new WeekEnd(new DateTime(2017, 4, 23), new DateTime(2017, 4, 25)), new WeekEnd(new DateTime(2017, 4, 29), new DateTime(2017, 4, 29)) }; WorkDayCalculator wdk = new WorkDayCalculator(); wdk.Calculate(startDate, dayCount, weekends); Console.ReadKey(); }
static void Main(string[] args) { try { string[] Weekends = new string[2]; WorkDayCalculator calculator = new WorkDayCalculator(); Console.Write("Start date:"); DateTime Date = Convert.ToDateTime(Console.ReadLine()); Console.Write("Duration, day(s):"); uint Duration = UInt32.Parse(Console.ReadLine()); Console.Write("Weekends 1:"); string weekends = Console.ReadLine(); if (weekends != "0") { Weekends = weekends.Split('-'); } DateTime startWeek = Convert.ToDateTime(Weekends[0]); DateTime endtWeek = Convert.ToDateTime(Weekends[1]); WeekEnd[] weekEnd = new WeekEnd[] { new WeekEnd(startWeek, endtWeek) }; Console.Write("Weekends 2:"); weekends = Console.ReadLine(); if (weekends != "0") { Weekends = weekends.Split('-'); startWeek = Convert.ToDateTime(Weekends[0]); endtWeek = Convert.ToDateTime(Weekends[1]); Array.Resize(ref weekEnd, 2); weekEnd[1] = new WeekEnd(startWeek, endtWeek); } Console.WriteLine($"At the exit there should be: {calculator.Calculate(Date, Duration, weekEnd).ToShortDateString()}"); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
public void All() { //Arrange. DateTime startDate = new DateTime(2020, 1, 10); int count = 5; WeekEnd[] weekends = new WeekEnd[] { new WeekEnd(new DateTime(2019, 1, 1), new DateTime(2020, 1, 1)), // Left outside new WeekEnd(new DateTime(2019, 1, 10), new DateTime(2020, 1, 14)), // +5 Left and rght point Eq +1 new WeekEnd(new DateTime(2020, 2, 1), new DateTime(2020, 2, 10)), // Right outside }; //Act. DateTime result = new WorkDayCalculator().Calculate(startDate, count, weekends); //Assert. DateTime expected = new DateTime(2020, 1, 19); Assert.AreEqual(expected, result); }
public void TestNegativeDaysCount() { DateTime result = new WorkDayCalculator().Calculate(DateTime.Now, -42, null); }