Example #1
0
        static async Task Main(string[] args)
        {
            try
            {
                //Collect Input
                string input = await Console.In.ReadToEndAsync();

                //Split input into lines
                string[] processedInput = input.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
                //Validate and parse command line arguments into a data structure containing orders
                IOrderInputParser orderInputParser = new OrderInputParser();
                List <int>[]      parsedOrders     = orderInputParser.ParseOrders(ordersInput: processedInput);
                //Calculate the sum of prize money passed out
                IPrizeMoneyCalculator prizeMoneyCalculator = new TotalPrizeMoneyCalculator(parsedOrders: parsedOrders);
                int totalGiveOutPrizeMoney = prizeMoneyCalculator.CalculateTotal();
                //Display Prize Money
                Console.WriteLine(totalGiveOutPrizeMoney);
            }
            catch (Exception ex)
            {   //Display error message
                if (ex.InnerException != default)
                {
                    Console.WriteLine(ex.InnerException.Message);
                }
                else
                {
                    Console.WriteLine(ex.Message);
                }
            }
        }
Example #2
0
        public void ExpectedOutputTest()
        {
            //Arrange
            string[] processedInput = InputGenerator.GenerateTestInput(new string[] { "5",
                                                                                      "3 1 2 3",
                                                                                      "2 1 1",
                                                                                      "4 10 5 5 1",
                                                                                      "0",
                                                                                      "1 2" });

            //Act
            OrderInputParser orderInputParser = new OrderInputParser();

            TotalPrizeMoneyCalculator totalPrizeMoneyCalculator = new TotalPrizeMoneyCalculator(orderInputParser.ParseOrders(processedInput));

            //Assert
            Assert.AreEqual(19, totalPrizeMoneyCalculator.CalculateTotal());
        }
Example #3
0
        public void NegativeDayOrderAmount()
        {
            //Arrange
            string[] processedInput = InputGenerator.GenerateTestInput(new string[] { "1",
                                                                                      "-2 4  3" });

            //Act
            try
            {
                //Act
                OrderInputParser          orderInputParser          = new OrderInputParser();
                TotalPrizeMoneyCalculator totalPrizeMoneyCalculator = new TotalPrizeMoneyCalculator(orderInputParser.ParseOrders(processedInput));
                totalPrizeMoneyCalculator.CalculateTotal();
            }
            catch (Exception ex)
            {
                Assert.AreEqual("Issue During Parsing Invalid Character Detected - Check Input", ex.InnerException.Message);
            }
        }
Example #4
0
        public void CampaignDayAmountOrderlineMisMatch2()
        {
            //Arrange
            string[] processedInput = InputGenerator.GenerateTestInput(new string[] { "2",
                                                                                      "3 1 2 3" });

            //Act
            try
            {
                //Act
                OrderInputParser          orderInputParser          = new OrderInputParser();
                TotalPrizeMoneyCalculator totalPrizeMoneyCalculator = new TotalPrizeMoneyCalculator(orderInputParser.ParseOrders(processedInput));
                totalPrizeMoneyCalculator.CalculateTotal();
            }
            catch (Exception ex)
            {
                Assert.AreEqual("Campaign Day Amout Does Not Match Order Detail Lines Sum", ex.Message);
            }
        }
Example #5
0
        public void GreaterThenValidTotalOrderAmount()
        {
            //Arrange
            string[] processedInput = InputGenerator.GenerateTestInput(new string[] { "1",
                                                                                      "10 100000 100000 100000 100000 100000 100000 100000 100000 100000 100001" });

            //Act
            try
            {
                //Act
                OrderInputParser          orderInputParser          = new OrderInputParser();
                TotalPrizeMoneyCalculator totalPrizeMoneyCalculator = new TotalPrizeMoneyCalculator(orderInputParser.ParseOrders(processedInput));
                totalPrizeMoneyCalculator.CalculateTotal();
            }
            catch (Exception ex)
            {
                Assert.AreEqual("Total order amount cannot exceed 1000000", ex.Message);
            }
        }
Example #6
0
        public void GreaterThenValidDayOrderAmount()
        {
            //Arrange
            string[] processedInput = InputGenerator.GenerateTestInput(new string[] { "1",
                                                                                      "100001 4  3" });

            //Act
            try
            {
                //Act
                OrderInputParser          orderInputParser          = new OrderInputParser();
                TotalPrizeMoneyCalculator totalPrizeMoneyCalculator = new TotalPrizeMoneyCalculator(orderInputParser.ParseOrders(processedInput));
                totalPrizeMoneyCalculator.CalculateTotal();
            }
            catch (Exception ex)
            {
                Assert.AreEqual("Invalid Day Amount Detected - Ensure Each Day Amount Is Valid", ex.InnerException.Message);
            }
        }
Example #7
0
 public void NoInputTest()
 {
     //Arrange
     string[] processedInput = default;
     //Act
     try
     {
         //Act
         OrderInputParser          orderInputParser          = new OrderInputParser();
         TotalPrizeMoneyCalculator totalPrizeMoneyCalculator = new TotalPrizeMoneyCalculator(orderInputParser.ParseOrders(processedInput));
         totalPrizeMoneyCalculator.CalculateTotal();
     }
     catch (Exception ex)
     {
         Assert.AreEqual("No Input Detected", ex.Message);
     }
 }
Example #8
0
        public void StressTest()
        {
            bool passed = false;

            try
            {
                //Arrange
                string[] processedInput = InputGenerator.GenerateTestInput(1000, 1000, "1");

                //Act
                OrderInputParser          orderInputParser          = new OrderInputParser();
                TotalPrizeMoneyCalculator totalPrizeMoneyCalculator = new TotalPrizeMoneyCalculator(orderInputParser.ParseOrders(processedInput));
                int totalGivenPrizeMoeny = totalPrizeMoneyCalculator.CalculateTotal();

                passed = true;
            }
            catch (Exception ex)
            {
            }

            //Assert
            Assert.AreEqual(true, passed);
        }