public void MyTestU01_emty_string_name() { List <VendingMachine> vendingMachines = new List <VendingMachine>(); //========================================================================================================== // CREATE(5, 10, 25, 100; 3; 10; 10; 10): int[] coinKinds = { 5, 10, 25, 100 }; int selectionButtonCount = 1; int coinRackCapacity = 10; int popRackCapcity = 10; int receptacleCapacity = 10; // Create VM: var vm = new VendingMachine(coinKinds, selectionButtonCount, coinRackCapacity, popRackCapcity, receptacleCapacity); VendingMachineLogic vmLogic = new VendingMachineLogic(vm); //Add it to the list of VM's: vendingMachines.Add(vm); int index = 0; // Index of VM which is going to be checked. vm = vendingMachines[index]; //================================================================================================================== // CONFIGURE([0] "Coke", 250; "water", 250; "stuff", 205): List <string> popNames = new List <string>() { "" }; List <int> popCosts = new List <int>() { 250 }; vm.Configure(popNames, popCosts); // Should throw the exception because of empty string pop name. }
public void U07_bad_button_number_2() { List <VendingMachine> vendingMachines = new List <VendingMachine>(); // Create list of VMs. //========================================================================================================== // CREATE(5, 10, 25; 100;3): int[] coinKinds = { 5, 10, 25, 100 }; int selectionButtonCount = 3; int coinRackCapacity = 0; int popRackCapcity = 0; int receptacleCapacity = 0; // Create VM: var vm = new VendingMachine(coinKinds, selectionButtonCount, coinRackCapacity, popRackCapcity, receptacleCapacity); VendingMachineLogic vmLogic = new VendingMachineLogic(vm); //Add it to the list of VM's: vendingMachines.Add(vm); int index = 0; // Index of VM which is going to be checked. vm = vendingMachines[index]; // Reference to the vending machine at index 0. //====================================================================================================================== // PRESS([0] 0): vm.SelectionButtons[-1].Press(); // Should throw the exception here }
public void U03_bad_names_list() { List <VendingMachine> vendingMachines = new List <VendingMachine>(); //========================================================================================================== // CREATE(5, 10, 25, 100; 3; 10; 10; 10): int[] coinKinds = { 5, 10, 25, 100 }; int selectionButtonCount = 3; int coinRackCapacity = 10; int popRackCapcity = 10; int receptacleCapacity = 10; // Create VM: var vm = new VendingMachine(coinKinds, selectionButtonCount, coinRackCapacity, popRackCapcity, receptacleCapacity); VendingMachineLogic vmLogic = new VendingMachineLogic(vm); //Add it to the list of VM's: vendingMachines.Add(vm); int index = 0; // Index of VM which is going to be checked. vm = vendingMachines[index]; // Reference to the vending machine at index 0. //================================================================================================================== // CONFIGURE([0] "Coke", 250; "water", 250) List <string> popNames = new List <string>() { "Coke", "water" }; List <int> popCosts = new List <int>() { 250, 250 }; vm.Configure(popNames, popCosts); // Should throw the Exception here }
/// test for U04-bad-non-unique-denomination public void TestMethod5() { coinKinds = new int[] { 1, 1 }; selectionButtonCount = 1; coinRackCapacity = 10; popCanRackCapacity = 10; receptacleCapacity = 10; VendingMachine vm = new VendingMachine(coinKinds, selectionButtonCount, coinRackCapacity, popCanRackCapacity, receptacleCapacity); expected = new VendingMachineLogic(vm); }
/// test for U06-bad-button-number public void TestMethod3() { coinKinds = new int[] { 5, 10, 25, 100 }; selectionButtonCount = 3; coinRackCapacity = 0; popCanRackCapacity = 0; receptacleCapacity = 0; VendingMachine vm = new VendingMachine(coinKinds, selectionButtonCount, coinRackCapacity, popCanRackCapacity, receptacleCapacity); vm.SelectionButtons.SetValue(3, 0); expected = new VendingMachineLogic(vm); }
/* * CREATE(5, 10, 25, 100; 3; 10; 10; 10) * EXTRACT([0]) * CHECK_DELIVERY(0) * UNLOAD([0]) * ` CHECK_TEARDOWN(0; 0) * */ public void TestMethod1() { coinKinds = new int[] { 5, 10, 25, 100 }; selectionButtonCount = 3; coinRackCapacity = 10; popCanRackCapacity = 10; receptacleCapacity = 10; VendingMachine vm = new VendingMachine(coinKinds, selectionButtonCount, coinRackCapacity, popCanRackCapacity, receptacleCapacity); vendingMachine = new VendingMachineLogic(vm); Assert.AreEqual(expected, actual); }
/// test for U03-bad-names-list public void TestMethod6() { coinKinds = new int[] { 5, 10, 25, 100 }; selectionButtonCount = 3; coinRackCapacity = 10; popCanRackCapacity = 10; receptacleCapacity = 10; List <string> name = new List <string>() { "Coke", "water" }; List <int> cost = new List <int>() { 250, 250 }; VendingMachine vm = new VendingMachine(coinKinds, selectionButtonCount, coinRackCapacity, popCanRackCapacity, receptacleCapacity); vm.Configure(name, cost); expected = new VendingMachineLogic(vm); }
//====================================================Creating vending machine public int CreateVendingMachine(List <int> coinKinds, int selectionButtonCount, int coinRackCapacity, int popRackCapacity, int receptacleCapacity) { int[] convertedCoinKinds = new int[coinKinds.Count]; int index = 0; foreach (int kind in coinKinds) { convertedCoinKinds[index++] = kind; } VendingMachine newMachine = new VendingMachine(convertedCoinKinds, selectionButtonCount, coinRackCapacity, popRackCapacity, receptacleCapacity); machines.Add(newMachine); VendingMachineLogic newLogic = new VendingMachineLogic(newMachine, coinKinds); return(0); /*//Test * Console.WriteLine("Test for create vending machine:"); * for (int i = 0; i < coinKinds.Count; i++) * { * Console.Write(coinKinds[i] + ","); * } * Console.WriteLine(selectionButtonCount);*/ }
public void T13_good_need_to_store_payment() { List <VendingMachine> vendingMachines = new List <VendingMachine>(); // Create list of VMs. //========================================================================================================== // CREATE(5, 10, 25, 100; 3; 10; 10; 10): int[] coinKinds = { 5, 10, 25, 100 }; int selectionButtonCount = 1; int coinRackCapacity = 10; int popRackCapcity = 10; int receptacleCapacity = 10; // Create VM: var vm = new VendingMachine(coinKinds, selectionButtonCount, coinRackCapacity, popRackCapcity, receptacleCapacity); VendingMachineLogic vmLogic = new VendingMachineLogic(vm); //Add it to the list of VM's: vendingMachines.Add(vm); int index = 0; // Index of VM which is going to be checked. vm = vendingMachines[index]; // Reference to the vending machine at index 0. //================================================================================================================== // CONFIGURE([0] "stuff", 135): List <string> popNames = new List <string>() { "stuff" }; List <int> popCosts = new List <int>() { 135 }; vm.Configure(popNames, popCosts); //=================================================================================================================== // COIN_LOAD([0] 0; 5, 10): int coinKindIndex = 0; List <Coin> coins = new List <Coin> { new Coin(5), new Coin(5), new Coin(5), new Coin(5), new Coin(5), new Coin(5), new Coin(5), new Coin(5), new Coin(5), new Coin(5) }; vm.CoinRacks[coinKindIndex].LoadCoins(coins); // COIN_LOAD([0] 1; 10, 10): coinKindIndex = 1; coins = new List <Coin> { new Coin(10), new Coin(10), new Coin(10), new Coin(10), new Coin(10), new Coin(10), new Coin(10), new Coin(10), new Coin(10), new Coin(10) }; vm.CoinRacks[coinKindIndex].LoadCoins(coins); // COIN_LOAD([0] 2; 25, 10): coinKindIndex = 2; coins = new List <Coin> { new Coin(25), new Coin(25), new Coin(25), new Coin(25), new Coin(25), new Coin(25), new Coin(25), new Coin(25), new Coin(25), new Coin(25) }; vm.CoinRacks[coinKindIndex].LoadCoins(coins); // COIN_LOAD([0] 3; 100, 10): coinKindIndex = 3; coins = new List <Coin> { new Coin(100), new Coin(100), new Coin(100), new Coin(100), new Coin(100), new Coin(100), new Coin(100), new Coin(100), new Coin(100), new Coin(100) }; vm.CoinRacks[coinKindIndex].LoadCoins(coins); //===================================================================================================================== // POP_LOAD([0] 0; "stuff", 1): int popKindIndex = 0; List <PopCan> pops = new List <PopCan> { new PopCan("stuff") }; vm.PopCanRacks[popKindIndex].LoadPops(pops); //======================================================================================================================= // INSERT([0] 25) // INSERT([0] 100) // INSERT([0] 10) vm.CoinSlot.AddCoin(new Coin(25)); vm.CoinSlot.AddCoin(new Coin(100)); vm.CoinSlot.AddCoin(new Coin(10)); //====================================================================================================================== // PRESS([0] 0): vm.SelectionButtons[0].Press(); //===================================================================================================================== // EXTRACT([0]) // CHECK_DELIVERY(0, "stuff"): // Get actual list of items from the delivery chute and create expected list of items: var items = vm.DeliveryChute.RemoveItems(); List <IDeliverable> itemsAsList = new List <IDeliverable>(items); List <IDeliverable> expectedItemsAsList = new List <IDeliverable> { new PopCan("stuff") }; // Check to see if two lists are of the same length, if not, throw the exception: if (itemsAsList.Count == expectedItemsAsList.Count) { int i = 0; while (i < items.Length) { // Compare element by element: var element1 = items[i]; var element2 = expectedItemsAsList[i]; Assert.AreEqual(element1.ToString(), element2.ToString()); i++; } } // Lists have different length, they are not the same, throw the exception: else { throw new AssertFailedException(); } //===================================================================================================================== // UNLOAD([0]) // CHECK_TEARDOWN(1400; 135): // Modify fields of the StoredContents obj, which corresponds to actual VM: var storedContents = new VendingMachineStoredContents(); foreach (var coinRack in vm.CoinRacks) { // Add items to CoinInCoinsRacks field: storedContents.CoinsInCoinRacks.Add(coinRack.Unload()); } // Modify PaymentCoinsInStorageBin field (add some items to it): storedContents.PaymentCoinsInStorageBin.AddRange(vm.StorageBin.Unload()); foreach (var popCanRack in vm.PopCanRacks) { // Add items to PopCansInPopCanRacks field: storedContents.PopCansInPopCanRacks.Add(popCanRack.Unload()); } // Modify fields of the StoredContents obj, based on expected values: VendingMachineStoredContents expectedStoredContents = new VendingMachineStoredContents(); // Modify PaymentCoinsInStorageBin field of the expected one: List <Coin> expectedCoinsInStorageBin = new List <Coin> { new Coin(25), new Coin(100), new Coin(10) }; foreach (var coin in expectedCoinsInStorageBin) { expectedStoredContents.PaymentCoinsInStorageBin.Add(coin); } // Create some lists in order to add them to CoinsInCoinRacks of the expected one: List <Coin> expectedCoinRack0 = new List <Coin> { new Coin(5), new Coin(5), new Coin(5), new Coin(5), new Coin(5), new Coin(5), new Coin(5), new Coin(5), new Coin(5), new Coin(5) }; List <Coin> expectedCoinRack1 = new List <Coin> { new Coin(10), new Coin(10), new Coin(10), new Coin(10), new Coin(10), new Coin(10), new Coin(10), new Coin(10), new Coin(10), new Coin(10) }; List <Coin> expectedCoinRack2 = new List <Coin> { new Coin(25), new Coin(25), new Coin(25), new Coin(25), new Coin(25), new Coin(25), new Coin(25), new Coin(25), new Coin(25), new Coin(25) }; List <Coin> expectedCoinRack3 = new List <Coin> { new Coin(100), new Coin(100), new Coin(100), new Coin(100), new Coin(100), new Coin(100), new Coin(100), new Coin(100), new Coin(100), new Coin(100) }; List <List <Coin> > expectedListOfCoinRacks = new List <List <Coin> > { expectedCoinRack0, expectedCoinRack1, expectedCoinRack2, expectedCoinRack3 }; foreach (var list in expectedListOfCoinRacks) { // Modify CoinsInCoinRacks field by adding some items to it: expectedStoredContents.CoinsInCoinRacks.Add(list); } // Create some lists in order to add them to PopCansInPopCanRacks of the expected one: List <PopCan> expectedPopRack0 = new List <PopCan> { }; List <List <PopCan> > expectedListOfPopRacks = new List <List <PopCan> > { expectedPopRack0 }; foreach (var list in expectedListOfPopRacks) { // Modify PopCansInPopCanRacks field by adding some items to it: expectedStoredContents.PopCansInPopCanRacks.Add(list); } // Comparison of expected and actual VM's storage bins: // Check length of lists first, if different, throw the exception: if (storedContents.PaymentCoinsInStorageBin.Count == expectedStoredContents.PaymentCoinsInStorageBin.Count) { int i = 0; // Check each element of the list: while (i < storedContents.PaymentCoinsInStorageBin.Count) { Assert.AreEqual(storedContents.PaymentCoinsInStorageBin[i].Value, expectedStoredContents.PaymentCoinsInStorageBin[i].Value); i++; } } // Length is different, throw the exception: else { throw new AssertFailedException(); } // Comparison of expected and actual VM's storage coin racks: // Check length of lists first, if different, throw the exception: if (storedContents.CoinsInCoinRacks.Count == expectedStoredContents.CoinsInCoinRacks.Count) { int i = 0; int j = 0; // Length is the same, check the inner lists: while (i < storedContents.CoinsInCoinRacks.Count) { // Check the length of the innner lists, throw exception if different: if (storedContents.CoinsInCoinRacks[i].Count == expectedStoredContents.CoinsInCoinRacks[i].Count) { // Compare the values of each elements in the inner lists: while (j < storedContents.CoinsInCoinRacks[i].Count) { Assert.AreEqual(storedContents.CoinsInCoinRacks[i][j].Value, expectedStoredContents.CoinsInCoinRacks[i][j].Value); j++; } } // Length is different of the inner lists, throw the exception: else { throw new AssertFailedException(); } // Go to the next pair of inner lists: j = 0; i++; } } // Length of the outer lists is different, throw the exception: else { throw new AssertFailedException(); } // Check to see if length of PopCansInPopCanRacks lists is the same: if (storedContents.PopCansInPopCanRacks.Count == expectedStoredContents.PopCansInPopCanRacks.Count) { int i = 0; int j = 0; // Length of outer lists is the same, check the inner lists: while (i < storedContents.PopCansInPopCanRacks.Count) { // Make sure that the length of the inner lists is the same: if (storedContents.PopCansInPopCanRacks[i].Count == expectedStoredContents.PopCansInPopCanRacks[i].Count) { // Length of the inner lists is the same, compare the name of all elements in the inner lists: while (j < storedContents.PopCansInPopCanRacks[i].Count) { Assert.AreEqual(storedContents.PopCansInPopCanRacks[i][j].Name, expectedStoredContents.PopCansInPopCanRacks[i][j].Name); j++; } } // Length of the inner lists is different, throw the exception: else { throw new AssertFailedException(); } j = 0; i++; } } // Length of the outer lists is different, throw the exception: else { throw new AssertFailedException(); } }
public void TestMethod1() { int[] coins = { 5, 10, 25, 100 }; int selectionButtonCount = 3; int coinRackCapacity = 10; int popRackCapacity = 10; int receptacleCapacity = 10; VendingMachine vm = new VendingMachine(coins, selectionButtonCount, coinRackCapacity, popRackCapacity, receptacleCapacity); VendingMachineLogic l = new VendingMachineLogic(vm); List <string> popNames = new List <string>(); popNames.Add("Coke"); popNames.Add("water"); popNames.Add("stuff"); List <int> popCosts = new List <int>(); popCosts.Add(250); popCosts.Add(250); popCosts.Add(205); vm.Configure(popNames, popCosts); Coin five = new Coin(5); Coin ten = new Coin(10); Coin twentyFive = new Coin(25); Coin hundred = new Coin(100); List <Coin> fiveCoins = new List <Coin>(); fiveCoins.Add(five); List <Coin> tenCoins = new List <Coin>(); tenCoins.Add(ten); List <Coin> twentyFiveCoins = new List <Coin>(); twentyFiveCoins.Add(twentyFive); var rack = vm.CoinRacks; rack[0].LoadCoins(fiveCoins); rack[1].LoadCoins(tenCoins); rack[2].LoadCoins(twentyFiveCoins); PopCan coke = new PopCan("Coke"); PopCan water = new PopCan("water"); PopCan stuff = new PopCan("stuff"); List <PopCan> cokes = new List <PopCan>(); cokes.Add(coke); List <PopCan> waters = new List <PopCan>(); waters.Add(water); List <PopCan> stuffs = new List <PopCan>(); stuffs.Add(stuff); }