Beispiel #1
0
        public void Test()
        {
            var taxi = new Taxi();

            var calculador = new TollCalculator();
            var res        = calculador.CalculateToll(taxi);

            Assert.AreEqual(3.50m, res);
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            var tollCalc = new TollCalculator();

            var car   = new Car();
            var taxi  = new Taxi();
            var bus   = new Bus();
            var truck = new DeliveryTruck();

            Console.WriteLine($"The toll for a car is {tollCalc.CalculateToll(car)}");
            Console.WriteLine($"The toll for a taxi is {tollCalc.CalculateToll(taxi)}");
            Console.WriteLine($"The toll for a bus is {tollCalc.CalculateToll(bus)}");
            Console.WriteLine($"The toll for a truck is {tollCalc.CalculateToll(truck)}");

            try
            {
                tollCalc.CalculateToll("this will fail");
            }
            catch (ArgumentException e)
            {
                Console.WriteLine("Caught an argument exception when using the wrong type");
            }
            try
            {
                tollCalc.CalculateToll(null);
            }
            catch (ArgumentNullException e)
            {
                Console.WriteLine("Caught an argument exception when using null");
            }
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            /*   First set of test code */
            var tollCalc = new TollCalculator();

            var car   = new Car();
            var taxi  = new Taxi();
            var bus   = new Bus();
            var truck = new DeliveryTruck();

            Console.WriteLine($"The toll for a car is {tollCalc.CalculateToll(car)}");
            Console.WriteLine($"The toll for a taxi is {tollCalc.CalculateToll(taxi)}");
            Console.WriteLine($"The toll for a bus is {tollCalc.CalculateToll(bus)}");
            Console.WriteLine($"The toll for a truck is {tollCalc.CalculateToll(truck)}");

            try
            {
                tollCalc.CalculateToll("this will fail");
            }
            catch (ArgumentException e)
            {
                Console.WriteLine("Caught an argument exception when using the wrong type");
                Console.WriteLine($"{e.Message}");
            }
            try
            {
                tollCalc.CalculateToll(null);
            }
            catch (ArgumentNullException e)
            {
                Console.WriteLine("Caught an argument exception when using null");
                Console.WriteLine($"{e.Message}");
            }

            /*  2nd test (after adding for occupants)
             * var tollCalc = new TollCalculator();
             *
             * var soloDriver = new Car();
             * var twoRideShare = new Car { Passengers = 1 };
             * var threeRideShare = new Car { Passengers = 2 };
             * var fullVan = new Car { Passengers = 5 };
             * var emptyTaxi = new Taxi();
             * var singleFare = new Taxi { Fares = 1 };
             * var doubleFare = new Taxi { Fares = 2 };
             * var fullVanPool = new Taxi { Fares = 5 };
             * var lowOccupantBus = new Bus { Capacity = 90, Riders = 15 };
             * var normalBus = new Bus { Capacity = 90, Riders = 75 };
             * var fullBus = new Bus { Capacity = 90, Riders = 85 };
             *
             * var heavyTruck = new DeliveryTruck { GrossWeightClass = 7500 };
             * var truck = new DeliveryTruck { GrossWeightClass = 4000 };
             * var lightTruck = new DeliveryTruck { GrossWeightClass = 2500 };
             *
             * Console.WriteLine($"The toll for a solo driver is {tollCalc.CalculateToll(soloDriver)}");
             * Console.WriteLine($"The toll for a two ride share is {tollCalc.CalculateToll(twoRideShare)}");
             * Console.WriteLine($"The toll for a three ride share is {tollCalc.CalculateToll(threeRideShare)}");
             * Console.WriteLine($"The toll for a fullVan is {tollCalc.CalculateToll(fullVan)}");
             *
             * Console.WriteLine($"The toll for an empty taxi is {tollCalc.CalculateToll(emptyTaxi)}");
             * Console.WriteLine($"The toll for a single fare taxi is {tollCalc.CalculateToll(singleFare)}");
             * Console.WriteLine($"The toll for a double fare taxi is {tollCalc.CalculateToll(doubleFare)}");
             * Console.WriteLine($"The toll for a full van taxi is {tollCalc.CalculateToll(fullVanPool)}");
             *
             * Console.WriteLine($"The toll for a low-occupant bus is {tollCalc.CalculateToll(lowOccupantBus)}");
             * Console.WriteLine($"The toll for a regular bus is {tollCalc.CalculateToll(normalBus)}");
             * Console.WriteLine($"The toll for a bus is {tollCalc.CalculateToll(fullBus)}");
             *
             * Console.WriteLine($"The toll for a truck is {tollCalc.CalculateToll(heavyTruck)}");
             * Console.WriteLine($"The toll for a truck is {tollCalc.CalculateToll(truck)}");
             * Console.WriteLine($"The toll for a truck is {tollCalc.CalculateToll(lightTruck)}");
             *
             * try
             * {
             *  tollCalc.CalculateToll("this will fail");
             * }
             * catch (ArgumentException e)
             * {
             *  Console.WriteLine("Caught an argument exception when using the wrong type");
             * }
             * try
             * {
             *  tollCalc.CalculateToll(null);
             * }
             * catch (ArgumentNullException e)
             * {
             *  Console.WriteLine("Caught an argument exception when using null");
             * }
             */

            /*
             * Console.WriteLine("Testing the time premiums");
             *
             * var testTimes = new DateTime[]
             * {
             *  new DateTime(2019, 3, 4, 8, 0, 0), // morning rush
             *  new DateTime(2019, 3, 6, 11, 30, 0), // daytime
             *  new DateTime(2019, 3, 7, 17, 15, 0), // evening rush
             *  new DateTime(2019, 3, 14, 03, 30, 0), // overnight
             *
             *  new DateTime(2019, 3, 16, 8, 30, 0), // weekend morning rush
             *  new DateTime(2019, 3, 17, 14, 30, 0), // weekend daytime
             *  new DateTime(2019, 3, 17, 18, 05, 0), // weekend evening rush
             *  new DateTime(2019, 3, 16, 01, 30, 0), // weekend overnight
             * };
             *
             * foreach (var time in testTimes)
             * {
             *  Console.WriteLine($"Inbound premium at {time} is {tollCalc.PeakTimePremiumFull(time, true)}");
             *  Console.WriteLine($"Outbound premium at {time} is {tollCalc.PeakTimePremiumFull(time, false)}");
             * }
             * Console.WriteLine("====================================================");
             * foreach (var time in testTimes)
             * {
             *  Console.WriteLine($"Inbound premium at {time} is {tollCalc.PeakTimePremium(time, true)}");
             *  Console.WriteLine($"Outbound premium at {time} is {tollCalc.PeakTimePremium(time, false)}");
             * }
             */
        }