Ejemplo 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());
        }
Ejemplo n.º 2
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());
        }
Ejemplo n.º 3
0
        public void TurnKrankMoreThenInsertQuartersTest()
        {
            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);

            gumballMachine.InsertQuarter();
            gumballMachine.InsertQuarter();
            for (int i = 0; i < 4; i++)
            {
                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.TURN_CRANK_NO_QUARTER_STATE);
            result.WriteLine(BaseConstants.TURN_CRANK_NO_QUARTER_STATE);

            Assert.AreEqual(result.ToString(), stringWriter.ToString());
            Assert.AreEqual(gumballMachineStateString, gumballMachine.ToString());
        }
Ejemplo n.º 4
0
        public void InitializeNaiveGumballMachineWithZeroBallsTest()
        {
            var stringWriter = new StringWriter();
            var result       = $"(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(0, stringWriter);

            Assert.AreEqual(result, gumballMachine.ToString());
        }
Ejemplo n.º 5
0
        public void InsertQuarterTest()
        {
            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" : "" ) }" +
                                            $" { 1 } quarter{ ( 1 != 1 ? "s" : "" ) } " +
                                            $"Machine is { Constants.TO_STRING_HAS_QUARTER_STATE })";
            var gumballMachine = new GumballMachine.NaiveGumballMachine.GumballMachine(2, stringWriter);

            gumballMachine.InsertQuarter();
            result.WriteLine(BaseConstants.INSERT_QUARTER_NO_QUARTER_STATE);

            Assert.AreEqual(result.ToString(), stringWriter.ToString());
            Assert.AreEqual(gumballMachineStateString, gumballMachine.ToString());
        }
Ejemplo n.º 6
0
        public void ReFillAfterCreationWithZeroBalls()
        {
            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" : "" ) }" +
                                            $" { 0 } quarter{ ( 0 != 1 ? "s" : "" ) } " +
                                            $"Machine is { BaseConstants.TO_STRING_NO_QUARTER_STATE })";
            var gumballMachine = new GumballMachine.NaiveGumballMachine.GumballMachine(0, stringWriter);

            gumballMachine.ReFill(10);
            result.WriteLine(MultiGumbalMachineConstants.GetReFillSoldOutStateConst(10));

            Assert.AreEqual(result.ToString(), stringWriter.ToString());
            Assert.AreEqual(gumballMachineStateString, gumballMachine.ToString());
        }
Ejemplo n.º 7
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());
        }
Ejemplo n.º 8
0
        public void EjectQuarterWithZeroBallsTest()
        {
            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(0, stringWriter);

            gumballMachine.EjectQuarter();
            result.WriteLine(BaseConstants.EJECT_QUARTER_SOLD_OUT_STATE);

            Assert.AreEqual(result.ToString(), stringWriter.ToString());
            Assert.AreEqual(gumballMachineStateString, gumballMachine.ToString());
        }
Ejemplo n.º 9
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();
        }
Ejemplo n.º 10
0
        public void InsertSomeQuartersTest()
        {
            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" : "" ) }" +
                                            $" { 3 } quarter{ ( 3 != 1 ? "s" : "" ) } " +
                                            $"Machine is { Constants.TO_STRING_HAS_QUARTER_STATE })";
            var gumballMachine = new GumballMachine.NaiveGumballMachine.GumballMachine(2, stringWriter);

            for (int i = 0; i < 3; i++)
            {
                gumballMachine.InsertQuarter();
            }
            result.WriteLine(BaseConstants.INSERT_QUARTER_NO_QUARTER_STATE);
            result.WriteLine(MultiGumbalMachineConstants.GetInsertQuarterHasQuarterStateConst(2));
            result.WriteLine(MultiGumbalMachineConstants.GetInsertQuarterHasQuarterStateConst(3));

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