Example #1
0
        public void Read_Input_CoinDenomination()
        {
            GivenCoinDenomination(new int[] { 1, 2, 3 });
            CoinChanger coinChanger = new CoinChanger(inputReader.Object);

            coinChanger.requestCoinDenomination();

            inputReader.Verify(x => x.ReadCoinDenomination(), Times.Once);
        }
Example #2
0
        public void Read_Input_Amount()
        {
            GivenChangeAmount(123);
            CoinChanger coinChanger = new CoinChanger(inputReader.Object);

            coinChanger.requestChangeAmount();

            inputReader.Verify(x => x.ReadAmount(), Times.Once);
        }
        public void TestWhenValueIsGreaterThan10()
        {
            //Arrange
            CoinChanger program = new CoinChanger();

            //Act
            program.GetTheChange(15);
            program.incrementdime = 10;
            //Assert
            Assert.AreEqual(program.incrementdime, 10);
        }
        public void TestWhenValueIsEqualTo5()
        {
            //Arrange
            CoinChanger program = new CoinChanger();

            //Act
            program.GetTheChange(5);
            program.incrementdime = 5;
            //Assert
            Assert.AreEqual(program.incrementdime, 5);
        }
        public void TestWhenValueIsLessThan10()
        {
            //Arrange
            CoinChanger program = new CoinChanger();

            //Act
            program.GetTheChange(5);
            program.incrementdime = 0;
            //Assert
            Assert.AreEqual(program.incrementdime, 0);
        }
Example #6
0
        static void Main(string[] args)
        {
            for (int i = 1; i < 99; i++)

            {
                coins = new CoinChanger();
                coins.GetTheChange(i);
                Console.WriteLine("Quarter: " + coins.incrementquarter + " Dimes: " + coins.incrementdime + " Nickels: " + coins.incrementnickel + " Pennies: " + coins.incrementpenny);
            }
            Console.ReadLine();
        }
        public void TestWhenValueIsLessThan25()
        {
            //Arrange
            CoinChanger program = new CoinChanger();

            //Act
            program.GetTheChange(20);
            program.incrementquarter = 0;
            //Assert
            Assert.AreEqual(program.incrementquarter, 0);
        }
        public void TestWhenValueMoreThan25()
        {
            //Arrange
            CoinChanger program = new CoinChanger();

            //Act
            program.GetTheChange(46);
            program.incrementquarter = 25;
            //Assert
            Assert.AreEqual(program.incrementquarter, 25);
        }
Example #9
0
        static void Main(string[] args)
        {
            try
            {
                using (CoinChanger c = new CoinChanger())
                {
                    c.CoinAccepted      += new EventHandler <CoinEventArgs>(c_CoinAccepted);
                    c.CoinChangerError  += new EventHandler <StatusEventArgs>(c_CoinChangerError);
                    c.CoinChangerStatus += new EventHandler <StatusEventArgs>(c_CoinChangerStatus);
                    c.Open();

                    if (c.IsOpen)
                    {
                        c.Start();
                        c.EnableCoinAccepting();

                        System.Threading.Thread.Sleep(4000);
                        if (c.LastCoinChangerStatus.Code == 1)
                        {
                            Console.WriteLine("Статус монетника: " + c.LastCoinChangerStatus.Message);

                            Console.WriteLine("Сумма доступной сдачи: " + (c.Coins.Sum(r => r.Sum) / 100).ToString() + " руб.");

                            Console.WriteLine("Минимальная монета для сдачи: " + (c.Coins.MinPayout / 100).ToString() + " руб.");

                            Console.WriteLine("Максимальная монета для сдачи: " + (c.Coins.MaxPayout / 100).ToString() + " руб.");


                            Console.ReadKey();
                            Console.WriteLine("Сумма доступной сдачи: " + (c.Coins.Sum(r => r.Sum) / 100).ToString() + " руб.");

                            Console.ReadKey();

                            if (c.TryPayout(3000))
                            {
                                Console.WriteLine("Выдана сдача " + (500 / 100).ToString() + " руб.");
                            }
                        }
                        else
                        {
                            throw new ArgumentException(c.LastCoinChangerStatus.Message);
                        }

                        c.DisableCoinAccepting();
                        c.Stop();
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Example #10
0
        public void When20Cents()
        {
            //Arrange
            CoinChanger test1 = new CoinChanger();

            //Act
            test1.GetTheChange(20);
            int numberOfDimes = test1.incrementdime;

            //Assert
            Assert.AreEqual(2, numberOfDimes);
        }
Example #11
0
        public void WhenOneQuarter()
        {
            //Arrange
            CoinChanger singlecoin = new CoinChanger();

            //Act
            singlecoin.GetTheChange(25);
            int numberOfQuarters = singlecoin.incrementquarter;

            //Assert
            Assert.AreEqual(numberOfQuarters, 1);
        }
Example #12
0
        public void WhenOneDime()
        {
            //Arrange
            CoinChanger singlecoin = new CoinChanger();

            //Act
            singlecoin.GetTheChange(10);
            int numberOfDimes = singlecoin.incrementdime;

            //Assert
            Assert.AreEqual(numberOfDimes, 1);
        }
Example #13
0
        public void WhenOneNickel()
        {
            //Arrange
            CoinChanger singlecoin = new CoinChanger();

            //Act
            singlecoin.GetTheChange(5);
            int numberOfNickels = singlecoin.incrementnickel;

            //Assert
            Assert.AreEqual(numberOfNickels, 1);
        }
Example #14
0
        public void WhenOnePenny()
        {
            //Arrange
            CoinChanger singlecoin = new CoinChanger();

            //Act
            singlecoin.GetTheChange(1);
            int numberofpennies = singlecoin.incrementpenny;

            //Assert
            Assert.AreEqual(numberofpennies, 1);
        }
Example #15
0
        public void When2Cents()
        {
            //Arrange
            CoinChanger test1 = new CoinChanger();

            //Act
            test1.GetTheChange(2);
            int numberOfPennies = test1.incrementpenny;

            //Assert
            Assert.AreEqual(2, numberOfPennies);
        }
Example #16
0
        //TestRule#1=> Multiple Coins
        //When 50 = 2Quarters
        //When 20 = 2Dimes
        //Wnen 10 = 2Nickels
        //When 2= 2Pennies
        public void When50Cents()
        {
            //Arrange
            CoinChanger test1 = new CoinChanger();

            //Act (Expected)
            test1.GetTheChange(50);
            int numberOfQuarters = test1.incrementquarter;

            //Assert
            Assert.AreEqual(2, numberOfQuarters);
        }
        public void Throw_WhenDenominationIsInvalid()
        {
            // Expectation

            // Arrange
            int[] denominatorArray = new int[] { 5, 10, 10 };
            int   changeAmount     = 4;

            // Act
            var result = CoinChanger.Compute(changeAmount, denominatorArray);

            // Assert
        }
Example #18
0
        public void When10Cents()
        {
            //Arrange
            CoinChanger test1 = new CoinChanger();

            //Act
            test1.GetTheChange(10);
            int numberOfnickels     = test1.incrementnickel;
            int numberOfDimesWhen10 = test1.incrementdime;

            //Assert
            Assert.AreEqual(0, numberOfnickels);
            Assert.AreEqual(1, numberOfDimesWhen10);
        }
        public void ReturnExactChange_WhenDenominationNotSorted()
        {
            // Expectation
            int[] expected = new int[] { 3, 0, 1 };

            // Arrange
            int[] denominatorArray = new int[] { 5, 1, 2 };
            int   changeAmount     = 17;

            // Act
            var result = CoinChanger.Compute(changeAmount, denominatorArray);

            // Assert
            CollectionAssert.AreEquivalent(expected, result);
        }
        public void ReturnExactChange_WhenUsingTwoCoins()
        {
            // Expectation
            int[] expected = new int[] { 0, 1 };

            // Arrange
            int[] denominatorArray = new int[] { 1, 5 };
            int   changeAmount     = 5;

            // Act
            var result = CoinChanger.Compute(changeAmount, denominatorArray);

            // Assert
            CollectionAssert.AreEquivalent(expected, result);
        }
Example #21
0
        public void DifferentCoinsTest2()
        {
            //Arrange
            CoinChanger differentCoins = new CoinChanger();

            //Act
            differentCoins.GetTheChange(36);
            int numberOfQuarters = differentCoins.incrementquarter;
            int numberOfDimes    = differentCoins.incrementdime;
            int numberOfNickels  = differentCoins.incrementnickel;
            int numberOfPennies  = differentCoins.incrementpenny;

            //Assert
            Assert.AreEqual(numberOfQuarters, 1);
            Assert.AreEqual(numberOfDimes, 1);
            Assert.AreEqual(numberOfNickels, 0);
            Assert.AreEqual(numberOfPennies, 1);
        }
Example #22
0
        public void MixIdeasTest2()
        {
            //Arrange
            CoinChanger test2 = new CoinChanger();

            //Act
            test2.GetTheChange(68);
            int numberOfQuarters = test2.incrementquarter;
            int numberOfDimes    = test2.incrementdime;
            int numberOfNickels  = test2.incrementnickel;
            int numberOfPennies  = test2.incrementpenny;

            //Assert
            Assert.AreEqual(numberOfQuarters, 2);
            Assert.AreEqual(numberOfDimes, 1);
            Assert.AreEqual(numberOfNickels, 1);
            Assert.AreEqual(numberOfPennies, 3);
        }
Example #23
0
        public void MixIdeasTest1()
        {
            //Arrange
            CoinChanger test = new CoinChanger();

            //Act
            test.GetTheChange(99);
            int numberOfQuarters = test.incrementquarter;
            int numberOfDimes    = test.incrementdime;
            int numberOfNickels  = test.incrementnickel;
            int numberOfPennies  = test.incrementpenny;

            //Assert
            Assert.AreEqual(3, numberOfQuarters);
            Assert.AreEqual(2, numberOfDimes);
            Assert.AreEqual(0, numberOfNickels);
            Assert.AreEqual(4, numberOfPennies);
        }
Example #24
0
        public void Change()
        {
            int result = CoinChanger.Change(10);

            Assert.Equal(3, result);
        }
Example #25
0
 public void Setup()
 {
     _coinChanger = new CoinChanger();
 }
Example #26
0
        public void SetUp()
        {
            inputReader = new Mock <IInputReader>();

            coinChanger = new CoinChanger(inputReader.Object);
        }
Example #27
0
        public void ActualShouldReturnExpectedResult(int input, int[] expected)
        {
            var actual = CoinChanger.Changer(input);

            actual.ShouldBeEquivalentTo(expected);
        }