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 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()); }
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()); }
public void EjectQuarter() { switch (_state) { case State.SoldOut: // _textWriter.WriteLine( BaseConstants.EJECT_QUARTER_SOLD_OUT_STATE ); if (!_quarterCounter.IsEmptyCounter()) { _textWriter.WriteLine(MultiGumbalMachineConstants.GetEjectQuarterSoldOutStateConst(_quarterCounter.QuarterAmount)); _quarterCounter.Zeroize(); } else { _textWriter.WriteLine(BaseConstants.EJECT_QUARTER_SOLD_OUT_STATE); } break; case State.NoQuarter: _textWriter.WriteLine(BaseConstants.EJECT_QUARTER_NO_QUARTER_STATE); break; case State.HasQuarter: _textWriter.WriteLine(MultiGumbalMachineConstants.GetEjectQuarterHasQuarterStateConst(_quarterCounter.QuarterAmount)); _quarterCounter.Zeroize(); _state = State.NoQuarter; break; case State.Sold: _textWriter.WriteLine(BaseConstants.EJECT_QUARTER_SOLD_STATE); break; } }
public void InsertQuarter() { switch (_state) { case State.SoldOut: _textWriter.WriteLine(BaseConstants.INSERT_QUARTER_SOLD_OUT_STATE); break; case State.NoQuarter: _textWriter.WriteLine(BaseConstants.INSERT_QUARTER_NO_QUARTER_STATE); _quarterCounter.Inc(); _state = State.HasQuarter; break; case State.HasQuarter: if (_quarterCounter.IsIncAvailable()) { _quarterCounter.Inc(); _textWriter.WriteLine(MultiGumbalMachineConstants.GetInsertQuarterHasQuarterStateConst(_quarterCounter.QuarterAmount)); } else { _textWriter.WriteLine(MultiGumbalMachineConstants.INSERT_QUARTER_MAX_LIMIT_HAS_QUARTER_STATE); } break; case State.Sold: _textWriter.WriteLine(BaseConstants.INSERT_QUARTER_SOLD_STATE); break; } }
public void ReFill(uint numBalls) { switch (_state) { case State.SoldOut: _count = numBalls; _textWriter.WriteLine(MultiGumbalMachineConstants.GetReFillSoldOutStateConst(_count)); _state = _count > 0 ? !_quarterCounter.IsEmptyCounter() ? State.HasQuarter : State.NoQuarter : State.SoldOut; break; case State.NoQuarter: _textWriter.WriteLine(MultiGumbalMachineConstants.REFILL_NO_QUARTER_STATE); break; case State.HasQuarter: _textWriter.WriteLine(MultiGumbalMachineConstants.REFILL_HAS_QUARTER_STATE); break; case State.Sold: _textWriter.WriteLine(MultiGumbalMachineConstants.REFILL_SOLD_STATE); break; } }
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()); }
public void EjectQuarter() { if (!_gumballMachine.QuarterCounter.IsEmptyCounter()) { _textWriter.WriteLine(MultiGumbalMachineConstants.GetEjectQuarterSoldOutStateConst(_gumballMachine.QuarterCounter.QuarterAmount)); _gumballMachine.QuarterCounter.Zeroize(); } else { _textWriter.WriteLine(BaseConstants.EJECT_QUARTER_SOLD_OUT_STATE); } }
public void InsertQuarter() { if (_gumballMachine.QuarterCounter.IsIncAvailable()) { _gumballMachine.QuarterCounter.Inc(); _textWriter.WriteLine(MultiGumbalMachineConstants.GetInsertQuarterHasQuarterStateConst(_gumballMachine.QuarterCounter.QuarterAmount)); } else { _textWriter.WriteLine(MultiGumbalMachineConstants.INSERT_QUARTER_MAX_LIMIT_HAS_QUARTER_STATE); } }
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 GumballMachineContext(0, stringWriter); gumballMachine.ReFill(10); result.WriteLine(MultiGumbalMachineConstants.GetReFillSoldOutStateConst(10)); Assert.AreEqual(result.ToString(), stringWriter.ToString()); Assert.AreEqual(gumballMachineStateString, gumballMachine.ToString()); }
public void ReFill(uint count) { _gumballMachine.AddBalls(count); _textWriter.WriteLine(MultiGumbalMachineConstants.GetReFillSoldOutStateConst(_gumballMachine.GetBallsCount())); if (_gumballMachine.GetBallsCount() > 0) { if (!_gumballMachine.QuarterCounter.IsEmptyCounter()) { _gumballMachine.SetHasQuarterState(); } else { _gumballMachine.SetNoQuarterState(); } } }
public void InsertSomeQuarterTest() { var stringWriter = new StringWriter(); var result = new StringWriter(); var gumballMachine = new GumballMachineContext(2, stringWriter); var gumballMachineStateString = $"(Mighty Gumball, Inc.C# - enabled Standing Gumball Model #2019 (with state)Inventory:" + $" { 2 } gumball{ ( 2 != 1 ? "s" : "" ) }" + $" { 2 } quarter{ ( 2 != 1 ? "s" : "" ) } " + $"Machine is { BaseConstants.TO_STRING_NO_QUARTER_STATE })"; var hasQuarterState = new HasQuarterState(gumballMachine, stringWriter); hasQuarterState.InsertQuarter(); hasQuarterState.InsertQuarter(); result.WriteLine(MultiGumbalMachineConstants.GetInsertQuarterHasQuarterStateConst(1)); result.WriteLine(MultiGumbalMachineConstants.GetInsertQuarterHasQuarterStateConst(2)); Assert.AreEqual(result.ToString(), stringWriter.ToString()); Assert.AreEqual(gumballMachineStateString, gumballMachine.ToString()); }
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()); }
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()); }
public void DispenseWithSomeQuarterAndSomeBallsTest() { var stringWriter = new StringWriter(); var result = new StringWriter(); var gumballMachine = new GumballMachineContext(2, stringWriter); var gumballMachineStateString = $"(Mighty Gumball, Inc.C# - enabled Standing Gumball Model #2019 (with state)Inventory:" + $" { 1 } gumball{ ( 1 != 1 ? "s" : "" ) }" + $" { 2 } quarter{ ( 2 != 1 ? "s" : "" ) } " + $"Machine is { BaseConstants.TO_STRING_HAS_QUARTER_STATE })"; var soldState = new SoldState(gumballMachine, stringWriter); gumballMachine.InsertQuarter(); gumballMachine.InsertQuarter(); soldState.Dispense(); result.WriteLine(BaseConstants.INSERT_QUARTER_NO_QUARTER_STATE); result.WriteLine(MultiGumbalMachineConstants.GetInsertQuarterHasQuarterStateConst(2)); result.WriteLine(BaseConstants.RELEASE_BALL); Assert.AreEqual(result.ToString(), stringWriter.ToString()); Assert.AreEqual(gumballMachineStateString, gumballMachine.ToString()); }
public void InsertOverLimitQuartersTest() { 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" : "" ) }" + $" { 5 } quarter{ ( 5 != 1 ? "s" : "" ) } " + $"Machine is { BaseConstants.TO_STRING_HAS_QUARTER_STATE })"; var gumballMachine = new GumballMachineContext(2, stringWriter); for (int i = 0; i < 6; i++) { gumballMachine.InsertQuarter(); } result.WriteLine(BaseConstants.INSERT_QUARTER_NO_QUARTER_STATE); for (int i = 0; i < 4; i++) { result.WriteLine(MultiGumbalMachineConstants.GetInsertQuarterHasQuarterStateConst(( uint )(i + 2))); } result.WriteLine(MultiGumbalMachineConstants.INSERT_QUARTER_MAX_LIMIT_HAS_QUARTER_STATE); Assert.AreEqual(result.ToString(), stringWriter.ToString()); Assert.AreEqual(gumballMachineStateString, gumballMachine.ToString()); }
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; } }
public void TurnCrank() { _gumballMachine.QuarterCounter.Dec(); _gumballMachine.SetSoldState(); _textWriter.WriteLine(MultiGumbalMachineConstants.GetTurnCrankHasQuarterStateConst(_gumballMachine.QuarterCounter.QuarterAmount)); }
public void EjectQuarter() { _textWriter.WriteLine(MultiGumbalMachineConstants.GetEjectQuarterHasQuarterStateConst(_gumballMachine.QuarterCounter.QuarterAmount)); _gumballMachine.QuarterCounter.Zeroize(); _gumballMachine.SetNoQuarterState(); }