From 744abbc4f548ac363b53cf2d436ed467c8837f34 Mon Sep 17 00:00:00 2001 From: Ram Narayan Nanduri <39412981+ramnnanduri@users.noreply.github.com> Date: Thu, 21 Feb 2019 21:07:12 +0000 Subject: [PATCH 1/2] fixed bug issue #93 --- src/ase/cw/model/Bill.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/ase/cw/model/Bill.java b/src/ase/cw/model/Bill.java index f5eb4ee..caf22cc 100644 --- a/src/ase/cw/model/Bill.java +++ b/src/ase/cw/model/Bill.java @@ -84,7 +84,6 @@ else if (temp.getItem().getCategory() == categoryBeverage) { discount += (ot.getItem().getPrice()); break; } - break; } break; } From a4cde7d7b9c0e090fac098df5442bb845d259727 Mon Sep 17 00:00:00 2001 From: Ram Narayan Nanduri <39412981+ramnnanduri@users.noreply.github.com> Date: Thu, 21 Feb 2019 22:59:46 +0000 Subject: [PATCH 2/2] Added Bill class test issue #92 Fixed bug issue #93 --- res/Items.csv | 2 +- test/TestBill.java | 84 ++++++++++++++++++++++++++++++++-------------- 2 files changed, 60 insertions(+), 26 deletions(-) diff --git a/res/Items.csv b/res/Items.csv index 5ac3a95..c82cb23 100644 --- a/res/Items.csv +++ b/res/Items.csv @@ -1,4 +1,4 @@ -cdd15ee5-a560-4aa2-be61-fe5ec82ab3b0,Apple,FOOD,5.50 +cdd15ee5-a560-4aa2-be61-fe5ec82ab3b0,Apple,FOOD,0.50 cdd15ee0-a560-4aa2-be61-fe5ec82ab3b0,Cheese Sandwich,FOOD,2.49 24220701-917a-462c-9f92-2abce1b95d44,Orange Juice,FOOD,1.09 000b1c12-4606-4728-be39-a2ecb256a698,Oregano Crisps,FOOD,1.29 diff --git a/test/TestBill.java b/test/TestBill.java index fbd38c5..8d2bcf8 100644 --- a/test/TestBill.java +++ b/test/TestBill.java @@ -1,58 +1,92 @@ import ase.cw.model.Item; import ase.cw.model.Order; -import org.junit.After; -import org.junit.Before; +import org.junit.BeforeClass; import org.junit.Test; import java.util.UUID; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; public class TestBill { - private static Order order; + private static Order order1; + private static Order order2; + private static Order order3; - @Before - public void setUp() throws Exception { - order = new Order("00000000"); + @BeforeClass + public static void setUp() throws Exception { - Item item1 = new Item(UUID.fromString("cdd15ee5-a560-4aa2-be61-fe5ec82ab3b0"), Item.Category.FOOD, "Sandwich", (float) 1); - Item item2 = new Item(UUID.fromString("cdd15ee5-a560-4aa2-be61-fe5ec82ab3b0"), Item.Category.FOOD, "Salad", (float) 2); - Item item3 = new Item(UUID.fromString("cdd15ee5-a560-4aa2-be61-fe5ec82ab3b0"), Item.Category.FOOD, "Pie", (float) 3); - Item item4 = new Item(UUID.fromString("cdd15ee5-a560-4aa2-be61-fe5ec82ab3b0"), Item.Category.BEVERAGE, "Coffee", (float) 4); - Item item5 = new Item(UUID.fromString("cdd15ee5-a560-4aa2-be61-fe5ec82ab3b0"), Item.Category.BEVERAGE, "Coffee", (float) 4); - Item item6 = new Item(UUID.fromString("cdd15ee5-a560-4aa2-be61-fe5ec82ab3b0"), Item.Category.OTHER, "Newspaper", (float) 5); + order1 = new Order("00000000"); + order2 = new Order("00000001"); + order3 = new Order("00000002"); + + Item item1 = new Item(UUID.fromString("cdd15ee5-a560-4aa2-be61-fe5ec82ab3b1"), Item.Category.FOOD, "Jam Doughnut", (float) 1.40); + Item item2 = new Item(UUID.fromString("cdd15ee5-a560-4aa2-be61-fe5ec82ab3b2"), Item.Category.FOOD, "Cheese Sandwich", (float) 2.50); + Item item3 = new Item(UUID.fromString("cdd15ee5-a560-4aa2-be61-fe5ec82ab3b3"), Item.Category.FOOD, "Cherry Pie", (float) 3.10); + Item item4 = new Item(UUID.fromString("cdd15ee5-a560-4aa2-be61-fe5ec82ab3b4"), Item.Category.BEVERAGE, "Coffee", (float) 4); + Item item5 = new Item(UUID.fromString("cdd15ee5-a560-4aa2-be61-fe5ec82ab3b5"), Item.Category.BEVERAGE, "Water", (float) 2); + Item item6 = new Item(UUID.fromString("cdd15ee5-a560-4aa2-be61-fe5ec82ab3b6"), Item.Category.OTHER, "Newspaper", (float) 1); + + order1.addOrderItem(item1); + order1.addOrderItem(item1); + order1.addOrderItem(item1); + order1.addOrderItem(item4); + order1.addOrderItem(item6); + + order2.addOrderItem(item1); + order2.addOrderItem(item4); + order2.addOrderItem(item4); + order2.addOrderItem(item6); + + order3.addOrderItem(item4); + order3.addOrderItem(item6); + order3.addOrderItem(item6); + order3.addOrderItem(item1); + order3.addOrderItem(item1); + order3.addOrderItem(item5); - order.addOrderItem(item1); - order.addOrderItem(item2); - order.addOrderItem(item3); - order.addOrderItem(item4); - order.addOrderItem(item5); - order.addOrderItem(item6); } @Test public void getSubtotalSuccess() { - double expected_value = 15; - assertEquals(expected_value, order.getBill().getSubtotal(), 0); + double expected_value1 = 9.2; + assertEquals(expected_value1, order1.getBill().getSubtotal(), 0.01); + + double expected_value2 = 10.39; + assertEquals(expected_value2, order2.getBill().getSubtotal(), 0.01); + + double expected_value3 = 10.80; + assertEquals(expected_value3, order3.getBill().getSubtotal(), 0.01); } @Test public void getDiscountSuccess() { - double expected_value = 15; - assertEquals(expected_value, order.getBill().getDiscount(), 0); + double expected_value1 = 3.48; + assertEquals(expected_value1, order1.getBill().getDiscount(), 0.01); + + double expected_value2 = 2.08; + assertEquals(expected_value2, order2.getBill().getDiscount(), 0.01); + + double expected_value3 = 2.76; + assertEquals(expected_value3, order3.getBill().getDiscount(), 0.01); } @Test public void getTotalSuccess() { - double expected_value = 15; - assertEquals(expected_value, order.getBill().getTotal(), 0); + double expected_value1 = 5.72; + assertEquals(expected_value1, order1.getBill().getTotal(), 0.01); + + double expected_value2 = 8.32; + assertEquals(expected_value2, order2.getBill().getTotal(), 0.01); + + double expected_value3 = 8.04; + assertEquals(expected_value3, order3.getBill().getTotal(), 0.01); }