-
Notifications
You must be signed in to change notification settings - Fork 109
Expand file tree
/
Copy pathBasketTest.java
More file actions
93 lines (81 loc) · 2.99 KB
/
BasketTest.java
File metadata and controls
93 lines (81 loc) · 2.99 KB
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
package com.booleanuk.core;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
class BasketTest {
// ADD BAGELS TEST
@Test
public void testAddBagelToBasketReturnTrue(){
Basket basket = new Basket();
boolean result = basket.add("chocolate");
Assertions.assertTrue(result);
}
@Test
public void testAddBagelToBasketWithTrueAndFalse(){
Basket basket = new Basket();
Assertions.assertTrue(basket.add("vanilla"));
Assertions.assertTrue(basket.add("chocolate"));
Assertions.assertFalse(basket.add(""));
}
// REMOVE BAGEL TESTS
@Test
public void testRemoveBagelFromBasketReturnsTrue(){
Basket basket = new Basket();
basket.add("Cookie Dough");
basket.add("Vanilla");
basket.add("Chocolate");
basket.add("Blueberry");
Assertions.assertTrue(basket.remove("Chocolate"));
Assertions.assertFalse(basket.remove("Plain"));
Assertions.assertTrue(basket.remove("Cookie Dough"));
}
@Test
public void testChangeCapacityOfBasket(){
Basket basket = new Basket();
Assertions.assertEquals(5, basket.capacity);
basket.changeCapacity(10);
Assertions.assertEquals(10, basket.capacity);
basket.changeCapacity(-3);
Assertions.assertEquals(5, basket.capacity);
}
@Test
public void testBasketIsFullAfterCapacityChange(){
Basket basket = new Basket();
basket.changeCapacity(10);
for (int i = 0; i < 8; i++) {
basket.add("bagel: " + i);
}
Assertions.assertTrue(basket.checkIfNotFull());
for (int i = 0; i < 8; i++) {
basket.add("bagel: " + i);
}
Assertions.assertFalse(basket.checkIfNotFull());
}
@Test
public void testAddBagelIfBasketIsFull(){
Basket basket = new Basket();
Assertions.assertTrue(basket.checkIfNotFull());
basket.add("Cookie Dough");
basket.add("Vanilla");
basket.add("Chocolate");
Assertions.assertTrue(basket.checkIfNotFull());
basket.add("Blueberry");
basket.add("Strawberry");
basket.add("Plain");
Assertions.assertFalse(basket.checkIfNotFull());
}
@Test
public void testTryRemoveBagelInList(){
Basket basket = new Basket();
basket.add("Blueberry");
basket.add("Strawberry");
basket.add("Plain");
basket.add("Cookie Dough");
basket.add("Vanilla");
basket.add("Chocolate");
Assertions.assertEquals("Bagel not in list", basket.tryRemoveBagel("Redberry"));
Assertions.assertEquals("Bagel is removed from list",basket.tryRemoveBagel("Cookie Dough"));
Assertions.assertEquals("Bagel not in list", basket.tryRemoveBagel("Plain."));
Assertions.assertEquals("Bagel is removed from list", basket.tryRemoveBagel("Blueberry"));
Assertions.assertEquals("Bagel is removed from list", basket.tryRemoveBagel("Vanilla"));
}
}