Esempio n. 1
0
        public void RemoveCoinTest()
        {
            //Arrange
            int coinCountOrig, coinCountAfterPenny, coinCountAfterFiveMorePennies;
            int numPennies = 5;


            decimal valueOrig, valueAfterPenny, valueAfterFiveMorePennies;
            decimal valueAfterNickel, valueAfterDime, valueAfterQuarter, valueAfterDollar;

            repo = new CurrencyRepo();  //reset repo

            //add some coins
            repo.AddCoin(penny);

            for (int i = 0; i < numPennies; i++)
            {
                repo.AddCoin(penny);
            }
            repo.AddCoin(nickel);
            repo.AddCoin(dime);
            repo.AddCoin(quarter);
            repo.AddCoin(dollarCoin);

            //Act
            coinCountOrig = repo.GetCoinCount();
            valueOrig     = repo.TotalValue();
            repo.RemoveCoin(penny);
            coinCountAfterPenny = repo.GetCoinCount();
            valueAfterPenny     = repo.TotalValue();

            for (int i = 0; i < numPennies; i++)
            {
                repo.RemoveCoin(penny);
            }
            coinCountAfterFiveMorePennies = repo.GetCoinCount();
            valueAfterFiveMorePennies     = repo.TotalValue();

            repo.RemoveCoin(nickel);
            valueAfterNickel = repo.TotalValue();
            repo.RemoveCoin(dime);
            valueAfterDime = repo.TotalValue();
            repo.RemoveCoin(quarter);
            valueAfterQuarter = repo.TotalValue();
            repo.RemoveCoin(dollarCoin);
            valueAfterDollar = repo.TotalValue();


            //Assert
            Assert.AreEqual(coinCountOrig - 1, coinCountAfterPenny);
            Assert.AreEqual(coinCountAfterPenny - numPennies, coinCountAfterFiveMorePennies);

            Assert.AreEqual(valueOrig - penny.MonetaryValue, valueAfterPenny);
            Assert.AreEqual(valueAfterPenny - (numPennies * penny.MonetaryValue), valueAfterFiveMorePennies);

            //Assert.AreEqual(valueAfterFiveMorePennies - nickel.MonetaryValue, valueAfterNickel); //HUH? 1.35 != 1.35 both are double?
            Assert.AreEqual(valueAfterNickel - dime.MonetaryValue, valueAfterDime);
            Assert.AreEqual(valueAfterDime - quarter.MonetaryValue, valueAfterQuarter);
            Assert.AreEqual(valueAfterQuarter - dollarCoin.MonetaryValue, valueAfterDollar);
        }
        public override ICurrencyRepo Reduce()
        {
            ICurrencyRepo originalRepo = this;
            ICurrencyRepo reducedRepo  = new USCurrencyRepo();

            for (int x = (PossibleCoins.Count - 1); x >= 0; x--)
            {
                ICoin         smallerCoin  = PossibleCoins[x]; //coin we're reducing
                ICurrencyRepo currentCoins = originalRepo.GetOnlyCoinsOfType(PossibleCoins[x].GetType());

                for (int y = 0; y < PossibleCoins.Count; y++)
                {
                    ICoin largerCoin = PossibleCoins[y]; //coin we're trying to reduce the smaller coin to

                    double amountNeededToReduce = largerCoin.MonetaryValue / smallerCoin.MonetaryValue;
                    if (currentCoins.GetCoinCount() >= amountNeededToReduce)
                    {
                        int amountPossible = (int)(currentCoins.GetCoinCount() / amountNeededToReduce);
                        for (int z = 0; z < amountPossible; z++)
                        {
                            reducedRepo.AddCoin(largerCoin);
                            for (int a = 0; a < amountNeededToReduce; a++) //removing reduced coins
                            {
                                currentCoins.Coins.RemoveAt(currentCoins.GetCoinCount() - 1);
                            }
                        }
                    }
                }
            }

            return(reducedRepo);
        }
Esempio n. 3
0
        public void AddCoinTest()
        {
            //Arrange
            int coinCountOrig, coinCountAfterPenny, coinCountAfterFiveMorePennies;
            int numPennies = 5;


            Double valueOrig, valueAfterPenny, valueAfterFiveMorePennies;
            Double valueAfterNickel, valueAfterDime, valueAfterQuarter, valueAfterDollar;

            //Act
            coinCountOrig = repo.GetCoinCount();
            valueOrig     = repo.TotalValue();

            repo.AddCoin(penny);
            coinCountAfterPenny = repo.GetCoinCount();
            valueAfterPenny     = repo.TotalValue();

            for (int i = 0; i < numPennies; i++)
            {
                repo.AddCoin(penny);
            }
            coinCountAfterFiveMorePennies = repo.GetCoinCount();
            valueAfterFiveMorePennies     = repo.TotalValue();

            repo.AddCoin(nickel);
            valueAfterNickel = repo.TotalValue();
            repo.AddCoin(dime);
            valueAfterDime = repo.TotalValue();
            repo.AddCoin(quarter);
            valueAfterQuarter = repo.TotalValue();
            repo.AddCoin(dollarCoin);
            valueAfterDollar = repo.TotalValue();


            //Assert
            Assert.AreEqual(coinCountOrig + 1, coinCountAfterPenny);
            Assert.AreEqual(coinCountAfterPenny + numPennies, coinCountAfterFiveMorePennies);

            Assert.AreEqual(valueOrig + penny.MonetaryValue, valueAfterPenny);
            Assert.AreEqual(valueAfterPenny + (numPennies * penny.MonetaryValue), valueAfterFiveMorePennies);

            Assert.AreEqual(valueAfterFiveMorePennies + nickel.MonetaryValue, valueAfterNickel);
            Assert.AreEqual(valueAfterNickel + dime.MonetaryValue, valueAfterDime);
            Assert.AreEqual(valueAfterDime + quarter.MonetaryValue, valueAfterQuarter);
            Assert.AreEqual(valueAfterQuarter + dollarCoin.MonetaryValue, valueAfterDollar);
        }
Esempio n. 4
0
 private void OCoin()
 {
     repo = repo.CreateChange(Amount);
     for (int i = 0; i < repo.GetCoinCount(); i++)
     {
         OCoins.Add(repo.Coins[i]);
     }
 }