示例#1
0
        public void When_Same_Start_Dates_Compare_By_End_Date()
        {
            var sut = new DateRangeComparer();

            sut.Compare(DateRange.Year(2017), DateRange.Years(2017, 2)).Should().Be(-1);
            sut.Compare(DateRange.Years(2017, 2), DateRange.Year(2017)).Should().Be(1);
        }
示例#2
0
        public void When_Different_Start_Dates_Compare_By_StartDate()
        {
            var sut = new DateRangeComparer();

            sut.Compare(DateRange.Year(2017), DateRange.Year(2018)).Should().Be(-1);
            sut.Compare(DateRange.Year(2018), DateRange.Year(2017)).Should().Be(1);
        }
示例#3
0
        public void Never_Must_Be_Smallest()
        {
            var sut = new DateRangeComparer();

            sut.Compare(DateRange.Never, DateRange.Always).Should().Be(-1);
            sut.Compare(DateRange.Always, DateRange.Never).Should().Be(1);
        }
        public static void Main()
        {
            var dates = new Dictionary <DateTime, DateTime>
            {
                {
                    new DateTime(2020, 3, 8),
                    new DateTime(2020, 3, 9)
                },
                {
                    new DateTime(2020, 3, 5),
                    new DateTime(2020, 3, 6)
                },
                {
                    new DateTime(2020, 1, 1),
                    new DateTime(2020, 1, 15)
                },
                {
                    new DateTime(2020, 2, 21),
                    new DateTime(2020, 2, 29)
                },
                {
                    new DateTime(2020, 1, 15),
                    new DateTime(2020, 1, 17)
                },
                {
                    new DateTime(2020, 1, 1),
                    new DateTime(2020, 1, 18)
                },
            };

            Console.WriteLine($"Collection {nameof( dates )} contains {dates.Count} elements");

            var dateRangePackage = new DateRangePackage(dates.Select(pair => new Lesson.Libs.Common.Types.DateRange(pair.Value, pair.Key)).ToList());

            var comparer = new DateRangeComparer();

            Console.WriteLine($"Before:   {dateRangePackage}");

            BubbleSort.Sort(dateRangePackage.DateRanges, comparer);

            Console.WriteLine($"After:    {dateRangePackage}");

            var expectedDateRangePackage = new DateRangePackage(dateRangePackage.DateRanges.OrderBy(dateRange => dateRange, comparer).ToList());

            Console.WriteLine($"Expected: {expectedDateRangePackage}");

            Console.WriteLine("Press ENTER to end execution...");
            Console.ReadLine();
        }
示例#5
0
        public void Unbounded_Compare_Returns_Zero()
        {
            var sut = new DateRangeComparer();

            sut.Compare(DateRange.Always, DateRange.Always).Should().Be(0);
        }