BasketCalculator { public float calculatePrice(List<String> books) { NormalizeBasket normalizeBasket = new NormalizeBasket(); normalizeBasket.addBooks(books); float amount = 0.0f; for (SetCollection collection : normalizeBasket.getCollections()) { int numBooks = collection.numBooks(); float discount = calculateDiscount(numBooks); amount += BOOK_PRICE * discount * numBooks; } return amount; }  float calculatePrice(List<String> books);  }
@Test public void shouldReturnZeroPriceForAnEmptyBasket() { BasketCalculator basketCalculator = new BasketCalculator(); float amount = basketCalculator.calculatePrice(EMPTY_BASKET); assertEquals(0, amount, DELTA_ZERO); }
@Test public void shouldReturnPriceWithoutDiscountWithABasketWithOneBook() { BasketCalculator basketCalculator = new BasketCalculator(); List<String> basket = givenBasketWithBooks(FIRST_BOOK); float amount = basketCalculator.calculatePrice(basket); assertEquals(8, amount, DELTA_ZERO); }
@Test public void shouldReturnPriceWithoutDiscountWithABasketWithTwoSameBooks() { BasketCalculator basketCalculator = new BasketCalculator(); List<String> basket = givenBasketWithBooks(FIRST_BOOK, FIRST_BOOK); float amount = basketCalculator.calculatePrice(basket); assertEquals(8 * 2, amount, DELTA_ZERO); }
@Test public void shouldReturnPriceWithDiscountWithABasketWithTwoDifferentBooks() { BasketCalculator basketCalculator = new BasketCalculator(); List<String> basket = givenBasketWithBooks(FIRST_BOOK, SECOND_BOOK); float amount = basketCalculator.calculatePrice(basket); assertEquals(8 * 2 * 0.95f, amount, DELTA_ZERO); }
@Test public void shouldReturnPriceWithDiscountWithABasketWithThreeBooksTwoDifferent() { BasketCalculator basketCalculator = new BasketCalculator(); List<String> basket = givenBasketWithBooks(FIRST_BOOK, FIRST_BOOK, SECOND_BOOK); float amount = basketCalculator.calculatePrice(basket); assertEquals((8 * 2 * 0.95f) + 8, amount, DELTA_ZERO); }
@Test public void shouldReturnPriceWithDiscountWithABasketWithThreeBooksAllDifferent() { BasketCalculator basketCalculator = new BasketCalculator(); List<String> basket = givenBasketWithBooks(FIRST_BOOK, SECOND_BOOK, THIRD_BOOK); float amount = basketCalculator.calculatePrice(basket); assertEquals(8 * 3 * 0.90f, amount, DELTA_ZERO); }
@Test public void shouldReturnPriceWithDiscountWithABasketWithFiveBooksThreeDifferents() { BasketCalculator basketCalculator = new BasketCalculator(); List<String> basket = givenBasketWithBooks(FIRST_BOOK, SECOND_BOOK, FIRST_BOOK, THIRD_BOOK, SECOND_BOOK); float amount = basketCalculator.calculatePrice(basket); assertEquals((8 * 3 * 0.90f) + (8 * 2 * 0.95f), amount, DELTA_ZERO); }
@Test public void shouldReturnPriceWithDiscountWithABasketWithSixBooksTwoDifferents() { BasketCalculator basketCalculator = new BasketCalculator(); List<String> basket = givenBasketWithBooks(FIRST_BOOK, SECOND_BOOK, FIRST_BOOK, SECOND_BOOK, SECOND_BOOK, FIRST_BOOK); float amount = basketCalculator.calculatePrice(basket); assertEquals((8 * 2 * 0.95f) + (8 * 2 * 0.95f) + (8 * 2 * 0.95f), amount, DELTA_ZERO); }