Example #1
0
        public void TestCreateSize()
        {
            ATMClass             newATM       = new ATMClass();
            List <(string, int)> ATMinventory = newATM.Inventory().ToList();

            Assert.AreEqual(ATMinventory.Count, 6);
        }
Example #2
0
        public void TestCreateList()
        {
            ATMClass             newATM     = new ATMClass();
            List <(string, int)> targetList = new List <(string, int)> {
                ("$100", 10),
                ("$50", 10),
                ("$20", 10),
                ("$10", 10),
                ("$5", 10),
                ("$1", 10)
            };
            List <(string, int)> ATMinventory = newATM.Inventory().ToList();

            CollectionAssert.AreEqual(targetList, ATMinventory, Comparer <(string, int)> .Create((x, y) => x.Item1 == y.Item1 && x.Item2 == y.Item2 ? 0 : -1));
        }
Example #3
0
        public void TestWithdraw1()
        {
            ATMClass newATM         = new ATMClass();
            int      withdrawAmount = newATM.Withdraw(208);

            Assert.AreEqual(withdrawAmount, 208);

            List <(string, int)> ATMinventory = newATM.Inventory().ToList();

            CollectionAssert.AreEqual(new List <(string, int)> {
                ("$100", 8),
                ("$50", 10),
                ("$20", 10),
                ("$10", 10),
                ("$5", 9),
                ("$1", 7)
            }
Example #4
0
        static void Main(string[] args)
        {
            ATMClass myATM = new ATMClass();

            while (true)
            {
                string   inputString    = Console.ReadLine();
                string[] inputArguments = inputString.Split(' ');
                switch (inputArguments[0])
                {
                case "I":
                    DisplayInventory(myATM.Inventory(inputArguments.Skip(1).ToArray()).ToList());
                    break;

                case "R":
                    myATM.Restock();
                    DisplayInventory(myATM.Inventory().ToList());
                    break;

                case "W":
                    try
                    {
                        int withdrawAmount = 0;
                        int amountReceived = 0;
                        if (int.TryParse(inputArguments[1].Trim('$'), out withdrawAmount))
                        {
                            amountReceived = myATM.Withdraw(withdrawAmount);
                        }
                        Console.WriteLine("Success: Dispensed ${0}", amountReceived.ToString());
                        Console.WriteLine("Machine balance:");
                        DisplayInventory(myATM.Inventory().ToList());
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("Failure: {0}", ex.Message);
                    }
                    break;

                default:
                    Console.WriteLine("Failure: Invalid Command");
                    break;
                }
            }
        }