Пример #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());
        }
Пример #2
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());
        }
Пример #3
0
        public void ReFillAfterInsertQuarterTest()
        {
            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 { BaseConstants.TO_STRING_HAS_QUARTER_STATE })";
            var gumballMachine = new GumballMachine.NaiveGumballMachine.GumballMachine(2, stringWriter);

            gumballMachine.InsertQuarter();
            gumballMachine.ReFill(10);
            result.WriteLine(BaseConstants.INSERT_QUARTER_NO_QUARTER_STATE);
            result.WriteLine(MultiGumbalMachineConstants.REFILL_HAS_QUARTER_STATE);

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