Esempio n. 1
0
        public void ChangeRequired2()
        {
            Money           moneyFloat    = SampleFloat();
            decimal         originalFloat = moneyFloat.Total;
            ChangeAlgorithm algo          = new ChangeAlgorithm();

            decimal price    = 1.7M;
            Money   tendered = new Money();

            tendered.Add(DenominationEnum.TwoEuro, 2);

            Money change;
            bool  result = algo.DetermineChange(moneyFloat, tendered, price, out change);

            Assert.IsTrue(result);
            Assert.AreEqual(tendered.Total - price, change.Total, "Change total incorrect. Change expected.");
            Assert.AreEqual(originalFloat + price, moneyFloat.Total, "Float incorrect.");

            Assert.AreEqual(1, change[DenominationEnum.TenCents].NumberOfCoins, "Incorrect change. 10 cents.");
            Assert.AreEqual(1, change[DenominationEnum.TwentyCents].NumberOfCoins, "Incorrect change. 20 cents.");
            Assert.AreEqual(0, change[DenominationEnum.FiftyCents].NumberOfCoins, "Incorrect change. 50 cents.");
            Assert.AreEqual(0, change[DenominationEnum.OneEuro].NumberOfCoins, "Incorrect change. 1 Euro.");
            Assert.AreEqual(1, change[DenominationEnum.TwoEuro].NumberOfCoins, "Incorrect change. 2 Euro.");

            Assert.AreEqual(99, moneyFloat[DenominationEnum.TenCents].NumberOfCoins, "Incorrect float. 10 cents.");
            Assert.AreEqual(99, moneyFloat[DenominationEnum.TwentyCents].NumberOfCoins, "Incorrect float. 20 cents.");
            Assert.AreEqual(100, moneyFloat[DenominationEnum.FiftyCents].NumberOfCoins, "Incorrect float. 50 cents.");
            Assert.AreEqual(100, moneyFloat[DenominationEnum.OneEuro].NumberOfCoins, "Incorrect float. 1 Euro.");
            Assert.AreEqual(101, moneyFloat[DenominationEnum.TwoEuro].NumberOfCoins, "Incorrect float. 2 Euro.");
        }
Esempio n. 2
0
        public void CannotGiveChange_FloatNotEmpty()
        {
            Money moneyFloat = new Money();

            moneyFloat.Add(DenominationEnum.FiftyCents, 1);
            decimal         originalFloat = moneyFloat.Total;
            ChangeAlgorithm algo          = new ChangeAlgorithm();

            decimal price    = 0.1M;
            Money   tendered = new Money();

            tendered.Add(DenominationEnum.TwentyCents, 1);

            Money change;
            bool  result = algo.DetermineChange(moneyFloat, tendered, price, out change);

            Assert.IsFalse(result);

            Assert.AreEqual(originalFloat, moneyFloat.Total, "Float incorrect.");

            Assert.AreEqual(0, moneyFloat[DenominationEnum.TenCents].NumberOfCoins, "Incorrect float. 10 cents.");
            Assert.AreEqual(0, moneyFloat[DenominationEnum.TwentyCents].NumberOfCoins, "Incorrect float. 20 cents.");
            Assert.AreEqual(1, moneyFloat[DenominationEnum.FiftyCents].NumberOfCoins, "Incorrect float. 50 cents.");
            Assert.AreEqual(0, moneyFloat[DenominationEnum.OneEuro].NumberOfCoins, "Incorrect float. 1 Euro.");
            Assert.AreEqual(0, moneyFloat[DenominationEnum.TwoEuro].NumberOfCoins, "Incorrect float. 2 Euro.");
        }