Esempio n. 1
0
        public Taxi BookACab(Source source, Destination destination)
        {
            var taxiBookingService = new TaxiBookingService();

            return(taxiBookingService.GetTaxi(source,
                                              destination));
        }
        public void BookACab_WhenAllCabs_AreAvailable()
        {
            var taxiBookingService = new TaxiBookingService();
            var rand = new Random();
            var taxi = taxiBookingService.GetTaxi(new Source(rand.Next(9), rand.Next(9)),
                                                  new Destination(rand.Next(9), rand.Next(9)));

            Assert.IsNotNull(taxi);
            Assert.AreEqual(taxi.status, TaxiStatus.Booked);
        }
Esempio n. 3
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);
        }
        public void BookACab_WhenNoCab_IsAvailable()
        {
            var taxiBookingService = new TaxiBookingService();
            var rand  = new Random();
            var taxi1 = taxiBookingService.GetTaxi(new Source(rand.Next(9), rand.Next(9)),
                                                   new Destination(rand.Next(9), rand.Next(9)));
            var taxi2 = taxiBookingService.GetTaxi(new Source(rand.Next(9), rand.Next(9)),
                                                   new Destination(rand.Next(9), rand.Next(9)));

            var taxi3 = taxiBookingService.GetTaxi(new Source(rand.Next(9), rand.Next(9)),
                                                   new Destination(rand.Next(9), rand.Next(9)));

            var newTaxi = taxiBookingService.GetTaxi(new Source(rand.Next(9), rand.Next(9)),
                                                     new Destination(rand.Next(9), rand.Next(9)));

            Assert.IsNull(newTaxi);

            TaxiFleet.Instance.ResetTaxis();
        }
        public void BookANearestCab_WhenMultipleCabsAreAvailable()
        {
            var taxiBookingService = new TaxiBookingService();

            var source = new Source(0, 0); var destination = new Destination(3, 4);
            //get a taxi for a particular destination;
            var taxi1 = taxiBookingService.GetTaxi(source, destination);

            SimpleTimeTracker <int> .Instance.IncrementTime(7);

            //check whether taxi reached to destination
            Assert.AreEqual(taxi1.TaxiLocation, destination);

            //here distance from taxi1 to next source is 3
            //distnace from 0,0 to next source is 4
            //so taxi1 should be booked.
            var nextsource      = new Source(1, 3);
            var nextdestination = new Destination(3, 5);
            var sametaxi        = taxiBookingService.GetTaxi(nextsource, nextdestination);

            Assert.AreEqual(taxi1, sametaxi);
        }