Cart { public double totalAmount() { double total = 0; for(Item item: items) { if (item.sku.startsWith("EACH")) { total += item.quantity * 5.0; } else if(item.sku.startsWith("WEIGHT")) { total += (item.quantity * 4.0) / 1000; } else if(item.sku.startsWith("SPECIAL")) { total += item.quantity * 0.4; int setsOfThree = item.quantity / 3; total -= setsOfThree * 0.2; } } return total; }  void addItem(Item item); double totalAmount();  }
@Test public void totalIsZeroWhenCartIsEmpty() { assertEquals(0, cart.totalAmount(), 0); }