@Before public void setUp() throws Exception { try { FileReader reader = new FileReader("inventory.txt"); BufferedReader br = new BufferedReader(reader); String row = br.readLine(); while (row != null) { String articleinfo[] = row.split(":"); char barcode[] = articleinfo[0].toCharArray(); String name = articleinfo[1]; int amount = Integer.parseInt(articleinfo[2]); double price = Double.parseDouble(articleinfo[3]); boolean food = Boolean.parseBoolean(articleinfo[4]); tempInventory.add(new cashRegisterSystem.inventoryArticle(barcode, name, amount, price)); row = br.readLine(); } br.close(); } catch (IOException e) { System.out.println("Error" + e.getMessage()); System.out.println("Error reading File"); } CRS.newItem(Long.parseLong(sBarcode), sArticleName, dPrice, iAmountInventory, isFood); CRS.writeInventory(); }
@Test public void testRemoveFromPrice() throws Exception { double dEndPrice = 1.0593; // price * (amountBuy - amountRemove) * myCart.TAX_FOOD; int iAmountBuy = 2; int iAmountRemove = 1; CRS.addToPrice(myCart, sBarcode.toCharArray(), iAmountBuy); CRS.removeFromPrice(myCart, sBarcode.toCharArray(), iAmountRemove); assertEquals(dEndPrice, myCart.getdFullPrice(), 0.001); }
@Test public void testStatistic() throws Exception { double dEndEarning = 0.99; int iAmountBuy = 2; int iAmountRemove = 1; assertEquals(dEndEarning, CRS.statistic(), 0.001); }
@Test public void testAddToPrice() throws Exception { double dEndPrice = 2.1186; // price*amountBuy*myCart.TAX_FOOD; int iAmountBuy = 2; CRS.addToPrice(myCart, sBarcode.toCharArray(), iAmountBuy); assertEquals(dEndPrice, myCart.getdFullPrice(), 0.001); }