コード例 #1
0
        public void TestRangeQuery()
        {
            const uint appointmentBookSize = 24;

            var a = new AppointmentMap(DateTime.Parse("03/1/2018"), appointmentBookSize);

            SortedSet <DateTime> allocatedDates = new SortedSet <DateTime>();

            for (var i = 0; i < 100; i++)
            {
                var result = a.ReserveFirstAvailableExcludeRequestedDate();
                Assert.IsTrue(result.Item1);
                allocatedDates.Add(result.Item2);
            }

            var maxDate = allocatedDates.Max;
            var refDate = maxDate;

            const int rangeSize = 10;

            var expectedRange = Enumerable.Range(1, rangeSize).Aggregate(new List <DateTime>(), (l, inex) =>
            {
                refDate = GetNextExpectedReservationDate(refDate);
                l.Add(refDate);
                return(l);
            });


            var availableRange = a.RetrieveFirstAvailableDateRangeExcludeRequestedDate(rangeSize);

            for (int i = 0; i < rangeSize; i++)
            {
                Assert.IsTrue(expectedRange[i] == availableRange[i]);
            }
        }
コード例 #2
0
        public void TestRangeQueryWhereAppointmentHasHolesinReservedSpots()
        {
            const uint appointmentBookSize = 24;

            var a = new AppointmentMap(DateTime.Parse("03/1/2018"), appointmentBookSize);

            Dictionary <int, DateTime> allocatedDates = new Dictionary <int, DateTime>();

            for (var i = 0; i < 100; i++)
            {
                var result = a.ReserveFirstAvailableExcludeRequestedDate();
                Assert.IsTrue(result.Item1);
                allocatedDates.Add(i, result.Item2);
            }

            const int rangeSize = 10;

            var cancelledAppointments = new SortedSet <DateTime>();

            var random = new Random();

            for (int i = 0; i < rangeSize; i++)
            {
                var j = random.Next(0, allocatedDates.Count);
                if (allocatedDates.ContainsKey(j))
                {
                    a.CancelAppointment(allocatedDates[j]);
                    cancelledAppointments.Add(allocatedDates[j]);
                }
            }

            var tempList = cancelledAppointments.ToList();


            var availableAppointmentRange = a.RetrieveFirstAvailableDateRangeExcludeRequestedDate(rangeSize);

            for (int i = 0; i < Math.Min(availableAppointmentRange.Count, tempList.Count); i++)
            {
                Assert.IsTrue(tempList[i] == availableAppointmentRange[i],
                              string.Format("failed Comarison for {0}: {1}, {2}",
                                            i, tempList[i], availableAppointmentRange[i]));
            }
        }