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 { BaseConstants.TO_STRING_SOLD_OUT_STATE })";
            var gumballMachine = new GumballMachineContext(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());
        }
Exemplo n.º 2
0
        public void ReFillWithSomeQuartersTest()
        {
            var stringWriter              = new StringWriter();
            var result                    = new StringWriter();
            var gumballMachine            = new GumballMachineContext(1, 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 soldOutState = new SoldOutState(gumballMachine, stringWriter);

            gumballMachine.InsertQuarter();
            gumballMachine.InsertQuarter();
            gumballMachine.TurnCrank();
            soldOutState.ReFill(10);
            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));

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

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

            Assert.AreEqual(result.ToString(), stringWriter.ToString());
            Assert.AreEqual(gumballMachineStateString, gumballMachine.ToString());
        }
Exemplo n.º 5
0
        public void TurnCrankWithOneQuarterTest()
        {
            var stringWriter              = new StringWriter();
            var result                    = new StringWriter();
            var gumballMachine            = new GumballMachineContext(3, stringWriter);
            var gumballMachineStateString = $"(Mighty Gumball, Inc.C# - enabled Standing Gumball Model #2019 (with state)Inventory:" +
                                            $" { 3 } gumball{ ( 3 != 1 ? "s" : "" ) }" +
                                            $" { 0 } quarter{ ( 0 != 1 ? "s" : "" ) } " +
                                            $"Machine is { BaseConstants.TO_STRING_SOLD_STATE })";
            var hasQuarterState = new HasQuarterState(gumballMachine, stringWriter);

            hasQuarterState.InsertQuarter();
            hasQuarterState.TurnCrank();

            result.WriteLine(MultiGumbalMachineConstants.GetInsertQuarterHasQuarterStateConst(1));
            result.WriteLine(MultiGumbalMachineConstants.GetTurnCrankHasQuarterStateConst(0));

            Assert.AreEqual(result.ToString(), stringWriter.ToString());
            Assert.AreEqual(gumballMachineStateString, gumballMachine.ToString());
        }
Exemplo n.º 6
0
        public void TurnCrank()
        {
            switch (_state)
            {
            case State.SoldOut:
                _textWriter.WriteLine(BaseConstants.TURN_CRANK_SOLD_OUT_STATE);
                break;

            case State.NoQuarter:
                _textWriter.WriteLine(BaseConstants.TURN_CRANK_NO_QUARTER_STATE);
                break;

            case State.HasQuarter:
                _quarterCounter.Dec();
                _textWriter.WriteLine(MultiGumbalMachineConstants.GetTurnCrankHasQuarterStateConst(_quarterCounter.QuarterAmount));
                _state = State.Sold;
                Dispense();
                break;

            case State.Sold:
                _textWriter.WriteLine(BaseConstants.TURN_CRANK_SOLD_STATE);
                break;
            }
        }
Exemplo n.º 7
0
 public void TurnCrank()
 {
     _gumballMachine.QuarterCounter.Dec();
     _gumballMachine.SetSoldState();
     _textWriter.WriteLine(MultiGumbalMachineConstants.GetTurnCrankHasQuarterStateConst(_gumballMachine.QuarterCounter.QuarterAmount));
 }