// Test case 8 : Testing eject method and get cents back method @Test public void testEjectAndCentsBackCheck() { gumballM1.insertQuarter(); gumballM1.ejectNickel(); gumballM1.insertDime(); gumballM1.insertDime(); gumballM1.insertQuarter(); // assertEquals(15, gumballM1.getChange()); assertEquals(false, gumballM1.isGumballInSlot()); gumballM1.turnCrank(); assertEquals(true, gumballM1.isGumballInSlot()); }
// Test case 6 : Insert 2 quarters and turn crank and Insert 2 quarters again and turn crank // Chenking to see if multiple time inserting 50 cents dispences the gumball @Test public void testCountOfGumballsInSlot() { gumballM1.insertQuarter(); gumballM1.insertQuarter(); gumballM1.turnCrank(); gumballM1.insertQuarter(); gumballM1.insertQuarter(); gumballM1.turnCrank(); assertEquals(true, gumballM1.isGumballInSlot()); gumballM1.takeGumballFromSlot(); assertEquals(false, gumballM1.isGumballInSlot()); }
/** @param args the command line arguments */ public static void main(String[] args) { System.out.println("GumBalls State Pattern Application"); System.out.println("----------------------------------"); GumballMachine gm = new GumballMachine(5); System.out.println(""); gm.insertQuarter(); System.out.println("\t\tafter inserting a quarter" + gm); gm.turnCrankFetchGumball(); System.out.println("\t\tafter turncrank to fetchgumball" + gm); System.out.println(""); gm.insertQuarter(); System.out.println("\t\tafter inserting a quarter" + gm); gm.ejectQuarter(); System.out.println("\t\twe ejected the quarter" + gm); gm.turnCrankFetchGumball(); System.out.println("\t\tafter turncrank to fetchgumball" + gm); System.out.println(""); gm.insertQuarter(); System.out.println("\t\tafter inserting a quarter" + gm); gm.turnCrankFetchGumball(); System.out.println("\t\tafter turncrank to fetchgumball" + gm); gm.insertQuarter(); System.out.println("\t\tafter inserting a quarter" + gm); gm.turnCrankFetchGumball(); System.out.println("\t\tafter turncrank to fetchgumball" + gm); gm.ejectQuarter(); System.out.println("\t\twe ejected the quarter" + gm); System.out.println(""); gm.insertQuarter(); System.out.println("\t\tafter inserting a quarter" + gm); gm.insertQuarter(); System.out.println("\t\tafter inserting a quarter" + gm); gm.turnCrankFetchGumball(); System.out.println("\t\tafter turncrank to fetchgumball" + gm); gm.insertQuarter(); System.out.println("\t\tafter inserting a quarter" + gm); gm.turnCrankFetchGumball(); System.out.println("\t\tafter turncrank to fetchgumball" + gm); gm.insertQuarter(); System.out.println("\t\tafter inserting a quarter" + gm); gm.turnCrankFetchGumball(); System.out.println("\t\tafter turncrank to fetchgumball" + gm); System.out.println(""); gm.insertQuarter(); System.out.println("\t\tafter inserting a quarter" + gm); gm.turnCrankFetchGumball(); System.out.println("\t\tafter turncrank to fetchgumball" + gm); System.out.println(""); System.out.println("----------------------------------"); }
public static void main(String[] args) { GumballMachine gumballMachine = new GumballMachine(5); System.out.println(gumballMachine); gumballMachine.insertQuarter(); gumballMachine.turnCrank(); System.out.println(gumballMachine); gumballMachine.insertQuarter(); gumballMachine.ejectQuarter(); gumballMachine.turnCrank(); System.out.println(gumballMachine); gumballMachine.insertQuarter(); gumballMachine.turnCrank(); gumballMachine.insertQuarter(); gumballMachine.turnCrank(); gumballMachine.ejectQuarter(); System.out.println(gumballMachine); gumballMachine.insertQuarter(); gumballMachine.insertQuarter(); gumballMachine.turnCrank(); gumballMachine.insertQuarter(); gumballMachine.turnCrank(); gumballMachine.insertQuarter(); gumballMachine.turnCrank(); System.out.println(gumballMachine); }
// Test case 5 : Inserting more then 50 cents and checking for change and Gumball in slot @Test public void testFiftyPlusSecond() { gumballM1.insertDime(); gumballM1.insertDime(); gumballM1.insertDime(); gumballM1.insertQuarter(); gumballM1.turnCrank(); assertEquals(true, gumballM1.isGumballInSlot()); }
// Test case 1: insert 1 quarter, insert 1 dime and 3 nickel = 50Cents : +ve test case @Test public void testQDNNNHappy() { gumballM1.insertQuarter(); gumballM1.insertDime(); gumballM1.insertNickel(); gumballM1.insertNickel(); gumballM1.insertNickel(); gumballM1.turnCrank(); assertEquals(true, gumballM1.isGumballInSlot()); }
// Test Case 9: Insert 50 cents first but remove some amount before // turning crank then check to see if gumball is dispenced or not : -ve test case @Test public void TestQDDDDEjectQNegative() { gumballM1.insertQuarter(); gumballM1.insertDime(); gumballM1.insertDime(); gumballM1.insertDime(); gumballM1.ejectQuarter(); gumballM1.turnCrank(); assertEquals(false, gumballM1.isGumballInSlot()); }
// Test case 4 :Try to take a dispensed gumball and crank the machine again without inserting any // coin @Test public void testTakeGumballAndCrankAgainWithoutInsertingAnyCoinQDNNN() { gumballM1.insertQuarter(); gumballM1.insertDime(); gumballM1.insertNickel(); gumballM1.insertNickel(); gumballM1.insertNickel(); gumballM1.turnCrank(); gumballM1.takeGumballFromSlot(); soldState.turnCrank(); assertEquals(false, gumballM1.isGumballInSlot()); }
// Test Case 7 : Negative test case : No gumball should return when less then 50 cents inserted // and turned crank @Test public void testAddOneQuarterNeg() { gumballM1.insertQuarter(); gumballM1.turnCrank(); assertEquals(false, gumballM1.isGumballInSlot()); }