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
-
7
1
import org .assertj .core .api .Assertions ;
8
2
import org .junit .Before ;
9
3
import org .junit .Ignore ;
10
4
import org .junit .Test ;
11
5
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
+
12
12
public class BookStoreTest {
13
13
14
14
// This is sufficient accuracy since we're handling currency values, which should be equal
@@ -26,118 +26,142 @@ public void setUp() {
26
26
public void onlyASingleBook () {
27
27
List <Integer > books = Collections .singletonList (1 );
28
28
assertThat (bookStore .calculateBasketCost (books ))
29
- .isCloseTo (8.00 , Assertions .offset (EQUALITY_TOLERANCE ));
29
+ .isCloseTo (8.00 , Assertions .offset (EQUALITY_TOLERANCE ));
30
30
}
31
31
32
32
@ Ignore ("Remove to run test" )
33
33
@ Test
34
34
public void twoOfSameBook () {
35
35
List <Integer > books = Arrays .asList (2 , 2 );
36
36
assertThat (bookStore .calculateBasketCost (books ))
37
- .isCloseTo (16.00 , Assertions .offset (EQUALITY_TOLERANCE ));
37
+ .isCloseTo (16.00 , Assertions .offset (EQUALITY_TOLERANCE ));
38
38
}
39
39
40
40
@ Ignore ("Remove to run test" )
41
41
@ Test
42
42
public void emptyBasket () {
43
43
List <Integer > books = Collections .emptyList ();
44
44
assertThat (bookStore .calculateBasketCost (books ))
45
- .isCloseTo (0.00 , Assertions .offset (EQUALITY_TOLERANCE ));
45
+ .isCloseTo (0.00 , Assertions .offset (EQUALITY_TOLERANCE ));
46
46
}
47
47
48
48
@ Ignore ("Remove to run test" )
49
49
@ Test
50
50
public void twoDifferentBooks () {
51
51
List <Integer > books = Arrays .asList (1 , 2 );
52
52
assertThat (bookStore .calculateBasketCost (books ))
53
- .isCloseTo (15.20 , Assertions .offset (EQUALITY_TOLERANCE ));
53
+ .isCloseTo (15.20 , Assertions .offset (EQUALITY_TOLERANCE ));
54
54
}
55
55
56
56
@ Ignore ("Remove to run test" )
57
57
@ Test
58
58
public void threeDifferentBooks () {
59
59
List <Integer > books = Arrays .asList (1 , 2 , 3 );
60
60
assertThat (bookStore .calculateBasketCost (books ))
61
- .isCloseTo (21.60 , Assertions .offset (EQUALITY_TOLERANCE ));
61
+ .isCloseTo (21.60 , Assertions .offset (EQUALITY_TOLERANCE ));
62
62
}
63
63
64
64
@ Ignore ("Remove to run test" )
65
65
@ Test
66
66
public void fourDifferentBooks () {
67
67
List <Integer > books = Arrays .asList (1 , 2 , 3 , 4 );
68
68
assertThat (bookStore .calculateBasketCost (books ))
69
- .isCloseTo (25.60 , Assertions .offset (EQUALITY_TOLERANCE ));
69
+ .isCloseTo (25.60 , Assertions .offset (EQUALITY_TOLERANCE ));
70
70
}
71
71
72
72
@ Ignore ("Remove to run test" )
73
73
@ Test
74
74
public void fiveDifferentBooks () {
75
75
List <Integer > books = Arrays .asList (1 , 2 , 3 , 4 , 5 );
76
76
assertThat (bookStore .calculateBasketCost (books ))
77
- .isCloseTo (30.00 , Assertions .offset (EQUALITY_TOLERANCE ));
77
+ .isCloseTo (30.00 , Assertions .offset (EQUALITY_TOLERANCE ));
78
78
}
79
79
80
80
@ Ignore ("Remove to run test" )
81
81
@ Test
82
82
public void twoGroupsOfFourIsCheaperThanGroupOfFivePlusGroupOfThree () {
83
83
List <Integer > books = Arrays .asList (1 , 1 , 2 , 2 , 3 , 3 , 4 , 5 );
84
84
assertThat (bookStore .calculateBasketCost (books ))
85
- .isCloseTo (51.20 , Assertions .offset (EQUALITY_TOLERANCE ));
85
+ .isCloseTo (51.20 , Assertions .offset (EQUALITY_TOLERANCE ));
86
86
}
87
87
88
88
@ Ignore ("Remove to run test" )
89
89
@ Test
90
90
public void twoGroupsOfFourIsCheaperThanGroupsOfFiveAndThree () {
91
91
List <Integer > books = Arrays .asList (1 , 1 , 2 , 3 , 4 , 4 , 5 , 5 );
92
92
assertThat (bookStore .calculateBasketCost (books ))
93
- .isCloseTo (51.20 , Assertions .offset (EQUALITY_TOLERANCE ));
93
+ .isCloseTo (51.20 , Assertions .offset (EQUALITY_TOLERANCE ));
94
94
}
95
95
96
96
@ Ignore ("Remove to run test" )
97
97
@ Test
98
98
public void groupOfFourPlusGroupOfTwoIsCheaperThanTwoGroupsOfThree () {
99
99
List <Integer > books = Arrays .asList (1 , 1 , 2 , 2 , 3 , 4 );
100
100
assertThat (bookStore .calculateBasketCost (books ))
101
- .isCloseTo (40.80 , Assertions .offset (EQUALITY_TOLERANCE ));
101
+ .isCloseTo (40.80 , Assertions .offset (EQUALITY_TOLERANCE ));
102
102
}
103
103
104
104
@ Ignore ("Remove to run test" )
105
105
@ Test
106
106
public void twoEachOfFirst4BooksAnd1CopyEachOfRest () {
107
107
List <Integer > books = Arrays .asList (1 , 1 , 2 , 2 , 3 , 3 , 4 , 4 , 5 );
108
108
assertThat (bookStore .calculateBasketCost (books ))
109
- .isCloseTo (55.60 , Assertions .offset (EQUALITY_TOLERANCE ));
109
+ .isCloseTo (55.60 , Assertions .offset (EQUALITY_TOLERANCE ));
110
110
}
111
111
112
112
@ Ignore ("Remove to run test" )
113
113
@ Test
114
114
public void twoCopiesOfEachBook () {
115
115
List <Integer > books = Arrays .asList (1 , 1 , 2 , 2 , 3 , 3 , 4 , 4 , 5 , 5 );
116
116
assertThat (bookStore .calculateBasketCost (books ))
117
- .isCloseTo (60.00 , Assertions .offset (EQUALITY_TOLERANCE ));
117
+ .isCloseTo (60.00 , Assertions .offset (EQUALITY_TOLERANCE ));
118
118
}
119
119
120
120
@ Ignore ("Remove to run test" )
121
121
@ Test
122
122
public void threeCopiesOfFirstBookAnd2EachOfRemaining () {
123
123
List <Integer > books = Arrays .asList (1 , 1 , 2 , 2 , 3 , 3 , 4 , 4 , 5 , 5 , 1 );
124
124
assertThat (bookStore .calculateBasketCost (books ))
125
- .isCloseTo (68.00 , Assertions .offset (EQUALITY_TOLERANCE ));
125
+ .isCloseTo (68.00 , Assertions .offset (EQUALITY_TOLERANCE ));
126
126
}
127
127
128
128
@ Ignore ("Remove to run test" )
129
129
@ Test
130
130
public void threeEachOFirst2BooksAnd2EachOfRemainingBooks () {
131
131
List <Integer > books = Arrays .asList (1 , 1 , 2 , 2 , 3 , 3 , 4 , 4 , 5 , 5 , 1 , 2 );
132
132
assertThat (bookStore .calculateBasketCost (books ))
133
- .isCloseTo (75.20 , Assertions .offset (EQUALITY_TOLERANCE ));
133
+ .isCloseTo (75.20 , Assertions .offset (EQUALITY_TOLERANCE ));
134
134
}
135
135
136
136
@ Ignore ("Remove to run test" )
137
137
@ Test
138
138
public void fourGroupsOfFourAreCheaperThanTwoGroupsEachOfFiveAndThree () {
139
139
List <Integer > books = Arrays .asList (1 , 1 , 2 , 2 , 3 , 3 , 4 , 5 , 1 , 1 , 2 , 2 , 3 , 3 , 4 , 5 );
140
140
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 ));
142
166
}
143
167
}
0 commit comments