1
exercism fetch java book-store

src/test/java/BookStoreTest.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import static org.junit.Assert.assertEquals;

import java.util.Collections;
import java.util.List;
import java.util.Arrays;

import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;

public class BookStoreTest {

  // This is sufficient accuracy since we're handling currency values, which should be equal to within 2 decimal places.
  private static final double EQUALITY_TOLERANCE = 0.001;

  private BookStore bookStore;

  @Before
  public void setUp() {
    bookStore = new BookStore();
  }

  @Test
  public void onlyASingleBook() {
    List<Integer> books = Collections.singletonList(1);
    assertEquals(8, bookStore.calculateBasketCost(books), EQUALITY_TOLERANCE);
  }

  @Ignore("Remove to run test")
  @Test
  public void twoOfSameBook() {
    List<Integer> books = Arrays.asList(1, 1);
    assertEquals(16, bookStore.calculateBasketCost(books), EQUALITY_TOLERANCE);
  }

  @Ignore("Remove to run test")
  @Test
  public void emptyBasket() {
    List<Integer> books = Collections.emptyList();
    assertEquals(0, bookStore.calculateBasketCost(books), EQUALITY_TOLERANCE);
  }

  @Ignore("Remove to run test")
  @Test
  public void twoDifferentBooks() {
    List<Integer> books = Arrays.asList(1, 2);
    assertEquals(15.20, bookStore.calculateBasketCost(books), EQUALITY_TOLERANCE);
  }

  @Ignore("Remove to run test")
  @Test
  public void threeDifferentBooks() {
    List<Integer> books = Arrays.asList(1, 2, 3);
    assertEquals(21.6, bookStore.calculateBasketCost(books), EQUALITY_TOLERANCE);
  }

  @Ignore("Remove to run test")
  @Test
  public void fourDifferentBooks() {
    List<Integer> books = Arrays.asList(1, 2, 3, 4);
    assertEquals(25.6, bookStore.calculateBasketCost(books), EQUALITY_TOLERANCE);
  }

  @Ignore("Remove to run test")
  @Test
  public void fiveDifferentBooks() {
    List<Integer> books = Arrays.asList(1, 2, 3, 4, 5);
    assertEquals(30, bookStore.calculateBasketCost(books), EQUALITY_TOLERANCE);
  }

  @Ignore("Remove to run test")
  @Test
  public void twoGroupsOfFourIsCheaperThanGroupOfFivePlusGroupOfThree() {
    List<Integer> books = Arrays.asList(1, 1, 2, 2, 3, 3, 4, 5);
    assertEquals(51.20, bookStore.calculateBasketCost(books), EQUALITY_TOLERANCE);
  }

  @Ignore("Remove to run test")
  @Test
  public void groupOfFourPlusGroupOfTwoIsCheaperThanTwoGroupsOfThree() {
    List<Integer> books = Arrays.asList(1, 1, 2, 2, 3, 4);
    assertEquals(40.8, bookStore.calculateBasketCost(books), EQUALITY_TOLERANCE);
  }

  @Ignore("Remove to run test")
  @Test
  public void twoEachOfFirst4BooksAnd1CopyEachOfRest() {
    List<Integer> books = Arrays.asList(1, 1, 2, 2, 3, 3, 4, 4, 5);
    assertEquals(55.60, bookStore.calculateBasketCost(books), EQUALITY_TOLERANCE);
  }

  @Ignore("Remove to run test")
  @Test
  public void twoCopiesOfEachBook() {
    List<Integer> books = Arrays.asList(1, 1, 2, 2, 3, 3, 4, 4, 5, 5);
    assertEquals(60.00, bookStore.calculateBasketCost(books), EQUALITY_TOLERANCE);
  }

  @Ignore("Remove to run test")
  @Test
  public void threeCopiesOfFirstBookAnd2EachOfRemaining() {
    List<Integer> books = Arrays.asList(1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 1);
    assertEquals(68.00, bookStore.calculateBasketCost(books), EQUALITY_TOLERANCE);
  }

  @Ignore("Remove to run test")
  @Test
  public void threeEachOFirst2BooksAnd2EachOfRemainingBooks() {
    List<Integer> books = Arrays.asList(1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 1, 2);
    assertEquals(75.20, bookStore.calculateBasketCost(books), EQUALITY_TOLERANCE);
  }

}