public void CalculateChange_WhenPassedValueDivisibleBySingleCoinValue_ShouldReturnObjectWithOneKeyValPair()
        {
            // arrange
            double original = 1;
            var    expected = new Dictionary <string, double>()
            {
                { "1", 1 }
            };

            double original2 = 2;
            var    expected2 = new Dictionary <string, double>()
            {
                { "2", 1 }
            };

            var x = new ChangeCalculator();

            // act
            var actual  = x.CalculateChange(original);
            var actual2 = x.CalculateChange(original2);

            // assert
            Assert.Equal(expected, actual);
            Assert.Equal(expected2, actual2);
        }
        public void Returns_Correct_Change(int amount, int quarters, int dimes, int nickles, int pennies)
        {
            var change = _calculator.CalculateChange(amount);

            var calculatedAmount = change.Quarters * 25 + change.Dimes * 10 + change.Nickles * 5 + change.Pennies;

            Assert.AreEqual(amount, calculatedAmount, $"Expected {amount} cents total, got {calculatedAmount}");
            Assert.AreEqual(quarters, change.Quarters, $"Expected {quarters} quarters, got {change.Quarters}");
            Assert.AreEqual(dimes, change.Dimes, $"Expected {dimes} dimes, got {change.Dimes}");
            Assert.AreEqual(nickles, change.Nickles, $"Expected {nickles} quarters, got {change.Nickles}");
            Assert.AreEqual(pennies, change.Pennies, $"Expected {pennies} quarters, got {change.Pennies}");
        }
Example #3
0
        public void CalculateChange_ExpectChangeCalculated_ExpectCorrectChange()
        {
            int cost        = 2;
            var transaction = new Transaction
            {
                Product = new Product
                {
                    Name = "Pickle",
                    Cost = cost
                },
                CoinsEntered = new double[]
                {
                    1,
                    2,
                    3,
                    4,
                    5
                }
            };

            var expectedChange = transaction.CoinsEntered.Sum() - cost;        //Preferred something human readable over autofixture

            var productList = _fixture.Create <List <Product> >();

            productList.Add(transaction.Product);   //Ensure that our product is in there

            var result = _sut.CalculateChange(transaction);

            Assert.AreEqual(expectedChange, result);
        }
Example #4
0
        public void ChangeCalculatorTest(int amount, int pay, ChangeModel expected)
        {
            var sut    = new ChangeCalculator();
            var actual = sut.CalculateChange(amount, pay);

            actual.Should().BeEquivalentTo(expected);
        }
Example #5
0
        public void CalculateChangeSuccessWithMinimumChange()
        {
            var calc = new ChangeCalculator();

            var actual = calc.CalculateChange(0.02m, 0.01m);

            Assert.AreEqual(1, actual.Count);
            Assert.AreEqual(1, actual[0.01m]);
        }
Example #6
0
        public void CalculateChangeSuccessWithExampleData()
        {
            var calc = new ChangeCalculator();

            var actual = calc.CalculateChange(20.00m, 5.50m);

            Assert.AreEqual(3, actual.Count);
            Assert.AreEqual(1, actual[10.00m]);
            Assert.AreEqual(2, actual[2.00m]);
            Assert.AreEqual(1, actual[0.50m]);
        }
        public void CalculateChange_WhenPassedNoChange_ShouldReturnEmptyObject()
        {
            // arrange
            double original = 0;
            var    expected = new Dictionary <string, double>();

            var x = new ChangeCalculator();

            // act
            var actual = x.CalculateChange(original);

            // assert
            Assert.Equal(expected, actual);
        }
        public void CalculateChange_WhenPassedValueNotEqualToAnyKey_ShouldDivideIntoSeveralKeys_AndReturnObject()
        {
            // arrange
            double original = 7;
            var    expected = new Dictionary <string, double>()
            {
                { "2", 1 },
                { "5", 1 }
            };

            var x = new ChangeCalculator();

            // act
            var actual = x.CalculateChange(original);

            // assert
            Assert.Equal(expected, actual);
        }
        public void CalculateChange_WhenPassedDoubleDigitNum_ShouldStillReturnCorrectObject()
        {
            //arrange
            double original = 13;
            var    expected = new Dictionary <string, double>()
            {
                { "1", 1 },
                { "2", 1 },
                { "10", 1 }
            };

            var x = new ChangeCalculator();

            // act
            var actual = x.CalculateChange(original);

            // assert
            Assert.Equal(expected, actual);
        }
        public void CalculateChange_WhenPassedTripleDigitNum_ShouldReturnObjectWithMultipleCoinsWherePossible()
        {
            //arrange
            double original = 229;
            var    expected = new Dictionary <string, double>()
            {
                { "2", 2 },
                { "5", 1 },
                { "20", 1 },
                { "50", 4 }
            };

            var x = new ChangeCalculator();

            // act
            var actual = x.CalculateChange(original);

            // assert
            Assert.Equal(expected, actual);
        }
Example #11
0
        public void CalculateChangeSuccessWithAllDenominations()
        {
            var calc = new ChangeCalculator();

            var actual = calc.CalculateChange(88.89m, 0.01m);

            Assert.AreEqual(12, actual.Count);
            Assert.AreEqual(1, actual[0.01m]);
            Assert.AreEqual(1, actual[0.02m]);
            Assert.AreEqual(1, actual[0.05m]);
            Assert.AreEqual(1, actual[0.10m]);
            Assert.AreEqual(1, actual[0.20m]);
            Assert.AreEqual(1, actual[0.50m]);
            Assert.AreEqual(1, actual[1.00m]);
            Assert.AreEqual(1, actual[2.00m]);
            Assert.AreEqual(1, actual[5.00m]);
            Assert.AreEqual(1, actual[10.00m]);
            Assert.AreEqual(1, actual[20.00m]);
            Assert.AreEqual(1, actual[50.00m]);
        }
Example #12
0
        public void CalculateChangeFailurePriceGreaterThanMoneyGiven()
        {
            var calc = new ChangeCalculator();

            Assert.ThrowsException <ArgumentException>(() => calc.CalculateChange(10m, 20m));
        }
Example #13
0
        public void CalculateChangeFailurePriceNegative()
        {
            var calc = new ChangeCalculator();

            Assert.ThrowsException <ArgumentOutOfRangeException>(() => calc.CalculateChange(10m, -10m));
        }
Example #14
0
        public void CalculateChangeFailureMoneyGivenZero()
        {
            var calc = new ChangeCalculator();

            Assert.ThrowsException <ArgumentOutOfRangeException>(() => calc.CalculateChange(0m, 5.50m));
        }