|
|
@@ -1,5 +1,6 @@
|
|
1
|
1
|
import static org.junit.Assert.assertEquals;
|
|
2
|
2
|
|
|
|
3
|
+import java.util.Collections;
|
|
3
|
4
|
import java.util.List;
|
|
4
|
5
|
import java.util.ArrayList;
|
|
5
|
6
|
import java.util.Arrays;
|
|
|
@@ -7,112 +8,112 @@ import java.util.Arrays;
|
|
7
|
8
|
import org.junit.Ignore;
|
|
8
|
9
|
import org.junit.Test;
|
|
9
|
10
|
|
|
10
|
|
-public class BookstoreTest{
|
|
11
|
|
-
|
|
12
|
|
- @Test
|
|
13
|
|
- public void onlyASingleBook(){
|
|
14
|
|
- List<Integer> books = new ArrayList<>(Arrays.asList(1));
|
|
15
|
|
- Bookstore bookstore = new Bookstore(books);
|
|
16
|
|
- assertEquals(8,bookstore.calculateTotalCost(),2);
|
|
17
|
|
- }
|
|
18
|
|
-
|
|
19
|
|
- @Ignore
|
|
20
|
|
- @Test
|
|
21
|
|
- public void twoOfSameBook(){
|
|
22
|
|
- List<Integer> books = new ArrayList<>(Arrays.asList(1,1));
|
|
23
|
|
- Bookstore bookstore = new Bookstore(books);
|
|
24
|
|
- assertEquals(16,bookstore.calculateTotalCost(),2);
|
|
25
|
|
- }
|
|
26
|
|
-
|
|
27
|
|
- @Ignore
|
|
28
|
|
- @Test
|
|
29
|
|
- public void emptyBasket(){
|
|
30
|
|
- List<Integer> books = new ArrayList<>();
|
|
31
|
|
- Bookstore bookstore = new Bookstore(books);
|
|
32
|
|
- assertEquals(0,bookstore.calculateTotalCost(),2);
|
|
33
|
|
- }
|
|
34
|
|
-
|
|
35
|
|
- @Ignore
|
|
36
|
|
- @Test
|
|
37
|
|
- public void twoDifferentBooks(){
|
|
38
|
|
- List<Integer> books = new ArrayList<>(Arrays.asList(1,2));
|
|
39
|
|
- Bookstore bookstore = new Bookstore(books);
|
|
40
|
|
- assertEquals(15.20,bookstore.calculateTotalCost(),2);
|
|
41
|
|
- }
|
|
42
|
|
-
|
|
43
|
|
- @Ignore
|
|
44
|
|
- @Test
|
|
45
|
|
- public void threeDifferentBooks(){
|
|
46
|
|
- List<Integer> books = new ArrayList<>(Arrays.asList(1,2,3));
|
|
47
|
|
- Bookstore bookstore = new Bookstore(books);
|
|
48
|
|
- assertEquals(21.6,bookstore.calculateTotalCost(),2);
|
|
49
|
|
- }
|
|
50
|
|
-
|
|
51
|
|
- @Ignore
|
|
52
|
|
- @Test
|
|
53
|
|
- public void fourDifferentBooks(){
|
|
54
|
|
- ArrayList<Integer> books = new ArrayList<>(Arrays.asList(1,2,3,4));
|
|
55
|
|
- Bookstore bookstore = new Bookstore(books);
|
|
56
|
|
- assertEquals(25.6,bookstore.calculateTotalCost(),2);
|
|
57
|
|
-
|
|
58
|
|
- }
|
|
59
|
|
-
|
|
60
|
|
- @Ignore
|
|
61
|
|
- @Test
|
|
62
|
|
- public void fiveDifferentBooks(){
|
|
63
|
|
- ArrayList<Integer> books = new ArrayList<>(Arrays.asList(1,2,3,4,5));
|
|
64
|
|
- Bookstore bookstore = new Bookstore(books);
|
|
65
|
|
- assertEquals(30,bookstore.calculateTotalCost(),2);
|
|
66
|
|
- }
|
|
67
|
|
-
|
|
68
|
|
- @Ignore
|
|
69
|
|
- @Test
|
|
70
|
|
- public void twoGroupsOfFourIsCheaperThanGroupOfFivePlusGroupOfThree(){
|
|
71
|
|
- List<Integer> books = new ArrayList<>(Arrays.asList(1,1,2,2,3,3,4,5));
|
|
72
|
|
- Bookstore bookstore = new Bookstore(books);
|
|
73
|
|
- assertEquals(51.20,bookstore.calculateTotalCost(),2);
|
|
74
|
|
- }
|
|
75
|
|
-
|
|
76
|
|
- @Ignore
|
|
77
|
|
- @Test
|
|
78
|
|
- public void groupOfFourPlusGroupOfTwoIsCheaperThanTwoGroupsOfThree(){
|
|
79
|
|
- List<Integer> books = new ArrayList<>(Arrays.asList(1,1,2,2,3,4));
|
|
80
|
|
- Bookstore bookstore = new Bookstore(books);
|
|
81
|
|
- assertEquals(40.8,bookstore.calculateTotalCost(),2);
|
|
82
|
|
- }
|
|
83
|
|
-
|
|
84
|
|
- @Ignore
|
|
85
|
|
- @Test
|
|
86
|
|
- public void twoEachOfFirst4BooksAnd1CopyEachOfRest(){
|
|
87
|
|
- Integer[] p = {1,1,2,2,3,3,4,4,5};
|
|
88
|
|
- List<Integer> books = new ArrayList<>(Arrays.asList(1,1,2,2,3,3,4,4,5));
|
|
89
|
|
- Bookstore bookstore = new Bookstore(books);
|
|
90
|
|
- assertEquals(55.60,bookstore.calculateTotalCost(),2);
|
|
91
|
|
- }
|
|
92
|
|
-
|
|
93
|
|
- @Ignore
|
|
94
|
|
- @Test
|
|
95
|
|
- public void twoCopiesOfEachBook(){
|
|
96
|
|
- List<Integer> books = new ArrayList<>(Arrays.asList(1,1,2,2,3,3,4,4,5,5));
|
|
97
|
|
- Bookstore bookstore = new Bookstore(books);
|
|
98
|
|
- assertEquals(60.00,bookstore.calculateTotalCost(),2);
|
|
99
|
|
- }
|
|
100
|
|
-
|
|
101
|
|
- @Ignore
|
|
102
|
|
- @Test
|
|
103
|
|
- public void threeCopiesOfFirstBookAnd2EachOfRemaining(){
|
|
104
|
|
- List<Integer> books = new ArrayList<>(Arrays.asList(1,1,2,2,3,3,4,4,5,5,1));
|
|
105
|
|
- Bookstore bookstore = new Bookstore(books);
|
|
106
|
|
- assertEquals(68.00,bookstore.calculateTotalCost(),2);
|
|
107
|
|
- }
|
|
108
|
|
-
|
|
109
|
|
- @Ignore
|
|
110
|
|
- @Test
|
|
111
|
|
- public void threeEachOFirst2BooksAnd2EachOfRemainingBooks(){
|
|
112
|
|
- List<Integer> books = new ArrayList<>(Arrays.asList(1,1,2,2,3,3,4,4,5,5,1,2));
|
|
113
|
|
- Bookstore bookstore = new Bookstore(books);
|
|
114
|
|
- assertEquals(75.20,bookstore.calculateTotalCost(),2);
|
|
115
|
|
- }
|
|
|
11
|
+public class BookstoreTest {
|
|
|
12
|
+
|
|
|
13
|
+ // This is sufficient accuracy since we're handling currency values, which should be equal to within 2 decimal places.
|
|
|
14
|
+ private static final double EQUALITY_TOLERANCE = 0.001;
|
|
|
15
|
+
|
|
|
16
|
+ @Test
|
|
|
17
|
+ public void onlyASingleBook() {
|
|
|
18
|
+ List<Integer> books = new ArrayList<>(Collections.singletonList(1));
|
|
|
19
|
+ Bookstore bookstore = new Bookstore(books);
|
|
|
20
|
+ assertEquals(8, bookstore.calculateTotalCost(), EQUALITY_TOLERANCE);
|
|
|
21
|
+ }
|
|
|
22
|
+
|
|
|
23
|
+ @Ignore
|
|
|
24
|
+ @Test
|
|
|
25
|
+ public void twoOfSameBook() {
|
|
|
26
|
+ List<Integer> books = new ArrayList<>(Arrays.asList(1, 1));
|
|
|
27
|
+ Bookstore bookstore = new Bookstore(books);
|
|
|
28
|
+ assertEquals(16, bookstore.calculateTotalCost(), EQUALITY_TOLERANCE);
|
|
|
29
|
+ }
|
|
|
30
|
+
|
|
|
31
|
+ @Ignore
|
|
|
32
|
+ @Test
|
|
|
33
|
+ public void emptyBasket() {
|
|
|
34
|
+ List<Integer> books = new ArrayList<>();
|
|
|
35
|
+ Bookstore bookstore = new Bookstore(books);
|
|
|
36
|
+ assertEquals(0, bookstore.calculateTotalCost(), EQUALITY_TOLERANCE);
|
|
|
37
|
+ }
|
|
|
38
|
+
|
|
|
39
|
+ @Ignore
|
|
|
40
|
+ @Test
|
|
|
41
|
+ public void twoDifferentBooks() {
|
|
|
42
|
+ List<Integer> books = new ArrayList<>(Arrays.asList(1, 2));
|
|
|
43
|
+ Bookstore bookstore = new Bookstore(books);
|
|
|
44
|
+ assertEquals(15.20, bookstore.calculateTotalCost(), EQUALITY_TOLERANCE);
|
|
|
45
|
+ }
|
|
|
46
|
+
|
|
|
47
|
+ @Ignore
|
|
|
48
|
+ @Test
|
|
|
49
|
+ public void threeDifferentBooks() {
|
|
|
50
|
+ List<Integer> books = new ArrayList<>(Arrays.asList(1, 2, 3));
|
|
|
51
|
+ Bookstore bookstore = new Bookstore(books);
|
|
|
52
|
+ assertEquals(21.6, bookstore.calculateTotalCost(), EQUALITY_TOLERANCE);
|
|
|
53
|
+ }
|
|
|
54
|
+
|
|
|
55
|
+ @Ignore
|
|
|
56
|
+ @Test
|
|
|
57
|
+ public void fourDifferentBooks() {
|
|
|
58
|
+ List<Integer> books = new ArrayList<>(Arrays.asList(1, 2, 3, 4));
|
|
|
59
|
+ Bookstore bookstore = new Bookstore(books);
|
|
|
60
|
+ assertEquals(25.6, bookstore.calculateTotalCost(), EQUALITY_TOLERANCE);
|
|
|
61
|
+ }
|
|
|
62
|
+
|
|
|
63
|
+ @Ignore
|
|
|
64
|
+ @Test
|
|
|
65
|
+ public void fiveDifferentBooks() {
|
|
|
66
|
+ List<Integer> books = new ArrayList<>(Arrays.asList(1, 2, 3, 4, 5));
|
|
|
67
|
+ Bookstore bookstore = new Bookstore(books);
|
|
|
68
|
+ assertEquals(30, bookstore.calculateTotalCost(), EQUALITY_TOLERANCE);
|
|
|
69
|
+ }
|
|
|
70
|
+
|
|
|
71
|
+ @Ignore
|
|
|
72
|
+ @Test
|
|
|
73
|
+ public void twoGroupsOfFourIsCheaperThanGroupOfFivePlusGroupOfThree() {
|
|
|
74
|
+ List<Integer> books = new ArrayList<>(Arrays.asList(1, 1, 2, 2, 3, 3, 4, 5));
|
|
|
75
|
+ Bookstore bookstore = new Bookstore(books);
|
|
|
76
|
+ assertEquals(51.20, bookstore.calculateTotalCost(), EQUALITY_TOLERANCE);
|
|
|
77
|
+ }
|
|
|
78
|
+
|
|
|
79
|
+ @Ignore
|
|
|
80
|
+ @Test
|
|
|
81
|
+ public void groupOfFourPlusGroupOfTwoIsCheaperThanTwoGroupsOfThree() {
|
|
|
82
|
+ List<Integer> books = new ArrayList<>(Arrays.asList(1, 1, 2, 2, 3, 4));
|
|
|
83
|
+ Bookstore bookstore = new Bookstore(books);
|
|
|
84
|
+ assertEquals(40.8, bookstore.calculateTotalCost(), EQUALITY_TOLERANCE);
|
|
|
85
|
+ }
|
|
|
86
|
+
|
|
|
87
|
+ @Ignore
|
|
|
88
|
+ @Test
|
|
|
89
|
+ public void twoEachOfFirst4BooksAnd1CopyEachOfRest() {
|
|
|
90
|
+ List<Integer> books = new ArrayList<>(Arrays.asList(1, 1, 2, 2, 3, 3, 4, 4, 5));
|
|
|
91
|
+ Bookstore bookstore = new Bookstore(books);
|
|
|
92
|
+ assertEquals(55.60, bookstore.calculateTotalCost(), EQUALITY_TOLERANCE);
|
|
|
93
|
+ }
|
|
|
94
|
+
|
|
|
95
|
+ @Ignore
|
|
|
96
|
+ @Test
|
|
|
97
|
+ public void twoCopiesOfEachBook() {
|
|
|
98
|
+ List<Integer> books = new ArrayList<>(Arrays.asList(1, 1, 2, 2, 3, 3, 4, 4, 5, 5));
|
|
|
99
|
+ Bookstore bookstore = new Bookstore(books);
|
|
|
100
|
+ assertEquals(60.00, bookstore.calculateTotalCost(), EQUALITY_TOLERANCE);
|
|
|
101
|
+ }
|
|
|
102
|
+
|
|
|
103
|
+ @Ignore
|
|
|
104
|
+ @Test
|
|
|
105
|
+ public void threeCopiesOfFirstBookAnd2EachOfRemaining() {
|
|
|
106
|
+ List<Integer> books = new ArrayList<>(Arrays.asList(1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 1));
|
|
|
107
|
+ Bookstore bookstore = new Bookstore(books);
|
|
|
108
|
+ assertEquals(68.00, bookstore.calculateTotalCost(), EQUALITY_TOLERANCE);
|
|
|
109
|
+ }
|
|
|
110
|
+
|
|
|
111
|
+ @Ignore
|
|
|
112
|
+ @Test
|
|
|
113
|
+ public void threeEachOFirst2BooksAnd2EachOfRemainingBooks() {
|
|
|
114
|
+ List<Integer> books = new ArrayList<>(Arrays.asList(1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 1, 2));
|
|
|
115
|
+ Bookstore bookstore = new Bookstore(books);
|
|
|
116
|
+ assertEquals(75.20, bookstore.calculateTotalCost(), EQUALITY_TOLERANCE);
|
|
|
117
|
+ }
|
|
116
|
118
|
|
|
117
|
119
|
}
|
|
118
|
|
-
|