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()); }
public void EjectQuarterWithSomeBallsAndZeroQuarterTest() { 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.EjectQuarter(); result.WriteLine(BaseConstants.EJECT_QUARTER_NO_QUARTER_STATE); Assert.AreEqual(result.ToString(), stringWriter.ToString()); Assert.AreEqual(gumballMachineStateString, gumballMachine.ToString()); }
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(); }