Exemple #1
0
        public JsonResult ConvertChange(decimal number)
        {
            string error = "";

            moneyChangeController = new MoneyChangeController();
            moneyChangeList       = moneyChangeController.GetMoneyChangeFromDataBase(number);
            if (moneyChangeController.Error != null && moneyChangeList.Count <= 0)
            {
                //There is an error with the sql, try no connection
                error           = moneyChangeController.Error;
                moneyChangeList = moneyChangeController.GetMoneyChange(number);
            }
            return(Json(moneyChangeList, JsonRequestBehavior.AllowGet));
        }
Exemple #2
0
        public void GetMoneyChange()
        {
            decimal number = Convert.ToDecimal(36.7);//834.35

            Debug.WriteLine("Number: " + number);
            decimal total = 0;

            MoneyChangeController moneyChangeController = new MoneyChangeController();
            List <MoneyChange>    moneyChangeList       = moneyChangeController.GetMoneyChange(number);

            for (int i = 0; i < moneyChangeList.Count; i++)
            {
                //if is the last one just add it
                if (i == moneyChangeList.Count - 1)
                {
                    total += moneyChangeList[i].CurrencyValue * moneyChangeList[i].Quantity;
                }
                else
                {
                    //make sure the next coin or bill is lower than the current one
                    if ((moneyChangeList[i + 1].Quantity <= moneyChangeList[i].Quantity) ||
                        (moneyChangeList[i + 1].Quantity * moneyChangeList[i + 1].CurrencyValue < moneyChangeList[i].CurrencyValue))
                    {
                        // if it is lower sum up to toal
                        total += moneyChangeList[i].CurrencyValue * moneyChangeList[i].Quantity;
                    }
                    //if it is not lower it wont add it to the total and it means we are not making sure that the highest values of coins and bills are used first
                    else
                    {
                        Assert.Fail("The algorithm is not making sure to use always the higher value coins and bills. ");
                    }
                }

                Debug.WriteLine("Currency Value: " + moneyChangeList[i].CurrencyValue + " Quantity: " + moneyChangeList[i].Quantity + " Total: " + total);
            }
            //if the total isn't the same as the original number it means there was one quantity of currency bigger hence the test fails
            Assert.IsTrue(total == number);
        }
Exemple #3
0
 public JsonResult GetAllSearches()
 {
     moneyChangeController = new MoneyChangeController();
     moneyChangeList       = moneyChangeController.GetAllMoneyChanges();
     return(Json(moneyChangeList, JsonRequestBehavior.AllowGet));
 }