1- import static org .assertj .core .api .Assertions .assertThat ;
2-
3- import java .util .Collections ;
4- import java .util .List ;
5- import java .util .Arrays ;
6-
71import org .assertj .core .api .Assertions ;
82import org .junit .Before ;
93import org .junit .Ignore ;
104import org .junit .Test ;
115
6+ import java .util .Arrays ;
7+ import java .util .Collections ;
8+ import java .util .List ;
9+
10+ import static org .assertj .core .api .Assertions .assertThat ;
11+
1212public class BookStoreTest {
1313
1414 // This is sufficient accuracy since we're handling currency values, which should be equal
@@ -26,118 +26,142 @@ public void setUp() {
2626 public void onlyASingleBook () {
2727 List <Integer > books = Collections .singletonList (1 );
2828 assertThat (bookStore .calculateBasketCost (books ))
29- .isCloseTo (8.00 , Assertions .offset (EQUALITY_TOLERANCE ));
29+ .isCloseTo (8.00 , Assertions .offset (EQUALITY_TOLERANCE ));
3030 }
3131
3232 @ Ignore ("Remove to run test" )
3333 @ Test
3434 public void twoOfSameBook () {
3535 List <Integer > books = Arrays .asList (2 , 2 );
3636 assertThat (bookStore .calculateBasketCost (books ))
37- .isCloseTo (16.00 , Assertions .offset (EQUALITY_TOLERANCE ));
37+ .isCloseTo (16.00 , Assertions .offset (EQUALITY_TOLERANCE ));
3838 }
3939
4040 @ Ignore ("Remove to run test" )
4141 @ Test
4242 public void emptyBasket () {
4343 List <Integer > books = Collections .emptyList ();
4444 assertThat (bookStore .calculateBasketCost (books ))
45- .isCloseTo (0.00 , Assertions .offset (EQUALITY_TOLERANCE ));
45+ .isCloseTo (0.00 , Assertions .offset (EQUALITY_TOLERANCE ));
4646 }
4747
4848 @ Ignore ("Remove to run test" )
4949 @ Test
5050 public void twoDifferentBooks () {
5151 List <Integer > books = Arrays .asList (1 , 2 );
5252 assertThat (bookStore .calculateBasketCost (books ))
53- .isCloseTo (15.20 , Assertions .offset (EQUALITY_TOLERANCE ));
53+ .isCloseTo (15.20 , Assertions .offset (EQUALITY_TOLERANCE ));
5454 }
5555
5656 @ Ignore ("Remove to run test" )
5757 @ Test
5858 public void threeDifferentBooks () {
5959 List <Integer > books = Arrays .asList (1 , 2 , 3 );
6060 assertThat (bookStore .calculateBasketCost (books ))
61- .isCloseTo (21.60 , Assertions .offset (EQUALITY_TOLERANCE ));
61+ .isCloseTo (21.60 , Assertions .offset (EQUALITY_TOLERANCE ));
6262 }
6363
6464 @ Ignore ("Remove to run test" )
6565 @ Test
6666 public void fourDifferentBooks () {
6767 List <Integer > books = Arrays .asList (1 , 2 , 3 , 4 );
6868 assertThat (bookStore .calculateBasketCost (books ))
69- .isCloseTo (25.60 , Assertions .offset (EQUALITY_TOLERANCE ));
69+ .isCloseTo (25.60 , Assertions .offset (EQUALITY_TOLERANCE ));
7070 }
7171
7272 @ Ignore ("Remove to run test" )
7373 @ Test
7474 public void fiveDifferentBooks () {
7575 List <Integer > books = Arrays .asList (1 , 2 , 3 , 4 , 5 );
7676 assertThat (bookStore .calculateBasketCost (books ))
77- .isCloseTo (30.00 , Assertions .offset (EQUALITY_TOLERANCE ));
77+ .isCloseTo (30.00 , Assertions .offset (EQUALITY_TOLERANCE ));
7878 }
7979
8080 @ Ignore ("Remove to run test" )
8181 @ Test
8282 public void twoGroupsOfFourIsCheaperThanGroupOfFivePlusGroupOfThree () {
8383 List <Integer > books = Arrays .asList (1 , 1 , 2 , 2 , 3 , 3 , 4 , 5 );
8484 assertThat (bookStore .calculateBasketCost (books ))
85- .isCloseTo (51.20 , Assertions .offset (EQUALITY_TOLERANCE ));
85+ .isCloseTo (51.20 , Assertions .offset (EQUALITY_TOLERANCE ));
8686 }
8787
8888 @ Ignore ("Remove to run test" )
8989 @ Test
9090 public void twoGroupsOfFourIsCheaperThanGroupsOfFiveAndThree () {
9191 List <Integer > books = Arrays .asList (1 , 1 , 2 , 3 , 4 , 4 , 5 , 5 );
9292 assertThat (bookStore .calculateBasketCost (books ))
93- .isCloseTo (51.20 , Assertions .offset (EQUALITY_TOLERANCE ));
93+ .isCloseTo (51.20 , Assertions .offset (EQUALITY_TOLERANCE ));
9494 }
9595
9696 @ Ignore ("Remove to run test" )
9797 @ Test
9898 public void groupOfFourPlusGroupOfTwoIsCheaperThanTwoGroupsOfThree () {
9999 List <Integer > books = Arrays .asList (1 , 1 , 2 , 2 , 3 , 4 );
100100 assertThat (bookStore .calculateBasketCost (books ))
101- .isCloseTo (40.80 , Assertions .offset (EQUALITY_TOLERANCE ));
101+ .isCloseTo (40.80 , Assertions .offset (EQUALITY_TOLERANCE ));
102102 }
103103
104104 @ Ignore ("Remove to run test" )
105105 @ Test
106106 public void twoEachOfFirst4BooksAnd1CopyEachOfRest () {
107107 List <Integer > books = Arrays .asList (1 , 1 , 2 , 2 , 3 , 3 , 4 , 4 , 5 );
108108 assertThat (bookStore .calculateBasketCost (books ))
109- .isCloseTo (55.60 , Assertions .offset (EQUALITY_TOLERANCE ));
109+ .isCloseTo (55.60 , Assertions .offset (EQUALITY_TOLERANCE ));
110110 }
111111
112112 @ Ignore ("Remove to run test" )
113113 @ Test
114114 public void twoCopiesOfEachBook () {
115115 List <Integer > books = Arrays .asList (1 , 1 , 2 , 2 , 3 , 3 , 4 , 4 , 5 , 5 );
116116 assertThat (bookStore .calculateBasketCost (books ))
117- .isCloseTo (60.00 , Assertions .offset (EQUALITY_TOLERANCE ));
117+ .isCloseTo (60.00 , Assertions .offset (EQUALITY_TOLERANCE ));
118118 }
119119
120120 @ Ignore ("Remove to run test" )
121121 @ Test
122122 public void threeCopiesOfFirstBookAnd2EachOfRemaining () {
123123 List <Integer > books = Arrays .asList (1 , 1 , 2 , 2 , 3 , 3 , 4 , 4 , 5 , 5 , 1 );
124124 assertThat (bookStore .calculateBasketCost (books ))
125- .isCloseTo (68.00 , Assertions .offset (EQUALITY_TOLERANCE ));
125+ .isCloseTo (68.00 , Assertions .offset (EQUALITY_TOLERANCE ));
126126 }
127127
128128 @ Ignore ("Remove to run test" )
129129 @ Test
130130 public void threeEachOFirst2BooksAnd2EachOfRemainingBooks () {
131131 List <Integer > books = Arrays .asList (1 , 1 , 2 , 2 , 3 , 3 , 4 , 4 , 5 , 5 , 1 , 2 );
132132 assertThat (bookStore .calculateBasketCost (books ))
133- .isCloseTo (75.20 , Assertions .offset (EQUALITY_TOLERANCE ));
133+ .isCloseTo (75.20 , Assertions .offset (EQUALITY_TOLERANCE ));
134134 }
135135
136136 @ Ignore ("Remove to run test" )
137137 @ Test
138138 public void fourGroupsOfFourAreCheaperThanTwoGroupsEachOfFiveAndThree () {
139139 List <Integer > books = Arrays .asList (1 , 1 , 2 , 2 , 3 , 3 , 4 , 5 , 1 , 1 , 2 , 2 , 3 , 3 , 4 , 5 );
140140 assertThat (bookStore .calculateBasketCost (books ))
141- .isCloseTo (102.4 , Assertions .offset (EQUALITY_TOLERANCE ));
141+ .isCloseTo (102.4 , Assertions .offset (EQUALITY_TOLERANCE ));
142+ }
143+
144+ @ Ignore ("Remove to run test" )
145+ @ Test
146+ public void groupsOfFourAreCreatedEvenWhenThereAreMoreGroupsOfThreeThanGroupsOfFive () {
147+ List <Integer > books = Arrays .asList (1 , 1 , 1 , 1 , 1 , 1 , 2 , 2 , 2 , 2 , 2 , 2 , 3 , 3 , 3 , 3 , 3 , 3 , 4 , 4 , 5 , 5 );
148+ assertThat (bookStore .calculateBasketCost (books ))
149+ .isCloseTo (145.6 , Assertions .offset (EQUALITY_TOLERANCE ));
150+ }
151+
152+ @ Ignore ("Remove to run test" )
153+ @ Test
154+ public void oneGroupOfOneAndFourIsCheaperThanOneGroupOfTwoAndThree () {
155+ List <Integer > books = Arrays .asList (1 , 1 , 2 , 3 , 4 );
156+ assertThat (bookStore .calculateBasketCost (books ))
157+ .isCloseTo (33.6 , Assertions .offset (EQUALITY_TOLERANCE ));
158+ }
159+
160+ @ Ignore ("Remove to run test" )
161+ @ Test
162+ public void oneGroupOfOneAndTwoPlusThreeGroupsOfFourIsCheaperThanOneGroupOfEachSize () {
163+ List <Integer > books = Arrays .asList (1 , 2 , 2 , 3 , 3 , 3 , 4 , 4 , 4 , 4 , 5 , 5 , 5 , 5 , 5 );
164+ assertThat (bookStore .calculateBasketCost (books ))
165+ .isCloseTo (100.0 , Assertions .offset (EQUALITY_TOLERANCE ));
142166 }
143167}
0 commit comments