Skip to content

Commit

Permalink
Merge pull request #95 from trz-maier/Ram
Browse files Browse the repository at this point in the history
Added bill class test issue #92. Fixed bug issue #93.
  • Loading branch information
trz-maier authored Feb 21, 2019
2 parents f135812 + a4cde7d commit 689154e
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 27 deletions.
2 changes: 1 addition & 1 deletion res/Items.csv
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 0 additions & 1 deletion src/ase/cw/model/Bill.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ else if (temp.getItem().getCategory() == categoryBeverage) {
discount += (ot.getItem().getPrice());
break;
}
break;
}
break;
}
Expand Down
84 changes: 59 additions & 25 deletions test/TestBill.java
Original file line number Diff line number Diff line change
@@ -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);

}

Expand Down

0 comments on commit 689154e

Please sign in to comment.