Esempio n. 1
0
        public void ReFillWithSomeBallsAfterEndingWithSomeQuarters()
        {
            var stringWriter = new StringWriter();
            var result       = new StringWriter();
            var gumballMachineStateString = $"(Mighty Gumball, Inc.C# - enabled Standing Gumball Model #2019 (with state)Inventory:" +
                                            $" { 10 } gumball{ ( 10 != 1 ? "s" : "" ) }" +
                                            $" { 1 } quarter{ ( 1 != 1 ? "s" : "" ) } " +
                                            $"Machine is { BaseConstants.TO_STRING_HAS_QUARTER_STATE })";
            var gumballMachine = new GumballMachine.NaiveGumballMachine.GumballMachine(1, stringWriter);

            gumballMachine.InsertQuarter();
            gumballMachine.InsertQuarter();
            gumballMachine.TurnCrank();
            gumballMachine.ReFill(10);

            Assert.AreEqual(gumballMachineStateString, gumballMachine.ToString());

            gumballMachine.TurnCrank();
            result.WriteLine(BaseConstants.INSERT_QUARTER_NO_QUARTER_STATE);
            result.WriteLine(MultiGumbalMachineConstants.GetInsertQuarterHasQuarterStateConst(2));
            result.WriteLine(MultiGumbalMachineConstants.GetTurnCrankHasQuarterStateConst(1));
            result.WriteLine(BaseConstants.RELEASE_BALL);
            result.WriteLine(BaseConstants.DISPENSE_SOLD_STATE);
            result.WriteLine(MultiGumbalMachineConstants.GetReFillSoldOutStateConst(10));
            result.WriteLine(MultiGumbalMachineConstants.GetTurnCrankHasQuarterStateConst(0));
            result.WriteLine(BaseConstants.RELEASE_BALL);

            gumballMachineStateString = $"(Mighty Gumball, Inc.C# - enabled Standing Gumball Model #2019 (with state)Inventory:" +
                                        $" { 9 } gumball{ ( 9 != 1 ? "s" : "" ) }" +
                                        $" { 0 } quarter{ ( 0 != 1 ? "s" : "" ) } " +
                                        $"Machine is { BaseConstants.TO_STRING_NO_QUARTER_STATE })";

            Assert.AreEqual(result.ToString(), stringWriter.ToString());
            Assert.AreEqual(gumballMachineStateString, gumballMachine.ToString());
        }
Esempio n. 2
0
        public void TurnKrankAndEjectSomeQuartersTest()
        {
            var stringWriter = new StringWriter();
            var result       = new StringWriter();
            var gumballMachineStateString = $"(Mighty Gumball, Inc.C# - enabled Standing Gumball Model #2019 (with state)Inventory:" +
                                            $" { 2 } gumball{ ( 2 != 1 ? "s" : "" ) }" +
                                            $" { 0 } quarter{ ( 0 != 1 ? "s" : "" ) } " +
                                            $"Machine is { Constants.TO_STRING_NO_QUARTER_STATE })";
            var gumballMachine = new GumballMachine.NaiveGumballMachine.GumballMachine(4, stringWriter);

            for (int i = 0; i < 4; i++)
            {
                gumballMachine.InsertQuarter();
            }
            gumballMachine.TurnCrank();
            gumballMachine.TurnCrank();
            gumballMachine.EjectQuarter();

            result.WriteLine(BaseConstants.INSERT_QUARTER_NO_QUARTER_STATE);
            result.WriteLine(MultiGumbalMachineConstants.GetInsertQuarterHasQuarterStateConst(2));
            result.WriteLine(MultiGumbalMachineConstants.GetInsertQuarterHasQuarterStateConst(3));
            result.WriteLine(MultiGumbalMachineConstants.GetInsertQuarterHasQuarterStateConst(4));
            result.WriteLine(MultiGumbalMachineConstants.GetTurnCrankHasQuarterStateConst(3));
            result.WriteLine(BaseConstants.RELEASE_BALL);
            result.WriteLine(MultiGumbalMachineConstants.GetTurnCrankHasQuarterStateConst(2));
            result.WriteLine(BaseConstants.RELEASE_BALL);
            result.WriteLine(MultiGumbalMachineConstants.GetEjectQuarterHasQuarterStateConst(2));

            Assert.AreEqual(result.ToString(), stringWriter.ToString());
            Assert.AreEqual(gumballMachineStateString, gumballMachine.ToString());
        }
Esempio n. 3
0
        public void TurnKrankThenBallsOverTest()
        {
            var stringWriter = new StringWriter();
            var result       = new StringWriter();
            var gumballMachineStateString = $"(Mighty Gumball, Inc.C# - enabled Standing Gumball Model #2019 (with state)Inventory:" +
                                            $" { 0 } gumball{ ( 0 != 1 ? "s" : "" ) }" +
                                            $" { 0 } quarter{ ( 0 != 1 ? "s" : "" ) } " +
                                            $"Machine is { Constants.TO_STRING_SOLD_OUT_STATE })";
            var gumballMachine = new GumballMachine.NaiveGumballMachine.GumballMachine(2, stringWriter);

            gumballMachine.InsertQuarter();
            gumballMachine.InsertQuarter();
            gumballMachine.TurnCrank();
            gumballMachine.TurnCrank();
            result.WriteLine(BaseConstants.INSERT_QUARTER_NO_QUARTER_STATE);
            result.WriteLine(MultiGumbalMachineConstants.GetInsertQuarterHasQuarterStateConst(2));
            result.WriteLine(MultiGumbalMachineConstants.GetTurnCrankHasQuarterStateConst(1));
            result.WriteLine(BaseConstants.RELEASE_BALL);
            result.WriteLine(MultiGumbalMachineConstants.GetTurnCrankHasQuarterStateConst(0));
            result.WriteLine(BaseConstants.RELEASE_BALL);
            result.WriteLine(BaseConstants.DISPENSE_SOLD_STATE);

            Assert.AreEqual(result.ToString(), stringWriter.ToString());
            Assert.AreEqual(gumballMachineStateString, gumballMachine.ToString());
        }
Esempio n. 4
0
        static void Main(string [] args)
        {
            MultiGumballMachine.GumballMachine gumballMachine = new MultiGumballMachine.GumballMachine(2, Console.Out);
            gumballMachine.InsertQuarter();
            gumballMachine.InsertQuarter();
            gumballMachine.InsertQuarter();
            gumballMachine.TurnCrank();
            gumballMachine.TurnCrank();
            gumballMachine.EjectQuarter();

            Console.WriteLine("---------------");

            NaiveGumballMachine.GumballMachine naiveGumballMachine = new NaiveGumballMachine.GumballMachine(2, Console.Out);
            naiveGumballMachine.InsertQuarter();
            naiveGumballMachine.InsertQuarter();
            naiveGumballMachine.InsertQuarter();
            naiveGumballMachine.TurnCrank();
            naiveGumballMachine.TurnCrank();
            naiveGumballMachine.EjectQuarter();
        }
Esempio n. 5
0
        public void TurnCrankWithSomeBallsAndZeroQuarterTest()
        {
            var stringWriter = new StringWriter();
            var result       = new StringWriter();
            var gumballMachineStateString = $"(Mighty Gumball, Inc.C# - enabled Standing Gumball Model #2019 (with state)Inventory:" +
                                            $" { 2 } gumball{ ( 2 != 1 ? "s" : "" ) }" +
                                            $" { 0 } quarter{ ( 0 != 1 ? "s" : "" ) } " +
                                            $"Machine is { Constants.TO_STRING_NO_QUARTER_STATE })";
            var gumballMachine = new GumballMachine.NaiveGumballMachine.GumballMachine(2, stringWriter);

            gumballMachine.TurnCrank();
            result.WriteLine(BaseConstants.TURN_CRANK_NO_QUARTER_STATE);

            Assert.AreEqual(result.ToString(), stringWriter.ToString());
            Assert.AreEqual(gumballMachineStateString, gumballMachine.ToString());
        }