コード例 #1
0
        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)));
        }
コード例 #2
0
        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)));
        }
コード例 #3
0
        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)));
        }
コード例 #4
0
        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)));
        }
コード例 #5
0
        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)));
        }
コード例 #6
0
        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)));
        }
コード例 #7
0
        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)));
        }
コード例 #8
0
        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)));
        }
コード例 #9
0
        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)));
        }
コード例 #10
0
        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);
        }
コード例 #11
0
        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));
        }
コード例 #12
0
        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)));
        }
コード例 #13
0
        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)));
        }
コード例 #14
0
        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);
        }
コード例 #15
0
        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));
        }
コード例 #16
0
        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);
        }
コード例 #17
0
        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)));
        }
コード例 #18
0
        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);
        }
コード例 #19
0
        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)));
        }
コード例 #20
0
        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)));
        }
コード例 #21
0
        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();
        }
コード例 #22
0
        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);
            }
        }
コード例 #23
0
        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);
        }
コード例 #24
0
 public void TestNegativeDaysCount()
 {
     DateTime result = new WorkDayCalculator().Calculate(DateTime.Now, -42, null);
 }