示例#1
0
        public void BookMultipleCabs_CheckAfterTicks_RideStatus()
        {
            var source1 = new Source(0, 1); var destination1 = new Destination(4, 2);
            var source2 = new Source(2, 0); var destination2 = new Destination(3, 5);

            var taxi1 = BookACab(source1, destination1);
            var taxi2 = BookACab(source2, destination2);

            Assert.AreNotEqual(taxi1, taxi2);
            Assert.AreEqual(taxi1.status, TaxiStatus.Booked);
            Assert.AreEqual(taxi2.status, TaxiStatus.Booked);

            var diffTimeForTaxi1 = new TimeAtDifferentPoints()
                                   .SetTimeAtDifferentPoints(new int[] { 0, 1, 3, 5 });

            var diffTimeForTaxi2 = new TimeAtDifferentPoints()
                                   .SetTimeAtDifferentPoints(new int[] { 0, 2, 3, 6 });



            //Increase Time to Reach to source
            SimpleTimeTracker <int> .Instance.IncrementTime(diffTimeForTaxi2.SourceReachedTime);

            Assert.IsTrue(taxi1.TaxiLocation.Equals(source1));
            Assert.IsTrue(taxi2.TaxiLocation.Equals(source2));
            Assert.AreEqual(taxi1.status, TaxiStatus.FinishingRide);
            Assert.AreEqual(taxi2.status, TaxiStatus.FinishingRide);

            //Increase Time to Reach to midway of journey
            SimpleTimeTracker <int> .Instance.IncrementTime(diffTimeForTaxi2.HalfJourneyTime - diffTimeForTaxi2.SourceReachedTime);

            //Assert.AreEqual(taxi.rides.Count, 1);
            Assert.IsTrue(taxi1.rides.Exists(x => x.OnGoing == true));
            Assert.IsTrue(taxi2.rides.Exists(x => x.OnGoing == true));


            //Increase Time to Reach to end of Journey for taxi1
            SimpleTimeTracker <int> .Instance
            .IncrementTime(diffTimeForTaxi1.SourceReachedTime +
                           diffTimeForTaxi1.ReachedDestinationTime -
                           diffTimeForTaxi1.HalfJourneyTime + 1);

            Assert.IsTrue(taxi1.rides.Exists(x => x.OnGoing == false));
            Assert.IsTrue(taxi1.TaxiLocation.Equals(destination1));
            Assert.AreEqual(taxi1.status, TaxiStatus.Available);

            //For taxi2 time need to be incremented by one more tick to finish ride
            SimpleTimeTracker <int> .Instance.IncrementTime();

            Assert.IsTrue(taxi2.rides.Exists(x => x.OnGoing == false));
            Assert.IsTrue(taxi2.TaxiLocation.Equals(destination2));
            Assert.AreEqual(taxi2.status, TaxiStatus.Available);
        }
示例#2
0
        public void BookACab_CheckAfterTicks_RideStatus(int sx, int sy,
                                                        int dx, int dy, int[] ticks)
        {
            var taxiBookingService = new TaxiBookingService();
            var rand        = new Random();
            var source      = new Source(sx, sy);
            var destination = new Destination(dx, dy);

            var taxi = taxiBookingService.GetTaxi(source,
                                                  destination);

            Assert.IsNotNull(taxi);

            var diffTimes = new TimeAtDifferentPoints();

            diffTimes.StartTime              = ticks[0];
            diffTimes.SourceReachedTime      = ticks[1];
            diffTimes.HalfJourneyTime        = ticks[2];
            diffTimes.ReachedDestinationTime = ticks[3];

            Assert.AreEqual(taxi.status, TaxiStatus.Booked);

            //Increase Time to Reach to source
            SimpleTimeTracker <int> .Instance.IncrementTime(diffTimes.SourceReachedTime);

            Assert.IsTrue(taxi.TaxiLocation.Equals(source));
            Assert.AreEqual(taxi.status, TaxiStatus.FinishingRide);


            //Increase Time to Reach to midway of journey
            SimpleTimeTracker <int> .Instance.IncrementTime(diffTimes.HalfJourneyTime - diffTimes.SourceReachedTime);

            //Assert.AreEqual(taxi.rides.Count, 1);
            Assert.IsTrue(taxi.rides.Exists(x => x.OnGoing == true));


            //Increase Time to Reach to end of Journey
            SimpleTimeTracker <int> .Instance
            .IncrementTime(diffTimes.SourceReachedTime + diffTimes.ReachedDestinationTime - diffTimes.HalfJourneyTime);

            Assert.IsTrue(taxi.rides.Exists(x => x.OnGoing == false));
            Assert.IsTrue(taxi.TaxiLocation.Equals(destination));
            Assert.AreEqual(taxi.status, TaxiStatus.Available);
        }