예제 #1
0
        public void ToString_Remainder_DenominationsAndRemainder()
        {
            var subject = new ChangeSolution(new[] { new Denomination(2) },
                                             new Money(5, CurrencyIsoCode.EUR));

            using (CultureReseter.Set(CultureInfo.InvariantCulture))
            {
                Assert.That(subject.ToString(), Is.EqualTo("< < 1 * 2 > > + < 5,00 € >"));
            }
        }
예제 #2
0
        public void ToString_NoRemainder_OnlyDenominations()
        {
            var subject = new ChangeSolution(new[] { new Denomination(2) },
                                             Money.Zero(CurrencyIsoCode.EUR));

            using (CultureReseter.Set(CultureInfo.InvariantCulture))
            {
                Assert.That(subject.ToString(), Is.EqualTo("< < 1 * 2 > >"));
            }
        }
예제 #3
0
        public void ToString_CanReceiveCustomFormatsAndProviders()
        {
            var denominations = new[] { new Denomination(2), new Denomination(.2m), new Denomination(.2m) };

            var subject = new ChangeSolution(denominations, Money.Zero(CurrencyIsoCode.EUR));
            var snailDecimalSeparator = (NumberFormatInfo)CultureInfo.InvariantCulture.NumberFormat.Clone();

            snailDecimalSeparator.NumberDecimalSeparator = "@";

            Assert.That(subject.ToString(".000", snailDecimalSeparator), Is.EqualTo("< < 1 * 2@000 > | < 2 * @200 > >"));
        }
예제 #4
0
        public void ToString_ValueString_AsPerCurrentCulture()
        {
            var denominations = new[] { new Denomination(2), new Denomination(.2m), new Denomination(.2m) };
            var subject       = new ChangeSolution(denominations, Money.Zero(CurrencyIsoCode.EUR));

            using (CultureReseter.Set("en-US"))
            {
                Assert.That(subject.ToString(), Is.EqualTo("< < 1 * 2 > | < 2 * 0.2 > >"), "US decimals with a dot");
            }

            using (CultureReseter.Set("da-DK"))
            {
                Assert.That(subject.ToString(), Is.EqualTo("< < 1 * 2 > | < 2 * 0,2 > >"), "DK decimals with a comma");
            }
        }
예제 #5
0
        public void Money_MakeChange()
        {
            Money moneyBack = 1m.Usd().Minus(.37m.Usd());             // ¢63

            Denomination[] usCoins =
            {
                new Denomination(.25m),                 // quarters
                new Denomination(.10m),                 // dimes
                new Denomination(.05m),                 // nickels
                new Denomination(.01m)                  // pennies
            };
            uint seventyThree = moneyBack.CountWaysToMakeChange(usCoins);

            // --> 73 ways to make change of ¢63
            Assert.That(seventyThree, Is.EqualTo(73));

            // optimal for canonical systems
            ChangeSolution change = moneyBack.MakeChange(usCoins);

            // --> six coins: 2 quarters, 1 dime, 3 pennies
            Assert.That(change.TotalCount, Is.EqualTo(6));

            OptimalChangeSolution sameChange = moneyBack.MakeOptimalChange(usCoins);

            // --> six coins as well: 2 quarters, 1 dime, 3 pennies
            Assert.That(sameChange.TotalCount, Is.EqualTo(6));

            var nonCanonicalDenominations = new[]
            {
                new Denomination(.25m),                 // quarters
                new Denomination(.10m),                 // dimes
                new Denomination(.05m),                 // nickels
                new Denomination(.01m),                 // pennies
                new Denomination(.21m)                  // ?
            };
            ChangeSolution subOptimal = moneyBack.MakeChange(nonCanonicalDenominations);

            // --> six coins: 2 quarters, 1 dime, 3 pennies
            Assert.That(subOptimal.TotalCount, Is.EqualTo(6));
            OptimalChangeSolution optimal = moneyBack.MakeOptimalChange(nonCanonicalDenominations);

            // --> three coins: 3 of .21
            Assert.That(optimal.TotalCount, Is.EqualTo(3));
        }
        public void GetChangeBankNotesAndCoinsReturnsCorrectSolution(int change, ChangeSolution expected)
        {
            var result = this.sut.GetChangeBankNotesAndCoins(change);

            result.Should().BeEquivalentTo(expected);
        }