|
2 | 2 |
|
3 | 3 | import static org.junit.jupiter.api.Assertions.assertEquals;
|
4 | 4 | import static org.junit.jupiter.api.Assertions.assertThrows;
|
5 |
| -import java.util.Collections; |
| 5 | + |
6 | 6 | import java.util.ArrayList;
|
| 7 | +import java.util.Collections; |
7 | 8 | import org.junit.jupiter.api.Test;
|
8 | 9 |
|
9 | 10 | public class SlotMachineTest {
|
@@ -62,99 +63,112 @@ public void testPayOut() {
|
62 | 63 | SlotMachine slotMachine2 = new SlotMachine(1, 10, "Test Slot 2", BuyType.BONUS_BUY, icons, 10);
|
63 | 64 | assertEquals(30, slotMachine2.payOut(), "Expected payout for BONUS_BUY to be 30");
|
64 | 65 | }
|
| 66 | + |
65 | 67 | @Test
|
66 |
| - public void testSetNumOfSlots() { |
67 |
| - SlotMachine slotMachine = new SlotMachine(3, 10, "Test Slot", BuyType.NORMAL_BUY, new ArrayList<>(), 10); |
| 68 | + public void testSetNumOfSlots() { |
| 69 | + SlotMachine slotMachine = |
| 70 | + new SlotMachine(3, 10, "Test Slot", BuyType.NORMAL_BUY, new ArrayList<>(), 10); |
68 | 71 |
|
69 |
| - slotMachine.setNumOfSlots(5); |
| 72 | + slotMachine.setNumOfSlots(5); |
70 | 73 |
|
71 |
| - assertEquals(5, slotMachine.getNumOfSlots(), "The number of slots should be updated to 5"); |
72 |
| - } |
73 |
| - @Test |
74 |
| - public void testSetPayAmount() { |
75 |
| - SlotMachine slotMachine = new SlotMachine(3, 10, "Test Slot", BuyType.NORMAL_BUY, new ArrayList<>(), 10); |
| 74 | + assertEquals(5, slotMachine.getNumOfSlots(), "The number of slots should be updated to 5"); |
| 75 | + } |
76 | 76 |
|
77 |
| - slotMachine.setPayAmount(20); |
| 77 | + @Test |
| 78 | + public void testSetPayAmount() { |
| 79 | + SlotMachine slotMachine = |
| 80 | + new SlotMachine(3, 10, "Test Slot", BuyType.NORMAL_BUY, new ArrayList<>(), 10); |
78 | 81 |
|
79 |
| - assertEquals(20, slotMachine.getPayAmount(), "The pay amount should be updated to 20"); |
80 |
| - } |
| 82 | + slotMachine.setPayAmount(20); |
81 | 83 |
|
82 |
| - @Test |
83 |
| - public void testSetName() { |
84 |
| - SlotMachine slotMachine = new SlotMachine(3, 10, "Test Slot", BuyType.NORMAL_BUY, new ArrayList<>(), 10); |
| 84 | + assertEquals(20, slotMachine.getPayAmount(), "The pay amount should be updated to 20"); |
| 85 | + } |
85 | 86 |
|
86 |
| - slotMachine.setName("Lucky Slot"); |
| 87 | + @Test |
| 88 | + public void testSetName() { |
| 89 | + SlotMachine slotMachine = |
| 90 | + new SlotMachine(3, 10, "Test Slot", BuyType.NORMAL_BUY, new ArrayList<>(), 10); |
87 | 91 |
|
88 |
| - assertEquals("Lucky Slot", slotMachine.getName(), "The name should be updated to 'Lucky Slot'"); |
89 |
| - } |
| 92 | + slotMachine.setName("Lucky Slot"); |
90 | 93 |
|
91 |
| - @Test |
92 |
| - public void testSetBuyType() { |
93 |
| - SlotMachine slotMachine = new SlotMachine(3, 10, "Test Slot", BuyType.NORMAL_BUY, new ArrayList<>(), 10); |
| 94 | + assertEquals("Lucky Slot", slotMachine.getName(), "The name should be updated to 'Lucky Slot'"); |
| 95 | + } |
94 | 96 |
|
95 |
| - slotMachine.setBuyType(BuyType.BONUS_BUY); |
| 97 | + @Test |
| 98 | + public void testSetBuyType() { |
| 99 | + SlotMachine slotMachine = |
| 100 | + new SlotMachine(3, 10, "Test Slot", BuyType.NORMAL_BUY, new ArrayList<>(), 10); |
96 | 101 |
|
97 |
| - assertEquals(BuyType.BONUS_BUY, slotMachine.getBuyType(), "The buy type should be updated to BONUS_BUY"); |
98 |
| - } |
99 |
| - @Test |
100 |
| - public void testSetIconList() { |
101 |
| - SlotMachine slotMachine = new SlotMachine(3, 10, "Test Slot", BuyType.NORMAL_BUY, new ArrayList<>(), 10); |
| 102 | + slotMachine.setBuyType(BuyType.BONUS_BUY); |
102 | 103 |
|
103 |
| - ArrayList<String> newIcons = new ArrayList<>(); |
104 |
| - newIcons.add("🍒"); |
105 |
| - newIcons.add("🍋"); |
106 |
| - newIcons.add("🍊"); |
| 104 | + assertEquals( |
| 105 | + BuyType.BONUS_BUY, slotMachine.getBuyType(), "The buy type should be updated to BONUS_BUY"); |
| 106 | + } |
| 107 | + |
| 108 | + @Test |
| 109 | + public void testSetIconList() { |
| 110 | + SlotMachine slotMachine = |
| 111 | + new SlotMachine(3, 10, "Test Slot", BuyType.NORMAL_BUY, new ArrayList<>(), 10); |
107 | 112 |
|
108 |
| - slotMachine.setIconList(newIcons); |
| 113 | + ArrayList<String> newIcons = new ArrayList<>(); |
| 114 | + newIcons.add("🍒"); |
| 115 | + newIcons.add("🍋"); |
| 116 | + newIcons.add("🍊"); |
109 | 117 |
|
110 |
| - assertEquals(newIcons, slotMachine.getIconList(), "The icon list should be updated with the new icons"); |
111 |
| - } |
| 118 | + slotMachine.setIconList(newIcons); |
112 | 119 |
|
113 |
| - @Test |
114 |
| - public void testSetMoneyNeeded() { |
115 |
| - SlotMachine slotMachine = new SlotMachine(3, 10, "Test Slot", BuyType.NORMAL_BUY, new ArrayList<>(), 10); |
| 120 | + assertEquals( |
| 121 | + newIcons, slotMachine.getIconList(), "The icon list should be updated with the new icons"); |
| 122 | + } |
116 | 123 |
|
117 |
| - slotMachine.setMoneyNeeded(15); |
| 124 | + @Test |
| 125 | + public void testSetMoneyNeeded() { |
| 126 | + SlotMachine slotMachine = |
| 127 | + new SlotMachine(3, 10, "Test Slot", BuyType.NORMAL_BUY, new ArrayList<>(), 10); |
118 | 128 |
|
119 |
| - assertEquals(15, slotMachine.getMoneyNeeded(), "The money needed should be updated to 15"); |
120 |
| - } |
121 |
| - @Test |
122 |
| - public void testSpinThrowsExceptionWhenMoneyIsInsufficient() { |
123 |
| - ArrayList<String> icons = new ArrayList<>(); |
124 |
| - icons.add("🍒"); |
125 |
| - icons.add("🍋"); |
126 |
| - icons.add("🍊"); |
| 129 | + slotMachine.setMoneyNeeded(15); |
127 | 130 |
|
128 |
| - SlotMachine slotMachine = new SlotMachine(3, 10, "Test Slot", BuyType.NORMAL_BUY, icons, 10); |
| 131 | + assertEquals(15, slotMachine.getMoneyNeeded(), "The money needed should be updated to 15"); |
| 132 | + } |
129 | 133 |
|
130 |
| - Exception exception = assertThrows(InvalidPayAmountException.class, () -> { |
131 |
| - slotMachine.spin(5); |
132 |
| - }); |
| 134 | + @Test |
| 135 | + public void testSpinThrowsExceptionWhenMoneyIsInsufficient() { |
| 136 | + ArrayList<String> icons = new ArrayList<>(); |
| 137 | + icons.add("🍒"); |
| 138 | + icons.add("🍋"); |
| 139 | + icons.add("🍊"); |
133 | 140 |
|
134 |
| - assertEquals("Amount inavalid", exception.getMessage()); |
135 |
| - } |
| 141 | + SlotMachine slotMachine = new SlotMachine(3, 10, "Test Slot", BuyType.NORMAL_BUY, icons, 10); |
136 | 142 |
|
137 |
| - @Test |
138 |
| - public void testSpinShufflesIconList() throws InvalidPayAmountException { |
139 |
| - ArrayList<String> icons = new ArrayList<>(); |
140 |
| - icons.add("🍒"); |
141 |
| - icons.add("🍋"); |
142 |
| - icons.add("🍊"); |
| 143 | + Exception exception = |
| 144 | + assertThrows( |
| 145 | + InvalidPayAmountException.class, |
| 146 | + () -> { |
| 147 | + slotMachine.spin(5); |
| 148 | + }); |
143 | 149 |
|
144 |
| - SlotMachine slotMachine = new SlotMachine(3, 10, "Test Slot", BuyType.NORMAL_BUY, icons, 10); |
| 150 | + assertEquals("Amount inavalid", exception.getMessage()); |
| 151 | + } |
145 | 152 |
|
146 |
| - ArrayList<String> originalIcons = new ArrayList<>(slotMachine.getIconList()); |
| 153 | + @Test |
| 154 | + public void testSpinShufflesIconList() throws InvalidPayAmountException { |
| 155 | + ArrayList<String> icons = new ArrayList<>(); |
| 156 | + icons.add("🍒"); |
| 157 | + icons.add("🍋"); |
| 158 | + icons.add("🍊"); |
147 | 159 |
|
148 |
| - slotMachine.spin(10); |
| 160 | + SlotMachine slotMachine = new SlotMachine(3, 10, "Test Slot", BuyType.NORMAL_BUY, icons, 10); |
149 | 161 |
|
150 |
| - ArrayList<String> shuffledIcons = slotMachine.getIconList(); |
| 162 | + ArrayList<String> originalIcons = new ArrayList<>(slotMachine.getIconList()); |
151 | 163 |
|
152 |
| - Collections.sort(originalIcons); |
153 |
| - Collections.sort(shuffledIcons); |
| 164 | + slotMachine.spin(10); |
154 | 165 |
|
155 |
| - assertEquals(originalIcons, shuffledIcons, "The icon list should have the same contents after spinning"); |
156 |
| - } |
157 |
| -} |
158 |
| - |
| 166 | + ArrayList<String> shuffledIcons = slotMachine.getIconList(); |
159 | 167 |
|
| 168 | + Collections.sort(originalIcons); |
| 169 | + Collections.sort(shuffledIcons); |
160 | 170 |
|
| 171 | + assertEquals( |
| 172 | + originalIcons, shuffledIcons, "The icon list should have the same contents after spinning"); |
| 173 | + } |
| 174 | +} |
0 commit comments