diff --git a/domain-model.md b/domain-model.md new file mode 100644 index 000000000..f677660f5 --- /dev/null +++ b/domain-model.md @@ -0,0 +1,41 @@ + + +| Class | Variables | Methods | Scenario | Output | +|----------------------|------------------------------------------------------|-----------------------------------|-------------------------------------------------------------------------------------------------------------------|-----------| +| Basket | ArrayList items | boolean addItem(SKU SKU) | Variant exists in catalog and inventory, and is added. | true | +| | int capacity | | basket is full and can't add the item. Calls basketIsFullMessage() | false | +| | HashMap quantityMap | | | | +| | | boolean removeItem(SKU SKU) | variant exists in basket, and is removed | true | +| | | | variant does not exist in basket and can't be removed. Calls itemNotInBasketMessage() | false | +| | | void basketIsFullMessage() | prints error message for user that basket is full | | +| | | boolean setCapacity(int capacity) | user wants to change the capacity to a reasonable amount | true | +| | | | user tries to change capacity to 0 or less | false | +| | | int getCapacity() | returns capacity of basket | capacity | +| | | void itemNotInBasketMessage() | prints error message for user that item doesn't exist in their basket | | +| | | float calculateCost() | total amount to pay is requested | totalCost | +| | | StringBuilder getReceipt() | iterates through items and calculates potential discounts. Important information is appended to StringBuilder obj | receipt | +| | | | | | +| | | | | | +| | | | | | +| Enum SKU | includes an enum variable for all variations of SKUs | | | | +| | | | | | +| | | | | | +| Item (abstract) | float price | float getPrice() | returns price of item | price | +| | String name | String getName() | returns name of item | name | +| | String variant | String getVariant() | returns variant of item | variant | +| | SKU SKU | enum getSKU() | returns SKU enum | SKU | +| | | | | | +| Bagel extends Item | | Bagel(SKU sku) | SKU refers to a bagel, and an instance is created | | +| | | | SKU does not refer to a bagel, and the instance is not created correctly | | +| Coffee extends Item | | Coffee(SKU sku) | SKU refers to a coffee, and an instance is created | | +| | | | SKU does not refer to a coffee, and the instance is not created correctly | | +| Filling extends Item | | Filling(SKU sku) | SKU refers to a filling, and an instance is created | | +| | | | SKU does not refer to a filling, and the instance is not created correctly | | +| | | | | | +| | | | | | +| | | | | | +| | | | | | +| | | | | | +| | | | | | +| | | | | | +| | | | | | diff --git a/src/BobsBagelsClassDiagram.png b/src/BobsBagelsClassDiagram.png new file mode 100644 index 000000000..8e2c99a25 Binary files /dev/null and b/src/BobsBagelsClassDiagram.png differ diff --git a/src/main/java/com/booleanuk/core/Bagel.java b/src/main/java/com/booleanuk/core/Bagel.java new file mode 100644 index 000000000..5116fc245 --- /dev/null +++ b/src/main/java/com/booleanuk/core/Bagel.java @@ -0,0 +1,32 @@ +package com.booleanuk.core; + +public class Bagel extends Item { + + public Bagel(SKU SKU) { + this.SKU = SKU; + switch (SKU) { + case BGLO: + this.price = 0.49F; + this.name = "Bagel"; + this.variant = "Onion"; + break; + case BGLP: + this.price = 0.39F; + this.name = "Bagel"; + this.variant = "Plain"; + break; + case BGLE: + this.price = 0.49F; + this.name = "Bagel"; + this.variant = "Everything"; + break; + case BGLS: + this.price = 0.49F; + this.name = "Bagel"; + this.variant = "Sesame"; + break; + } + } + + +} diff --git a/src/main/java/com/booleanuk/core/Basket.java b/src/main/java/com/booleanuk/core/Basket.java new file mode 100644 index 000000000..220d013c1 --- /dev/null +++ b/src/main/java/com/booleanuk/core/Basket.java @@ -0,0 +1,82 @@ +package com.booleanuk.core; + +import java.util.ArrayList; +import java.util.Scanner; + +public class Basket { + ArrayList items; + protected int capacity = 20; + + public Basket() { + items = new ArrayList<>(); + } + + public boolean addItem(SKU sku) { + + // if no capacity, return false + if(items.size() >= capacity) { + basketIsFullMessage(); + return false; + } + + // add Bagel + if(sku == SKU.BGLE || sku == SKU.BGLO || sku == SKU.BGLP || sku == SKU.BGLS) { + items.add(new Bagel(sku)); + } + // add Coffee + else if (sku == SKU.COFB || sku == SKU.COFW || sku == SKU.COFC || sku == SKU.COFL) { + items.add(new Coffee(sku)); + } + // add Filling + else if(sku == SKU.FILB || sku == SKU.FILC || sku == SKU.FILE || + sku == SKU.FILH || sku == SKU.FILS || sku == SKU.FILX) { + items.add(new Filling(sku)); + } + // SKU not recognized, return false + else { + System.out.println("SKU doesn't exist in catalog."); + return false; + } + return true; + } + + boolean removeBagel(SKU SKU) { + for(int i = 0; i < items.size(); i++) { + if(items.get(i).SKU == SKU) { + items.remove(i); + return true; + } + } + itemNotInBasket(); + return false; + } + + public void basketIsFullMessage() { + System.out.println("Basket is full."); + } + + public void itemNotInBasket() { + System.out.println("Couldn't find that item in your basket."); + } + + public float calculateCost() { + float totalCost = 0F; + for(Item item : items) { + totalCost += item.getPrice(); + } + return totalCost; + } + + public boolean setCapacity(int capacity) { + if(capacity > 0) { + this.capacity = capacity; + return true; + } + System.out.println("Invalid capacity entered."); + return false; + } + + public int getCapacity() { + return this.capacity; + } +} diff --git a/src/main/java/com/booleanuk/core/Coffee.java b/src/main/java/com/booleanuk/core/Coffee.java new file mode 100644 index 000000000..694610ad0 --- /dev/null +++ b/src/main/java/com/booleanuk/core/Coffee.java @@ -0,0 +1,30 @@ +package com.booleanuk.core; + +public class Coffee extends Item { + + public Coffee(SKU SKU) { + this.SKU = SKU; + switch (SKU) { + case COFB: + this.price = 0.99F; + this.name = "Coffee"; + this.variant = "Black"; + break; + case COFW: + this.price = 1.19F; + this.name = "Coffee"; + this.variant = "White"; + break; + case COFC: + this.price = 1.29F; + this.name = "Coffee"; + this.variant = "Capuccino"; + break; + case COFL: + this.price = 1.29F; + this.name = "Coffee"; + this.variant = "Latte"; + break; + } + } +} diff --git a/src/main/java/com/booleanuk/core/Filling.java b/src/main/java/com/booleanuk/core/Filling.java new file mode 100644 index 000000000..582831857 --- /dev/null +++ b/src/main/java/com/booleanuk/core/Filling.java @@ -0,0 +1,40 @@ +package com.booleanuk.core; + +public class Filling extends Item { + + public Filling(SKU SKU) { + this.SKU = SKU; + switch (SKU) { + case FILB: + this.price = 0.12F; + this.name = "Filling"; + this.variant = "Bacon"; + break; + case FILE: + this.price = 0.12F; + this.name = "Filling"; + this.variant = "Egg"; + break; + case FILC: + this.price = 0.12F; + this.name = "Filling"; + this.variant = "Cheese"; + break; + case FILX: + this.price = 0.12F; + this.name = "Filling"; + this.variant = "Cream Cheese"; + break; + case FILS: + this.price = 0.12F; + this.name = "Filling"; + this.variant = "Smoked Salmon"; + break; + case FILH: + this.price = 0.12F; + this.name = "Filling"; + this.variant = "Ham"; + break; + } + } +} diff --git a/src/main/java/com/booleanuk/core/Item.java b/src/main/java/com/booleanuk/core/Item.java new file mode 100644 index 000000000..8f229e8f7 --- /dev/null +++ b/src/main/java/com/booleanuk/core/Item.java @@ -0,0 +1,40 @@ +package com.booleanuk.core; + +enum SKU { + BGLO, + BGLP, + BGLE, + BGLS, + COFB, + COFW, + COFC, + COFL, + FILB, + FILE, + FILC, + FILX, + FILS, + FILH +} +public abstract class Item { + protected SKU SKU; + protected float price; + protected String name; + protected String variant; + + public float getPrice() { + return price; + } + + public String getName() { + return name; + } + + String getVariant() { + return variant; + } + + SKU getSKU() { + return SKU; + } +} diff --git a/src/main/java/com/booleanuk/extension/Bagel.java b/src/main/java/com/booleanuk/extension/Bagel.java new file mode 100644 index 000000000..dc661e92d --- /dev/null +++ b/src/main/java/com/booleanuk/extension/Bagel.java @@ -0,0 +1,32 @@ +package com.booleanuk.extension; + +public class Bagel extends Item { + + public Bagel(SKU SKU) { + this.SKU = SKU; + switch (SKU) { + case BGLO: + this.price = 0.49F; + this.name = "Bagel"; + this.variant = "Onion"; + break; + case BGLP: + this.price = 0.39F; + this.name = "Bagel"; + this.variant = "Plain"; + break; + case BGLE: + this.price = 0.49F; + this.name = "Bagel"; + this.variant = "Everything"; + break; + case BGLS: + this.price = 0.49F; + this.name = "Bagel"; + this.variant = "Sesame"; + break; + } + } + + +} diff --git a/src/main/java/com/booleanuk/extension/Basket.java b/src/main/java/com/booleanuk/extension/Basket.java new file mode 100644 index 000000000..41cc86dbb --- /dev/null +++ b/src/main/java/com/booleanuk/extension/Basket.java @@ -0,0 +1,187 @@ +package com.booleanuk.extension; + +import java.util.ArrayList; +import java.util.HashMap; + +public class Basket { + ArrayList items; + protected int capacity = 30; + HashMap quantityMap; + + public Basket() { + items = new ArrayList<>(); + } + + public boolean addItem(SKU sku) { + + // if no capacity, return false + if(items.size() >= capacity) { + basketIsFullMessage(); + return false; + } + + // add Bagel + if(sku == SKU.BGLE || sku == SKU.BGLO || sku == SKU.BGLP || sku == SKU.BGLS) { + items.add(new Bagel(sku)); + } + // add Coffee + else if (sku == SKU.COFB || sku == SKU.COFW || sku == SKU.COFC || sku == SKU.COFL) { + items.add(new Coffee(sku)); + } + // add Filling + else if(sku == SKU.FILB || sku == SKU.FILC || sku == SKU.FILE || + sku == SKU.FILH || sku == SKU.FILS || sku == SKU.FILX) { + items.add(new Filling(sku)); + } + // SKU not recognized, return false + else { + System.out.println("SKU doesn't exist in catalog."); + return false; + } + return true; + } + + boolean removeItem(SKU SKU) { + for(int i = 0; i < items.size(); i++) { + if(items.get(i).SKU == SKU) { + items.remove(i); + return true; + } + } + itemNotInBasket(); + return false; + } + + public void basketIsFullMessage() { + System.out.println("Basket is full."); + } + + public void itemNotInBasket() { + System.out.println("Couldn't find that item in your basket."); + } + + public float calculateCost() { + float totalCost = 0F; + for(Item item : items) { + totalCost += item.getPrice(); + } + return totalCost; + } + + public boolean setCapacity(int capacity) { + if(capacity > 0) { + this.capacity = capacity; + return true; + } + System.out.println("Invalid capacity entered."); + return false; + } + + public int getCapacity() { + return this.capacity; + } + + public StringBuilder getReceipt() { + this.quantityMap = new HashMap<>(); + for(Item i : items) { + Integer counter = quantityMap.get(i.getSKU()); + if(counter == null) { + counter = 0; + } + quantityMap.put(i.getSKU(), counter+1 ); + } + System.out.println(quantityMap); + + StringBuilder receipt = new StringBuilder(); + float totalCost = 0F; + + receipt.append("\t~~~ Bob's Bagels ~~~\n"); + receipt.append(" --------------------------\n\n"); + + // calculate discount for bagels + for(SKU k : quantityMap.keySet()) { + if(k == SKU.BGLE || k == SKU.BGLP || k == SKU.BGLS || k == SKU.BGLO) { + // Calculate 12x discount for a bagel + while(quantityMap.get(k) >= 12) { + Bagel refBagel = new Bagel(k); + totalCost += 3.99F; + receipt.append(refBagel.getVariant() + " " + refBagel.getName() + "\t\t\t" + 12 + "\t£3.99\n"); + quantityMap.put(k, quantityMap.get(k) - 12); + } + + // calculate 6x discount for a bagel + while(quantityMap.get(k) >= 6) { + Bagel refBagel = new Bagel(k); + totalCost += 2.49F; + receipt.append(refBagel.getVariant() + " " + refBagel.getName() + "\t\t\t" + 6 + "\t£2.49\n"); + quantityMap.put(k, quantityMap.get(k) - 6); + } + } + } + + // calculate discount for "Bagel and Coffee" + for(SKU k : quantityMap.keySet()) { + if(k == SKU.COFB || k == SKU.COFC || k == SKU.COFL || k == SKU.COFW) { + Coffee refCoffee = new Coffee(k); + + while(quantityMap.get(k) > 0) { + if (quantityMap.containsKey(SKU.BGLE) && quantityMap.get(SKU.BGLE) > 0) { + totalCost += 1.25F; + receipt.append("Coffee + Bagel\t\t" + 1 + "\t£1.25\n"); + quantityMap.put(k, quantityMap.get(k) - 1); + quantityMap.put(SKU.BGLE, quantityMap.get(SKU.BGLE) - 1); + } + else if (quantityMap.containsKey(SKU.BGLO) && quantityMap.get(SKU.BGLO) > 0) { + totalCost += 1.25F; + receipt.append("Coffee + Bagel\t\t" + 1 + "\t£1.25\n"); + quantityMap.put(k, quantityMap.get(k) - 1); + quantityMap.put(SKU.BGLO, quantityMap.get(SKU.BGLO) - 1); + } + else if (quantityMap.containsKey(SKU.BGLS) && quantityMap.get(SKU.BGLS) > 0) { + totalCost += 1.25F; + receipt.append("Coffee + Bagel\t\t" + 1 + "\t£1.25\n"); + quantityMap.put(k, quantityMap.get(k) - 1); + quantityMap.put(SKU.BGLS, quantityMap.get(SKU.BGLS) - 1); + } + else if (quantityMap.containsKey(SKU.BGLP) && quantityMap.get(SKU.BGLP) > 0) { + totalCost += 1.25F; + receipt.append("Coffee + Bagel\t\t" + 1 + "\t£1.25\n"); + quantityMap.put(k, quantityMap.get(k) - 1); + quantityMap.put(SKU.BGLP, quantityMap.get(SKU.BGLP) - 1); + } + else { + totalCost += refCoffee.getPrice() * quantityMap.get(k); + receipt.append(refCoffee.getVariant() + " " + refCoffee.getName() + "\t\t" + + quantityMap.get(k) + "\t£" + (refCoffee.getPrice() * quantityMap.get(k)) + "\n"); + quantityMap.put(k, 0); + } + } + } + } + + for(SKU k : quantityMap.keySet()) { + Item refItem; + if(k == SKU.BGLE || k == SKU.BGLO || k == SKU.BGLP || k == SKU.BGLS) { + refItem = new Bagel(k); + } + else if(k == SKU.COFB || k == SKU.COFC || k == SKU.COFL || k == SKU.COFW) { + refItem = new Coffee(k); + } + else { + refItem = new Filling(k); + } + + if(quantityMap.get(k) > 0) { + float cost = refItem.getPrice() * quantityMap.get(k); + totalCost += cost; + receipt.append(refItem.getVariant() + " " + refItem.getName() + "\t\t" + quantityMap.get(k) + "\t£" + cost + "\n"); + quantityMap.put(k, 0); + } + } + receipt.append("\n --------------------------"); + receipt.append("\nTotal cost:\t\t\t\t£" + totalCost); + + return receipt; + + } +} diff --git a/src/main/java/com/booleanuk/extension/Coffee.java b/src/main/java/com/booleanuk/extension/Coffee.java new file mode 100644 index 000000000..c00aef3ef --- /dev/null +++ b/src/main/java/com/booleanuk/extension/Coffee.java @@ -0,0 +1,30 @@ +package com.booleanuk.extension; + +public class Coffee extends Item { + + public Coffee(SKU SKU) { + this.SKU = SKU; + switch (SKU) { + case COFB: + this.price = 0.99F; + this.name = "Coffee"; + this.variant = "Black"; + break; + case COFW: + this.price = 1.19F; + this.name = "Coffee"; + this.variant = "White"; + break; + case COFC: + this.price = 1.29F; + this.name = "Coffee"; + this.variant = "Capuccino"; + break; + case COFL: + this.price = 1.29F; + this.name = "Coffee"; + this.variant = "Latte"; + break; + } + } +} diff --git a/src/main/java/com/booleanuk/extension/Filling.java b/src/main/java/com/booleanuk/extension/Filling.java new file mode 100644 index 000000000..8dcdf9059 --- /dev/null +++ b/src/main/java/com/booleanuk/extension/Filling.java @@ -0,0 +1,40 @@ +package com.booleanuk.extension; + +public class Filling extends Item { + + public Filling(SKU SKU) { + this.SKU = SKU; + switch (SKU) { + case FILB: + this.price = 0.12F; + this.name = "Filling"; + this.variant = "Bacon"; + break; + case FILE: + this.price = 0.12F; + this.name = "Filling"; + this.variant = "Egg"; + break; + case FILC: + this.price = 0.12F; + this.name = "Filling"; + this.variant = "Cheese"; + break; + case FILX: + this.price = 0.12F; + this.name = "Filling"; + this.variant = "Cream Cheese"; + break; + case FILS: + this.price = 0.12F; + this.name = "Filling"; + this.variant = "Smoked Salmon"; + break; + case FILH: + this.price = 0.12F; + this.name = "Filling"; + this.variant = "Ham"; + break; + } + } +} diff --git a/src/main/java/com/booleanuk/extension/Item.java b/src/main/java/com/booleanuk/extension/Item.java new file mode 100644 index 000000000..a96d3cc5d --- /dev/null +++ b/src/main/java/com/booleanuk/extension/Item.java @@ -0,0 +1,24 @@ +package com.booleanuk.extension; + +public abstract class Item { + protected SKU SKU; + protected float price; + protected String name; + protected String variant; + + public float getPrice() { + return price; + } + + public String getName() { + return name; + } + + String getVariant() { + return variant; + } + + SKU getSKU() { + return SKU; + } +} diff --git a/src/main/java/com/booleanuk/extension/SKU.java b/src/main/java/com/booleanuk/extension/SKU.java new file mode 100644 index 000000000..7c12e4469 --- /dev/null +++ b/src/main/java/com/booleanuk/extension/SKU.java @@ -0,0 +1,18 @@ +package com.booleanuk.extension; + +enum SKU { + BGLO, + BGLP, + BGLE, + BGLS, + COFB, + COFW, + COFC, + COFL, + FILB, + FILE, + FILC, + FILX, + FILS, + FILH +} diff --git a/src/test/java/com/booleanuk/core/BagelTest.java b/src/test/java/com/booleanuk/core/BagelTest.java new file mode 100644 index 000000000..cc3dd2205 --- /dev/null +++ b/src/test/java/com/booleanuk/core/BagelTest.java @@ -0,0 +1,43 @@ +package com.booleanuk.core; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +public class BagelTest { + + @Test + public void checkBagelPriceTest() { + Bagel bagel = new Bagel(SKU.BGLP); + Assertions.assertEquals(0.39F, bagel.getPrice()); + } + + @Test + public void checkWrongBagelPriceTest() { + Bagel bagel = new Bagel(SKU.BGLS); + Assertions.assertNotEquals(0.39F, bagel.getPrice()); + } + + @Test + public void checkBagelNameTest() { + Bagel bagel = new Bagel(SKU.BGLP); + Assertions.assertEquals("Bagel", bagel.getName()); + } + + @Test + public void checkWrongBagelNameTest() { + Bagel bagel = new Bagel(SKU.FILC); + Assertions.assertNotEquals("Bagel", bagel.getName()); + } + + @Test + public void checkBagelVariantTest() { + Bagel bagel = new Bagel(SKU.BGLP); + Assertions.assertEquals("Plain", bagel.getVariant()); + } + + @Test + public void checkWrongBagelVariantTest() { + Bagel bagel = new Bagel(SKU.BGLE); + Assertions.assertNotEquals("Plain", bagel.getVariant()); + } +} diff --git a/src/test/java/com/booleanuk/core/BasketTest.java b/src/test/java/com/booleanuk/core/BasketTest.java new file mode 100644 index 000000000..308e1b670 --- /dev/null +++ b/src/test/java/com/booleanuk/core/BasketTest.java @@ -0,0 +1,91 @@ +package com.booleanuk.core; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +public class BasketTest { + + @Test + public void addBagelCorrectlyTest() { + Basket basket = new Basket(); + basket.addItem(SKU.BGLP); + Assertions.assertEquals(1, basket.items.size()); + Assertions.assertEquals(SKU.BGLP, basket.items.getFirst().SKU); + } + + @Test + public void addBagelCorrectlyTest2() { + Basket basket = new Basket(); + Assertions.assertTrue(basket.addItem(SKU.BGLP)); + } + + @Test + public void addBagelIncorrectlyTest() { + Basket basket = new Basket(); + basket.addItem(SKU.BGLP); + Assertions.assertEquals(1, basket.items.size()); + Assertions.assertNotEquals(SKU.BGLE, basket.items.getFirst().getSKU()); + } + + @Test + public void removeBagelCorrectlyTest() { + Basket basket = new Basket(); + basket.addItem(SKU.BGLP); + Assertions.assertEquals(1, basket.items.size()); + Assertions.assertTrue(basket.removeBagel(SKU.BGLP)); + Assertions.assertEquals(0, basket.items.size()); + } + + @Test + public void removeBagelIncorrectlyTest() { + Basket basket = new Basket(); + basket.addItem(SKU.BGLP); + Assertions.assertFalse(basket.removeBagel(SKU.BGLE)); + } + + @Test + public void removeBagelIncorrectlyTest2() { + Basket basket = new Basket(); + basket.addItem(SKU.BGLP); + Assertions.assertFalse(basket.removeBagel(SKU.COFW)); + } + + @Test + public void changeCapacityCorrectlyTest() { + Basket basket = new Basket(); + basket.setCapacity(10); + Assertions.assertEquals(10, basket.getCapacity()); + } + + @Test + public void changeCapacityCorrectlyTest2() { + Basket basket = new Basket(); + Assertions.assertTrue(basket.setCapacity(10)); + } + + @Test + public void changeCapacityIncorrectlyTest() { + Basket basket = new Basket(); + Assertions.assertFalse(basket.setCapacity(-5)); + } + + @Test + public void changeCapacityIncorrectlyTest2() { + Basket basket = new Basket(); + basket.setCapacity(-20); + Assertions.assertNotEquals(-20, basket.getCapacity()); + } + + @Test + public void changeCapacityIncorrectlyTest3() { + Basket basket = new Basket(); + Bagel bagel1 = new Bagel(SKU.BGLP); + Bagel bagel2 = new Bagel(SKU.BGLO); + Coffee coffee = new Coffee(SKU.COFW); + basket.addItem(bagel1.SKU); + basket.addItem(bagel2.SKU); + basket.addItem(coffee.SKU); + float totalPrice = bagel1.getPrice() + bagel2.getPrice() + coffee.getPrice(); + Assertions.assertEquals(totalPrice, basket.calculateCost()); + } +} diff --git a/src/test/java/com/booleanuk/core/CoffeeTest.java b/src/test/java/com/booleanuk/core/CoffeeTest.java new file mode 100644 index 000000000..cbb755f63 --- /dev/null +++ b/src/test/java/com/booleanuk/core/CoffeeTest.java @@ -0,0 +1,42 @@ +package com.booleanuk.core; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +public class CoffeeTest { + @Test + public void checkCoffeePriceTest() { + Coffee coffee = new Coffee(SKU.COFB); + Assertions.assertEquals(0.99F, coffee.getPrice()); + } + + @Test + public void checkWrongCoffeePriceTest() { + Coffee coffee = new Coffee(SKU.COFW); + Assertions.assertNotEquals(0.99F, coffee.getPrice()); + } + + @Test + public void checkCoffeeNameTest() { + Coffee coffee = new Coffee(SKU.COFB); + Assertions.assertEquals("Coffee", coffee.getName()); + } + + @Test + public void checkWrongCoffeeNameTest() { + Coffee coffee = new Coffee(SKU.COFB); + Assertions.assertNotEquals("Bagel", coffee.getName()); + } + + @Test + public void checkCoffeeVariantTest() { + Coffee coffee = new Coffee(SKU.COFW); + Assertions.assertEquals("White", coffee.getVariant()); + } + + @Test + public void checkWrongCoffeeVariantTest() { + Coffee coffee = new Coffee(SKU.COFW); + Assertions.assertNotEquals("Black", coffee.getVariant()); + } +} diff --git a/src/test/java/com/booleanuk/core/FillingTest.java b/src/test/java/com/booleanuk/core/FillingTest.java new file mode 100644 index 000000000..6463bc3d0 --- /dev/null +++ b/src/test/java/com/booleanuk/core/FillingTest.java @@ -0,0 +1,42 @@ +package com.booleanuk.core; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +public class FillingTest { + @Test + public void checkFillingPriceTest() { + Filling filling = new Filling(SKU.FILB); + Assertions.assertEquals(0.12F, filling.getPrice()); + } + + @Test + public void checkWrongFillingPriceTest() { + Filling filling = new Filling(SKU.FILB); + Assertions.assertNotEquals(0.99F, filling.getPrice()); + } + + @Test + public void checkFillingNameTest() { + Filling filling = new Filling(SKU.FILB); + Assertions.assertEquals("Filling", filling.getName()); + } + + @Test + public void checkWrongFillingNameTest() { + Filling filling = new Filling(SKU.FILC); + Assertions.assertNotEquals("Bagel", filling.getName()); + } + + @Test + public void checkFillingVariantTest() { + Filling filling = new Filling(SKU.FILB); + Assertions.assertEquals("Bacon", filling.getVariant()); + } + + @Test + public void checkWrongFillingVariantTest() { + Filling filling = new Filling(SKU.FILH); + Assertions.assertNotEquals("Bacon", filling.getVariant()); + } +} diff --git a/src/test/java/com/booleanuk/extension/BagelTest.java b/src/test/java/com/booleanuk/extension/BagelTest.java new file mode 100644 index 000000000..4f5c240d7 --- /dev/null +++ b/src/test/java/com/booleanuk/extension/BagelTest.java @@ -0,0 +1,43 @@ +package com.booleanuk.extension; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +public class BagelTest { + + @Test + public void checkBagelPriceTest() { + Bagel bagel = new Bagel(SKU.BGLP); + Assertions.assertEquals(0.39F, bagel.getPrice()); + } + + @Test + public void checkWrongBagelPriceTest() { + Bagel bagel = new Bagel(SKU.BGLS); + Assertions.assertNotEquals(0.39F, bagel.getPrice()); + } + + @Test + public void checkBagelNameTest() { + Bagel bagel = new Bagel(SKU.BGLP); + Assertions.assertEquals("Bagel", bagel.getName()); + } + + @Test + public void checkWrongBagelNameTest() { + Bagel bagel = new Bagel(SKU.FILC); + Assertions.assertNotEquals("Bagel", bagel.getName()); + } + + @Test + public void checkBagelVariantTest() { + Bagel bagel = new Bagel(SKU.BGLP); + Assertions.assertEquals("Plain", bagel.getVariant()); + } + + @Test + public void checkWrongBagelVariantTest() { + Bagel bagel = new Bagel(SKU.BGLE); + Assertions.assertNotEquals("Plain", bagel.getVariant()); + } +} diff --git a/src/test/java/com/booleanuk/extension/BasketTest.java b/src/test/java/com/booleanuk/extension/BasketTest.java new file mode 100644 index 000000000..c183e2b7a --- /dev/null +++ b/src/test/java/com/booleanuk/extension/BasketTest.java @@ -0,0 +1,115 @@ +package com.booleanuk.extension; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +public class BasketTest { + + @Test + public void addBagelCorrectlyTest() { + Basket basket = new Basket(); + basket.addItem(SKU.BGLP); + Assertions.assertEquals(1, basket.items.size()); + Assertions.assertEquals(SKU.BGLP, basket.items.getFirst().SKU); + } + + @Test + public void addBagelCorrectlyTest2() { + Basket basket = new Basket(); + Assertions.assertTrue(basket.addItem(SKU.BGLP)); + } + + @Test + public void addBagelIncorrectlyTest() { + Basket basket = new Basket(); + basket.addItem(SKU.BGLP); + Assertions.assertEquals(1, basket.items.size()); + Assertions.assertNotEquals(SKU.BGLE, basket.items.getFirst().getSKU()); + } + + @Test + public void removeBagelCorrectlyTest() { + Basket basket = new Basket(); + basket.addItem(SKU.BGLP); + Assertions.assertEquals(1, basket.items.size()); + Assertions.assertTrue(basket.removeItem(SKU.BGLP)); + Assertions.assertEquals(0, basket.items.size()); + } + + @Test + public void removeBagelIncorrectlyTest() { + Basket basket = new Basket(); + basket.addItem(SKU.BGLP); + Assertions.assertFalse(basket.removeItem(SKU.BGLE)); + } + + @Test + public void changeCapacityCorrectlyTest() { + Basket basket = new Basket(); + basket.setCapacity(10); + Assertions.assertEquals(10, basket.getCapacity()); + } + + @Test + public void changeCapacityCorrectlyTest2() { + Basket basket = new Basket(); + Assertions.assertTrue(basket.setCapacity(10)); + } + + @Test + public void changeCapacityIncorrectlyTest() { + Basket basket = new Basket(); + Assertions.assertFalse(basket.setCapacity(-5)); + } + + @Test + public void changeCapacityIncorrectlyTest2() { + Basket basket = new Basket(); + basket.setCapacity(-20); + Assertions.assertNotEquals(-20, basket.getCapacity()); + } + + @Test + public void changeCapacityIncorrectlyTest3() { + Basket basket = new Basket(); + Bagel bagel1 = new Bagel(SKU.BGLP); + Bagel bagel2 = new Bagel(SKU.BGLO); + Coffee coffee = new Coffee(SKU.COFW); + basket.addItem(bagel1.SKU); + basket.addItem(bagel2.SKU); + basket.addItem(coffee.SKU); + float totalPrice = bagel1.getPrice() + bagel2.getPrice() + coffee.getPrice(); + Assertions.assertEquals(totalPrice, basket.calculateCost()); + } + + @Test + public void testetst() { + Basket basket = new Basket(); + basket.addItem(SKU.BGLO); + basket.addItem(SKU.BGLO); + basket.addItem(SKU.BGLO); + basket.addItem(SKU.BGLO); + basket.addItem(SKU.BGLO); + basket.addItem(SKU.BGLO); + basket.addItem(SKU.BGLO); + basket.addItem(SKU.BGLO); + basket.addItem(SKU.BGLO); + basket.addItem(SKU.BGLO); + basket.addItem(SKU.BGLO); + basket.addItem(SKU.BGLO); + basket.addItem(SKU.BGLO); + basket.addItem(SKU.BGLO); + basket.addItem(SKU.BGLO); + basket.addItem(SKU.BGLO); + basket.addItem(SKU.BGLO); + basket.addItem(SKU.BGLO); + basket.addItem(SKU.BGLO); + basket.addItem(SKU.BGLO); + basket.addItem(SKU.COFW); + basket.addItem(SKU.COFW); + basket.addItem(SKU.COFB); + basket.addItem(SKU.COFB); + basket.addItem(SKU.FILB); + System.out.println(basket.getReceipt()); + } +} diff --git a/src/test/java/com/booleanuk/extension/CoffeeTest.java b/src/test/java/com/booleanuk/extension/CoffeeTest.java new file mode 100644 index 000000000..7917653ec --- /dev/null +++ b/src/test/java/com/booleanuk/extension/CoffeeTest.java @@ -0,0 +1,42 @@ +package com.booleanuk.extension; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +public class CoffeeTest { + @Test + public void checkCoffeePriceTest() { + Coffee coffee = new Coffee(SKU.COFB); + Assertions.assertEquals(0.99F, coffee.getPrice()); + } + + @Test + public void checkWrongCoffeePriceTest() { + Coffee coffee = new Coffee(SKU.COFW); + Assertions.assertNotEquals(0.99F, coffee.getPrice()); + } + + @Test + public void checkCoffeeNameTest() { + Coffee coffee = new Coffee(SKU.COFB); + Assertions.assertEquals("Coffee", coffee.getName()); + } + + @Test + public void checkWrongCoffeeNameTest() { + Coffee coffee = new Coffee(SKU.COFB); + Assertions.assertNotEquals("Bagel", coffee.getName()); + } + + @Test + public void checkCoffeeVariantTest() { + Coffee coffee = new Coffee(SKU.COFW); + Assertions.assertEquals("White", coffee.getVariant()); + } + + @Test + public void checkWrongCoffeeVariantTest() { + Coffee coffee = new Coffee(SKU.COFW); + Assertions.assertNotEquals("Black", coffee.getVariant()); + } +} diff --git a/src/test/java/com/booleanuk/extension/FillingTest.java b/src/test/java/com/booleanuk/extension/FillingTest.java new file mode 100644 index 000000000..cf80ef7a4 --- /dev/null +++ b/src/test/java/com/booleanuk/extension/FillingTest.java @@ -0,0 +1,42 @@ +package com.booleanuk.extension; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +public class FillingTest { + @Test + public void checkFillingPriceTest() { + Filling filling = new Filling(SKU.FILB); + Assertions.assertEquals(0.12F, filling.getPrice()); + } + + @Test + public void checkWrongFillingPriceTest() { + Filling filling = new Filling(SKU.FILB); + Assertions.assertNotEquals(0.99F, filling.getPrice()); + } + + @Test + public void checkFillingNameTest() { + Filling filling = new Filling(SKU.FILB); + Assertions.assertEquals("Filling", filling.getName()); + } + + @Test + public void checkWrongFillingNameTest() { + Filling filling = new Filling(SKU.FILC); + Assertions.assertNotEquals("Bagel", filling.getName()); + } + + @Test + public void checkFillingVariantTest() { + Filling filling = new Filling(SKU.FILB); + Assertions.assertEquals("Bacon", filling.getVariant()); + } + + @Test + public void checkWrongFillingVariantTest() { + Filling filling = new Filling(SKU.FILH); + Assertions.assertNotEquals("Bacon", filling.getVariant()); + } +}