Skip to content

Commit 5bdc97a

Browse files
committed
Feat: Adds Shawn Dunsmore Jr Added Spotless
1 parent e776a62 commit 5bdc97a

File tree

2 files changed

+82
-69
lines changed

2 files changed

+82
-69
lines changed

lesson_16/objects/objects_app/src/main/java/com/codedifferently/lesson16/ShawnDunsmore/SlotMachine.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,5 +103,4 @@ public void setIconList(ArrayList<String> iconList) {
103103
public void setMoneyNeeded(int moneyNeeded) {
104104
this.moneyNeeded = moneyNeeded;
105105
}
106-
107106
}

lesson_16/objects/objects_app/src/test/java/com/codedifferently/lesson16/ShawnDunsmore/SlotMachineTest.java

Lines changed: 82 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22

33
import static org.junit.jupiter.api.Assertions.assertEquals;
44
import static org.junit.jupiter.api.Assertions.assertThrows;
5-
import java.util.Collections;
5+
66
import java.util.ArrayList;
7+
import java.util.Collections;
78
import org.junit.jupiter.api.Test;
89

910
public class SlotMachineTest {
@@ -62,99 +63,112 @@ public void testPayOut() {
6263
SlotMachine slotMachine2 = new SlotMachine(1, 10, "Test Slot 2", BuyType.BONUS_BUY, icons, 10);
6364
assertEquals(30, slotMachine2.payOut(), "Expected payout for BONUS_BUY to be 30");
6465
}
66+
6567
@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);
6871

69-
slotMachine.setNumOfSlots(5);
72+
slotMachine.setNumOfSlots(5);
7073

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+
}
7676

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);
7881

79-
assertEquals(20, slotMachine.getPayAmount(), "The pay amount should be updated to 20");
80-
}
82+
slotMachine.setPayAmount(20);
8183

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+
}
8586

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);
8791

88-
assertEquals("Lucky Slot", slotMachine.getName(), "The name should be updated to 'Lucky Slot'");
89-
}
92+
slotMachine.setName("Lucky Slot");
9093

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+
}
9496

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);
96101

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);
102103

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);
107112

108-
slotMachine.setIconList(newIcons);
113+
ArrayList<String> newIcons = new ArrayList<>();
114+
newIcons.add("🍒");
115+
newIcons.add("🍋");
116+
newIcons.add("🍊");
109117

110-
assertEquals(newIcons, slotMachine.getIconList(), "The icon list should be updated with the new icons");
111-
}
118+
slotMachine.setIconList(newIcons);
112119

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+
}
116123

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);
118128

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);
127130

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+
}
129133

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("🍊");
133140

134-
assertEquals("Amount inavalid", exception.getMessage());
135-
}
141+
SlotMachine slotMachine = new SlotMachine(3, 10, "Test Slot", BuyType.NORMAL_BUY, icons, 10);
136142

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+
});
143149

144-
SlotMachine slotMachine = new SlotMachine(3, 10, "Test Slot", BuyType.NORMAL_BUY, icons, 10);
150+
assertEquals("Amount inavalid", exception.getMessage());
151+
}
145152

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("🍊");
147159

148-
slotMachine.spin(10);
160+
SlotMachine slotMachine = new SlotMachine(3, 10, "Test Slot", BuyType.NORMAL_BUY, icons, 10);
149161

150-
ArrayList<String> shuffledIcons = slotMachine.getIconList();
162+
ArrayList<String> originalIcons = new ArrayList<>(slotMachine.getIconList());
151163

152-
Collections.sort(originalIcons);
153-
Collections.sort(shuffledIcons);
164+
slotMachine.spin(10);
154165

155-
assertEquals(originalIcons, shuffledIcons, "The icon list should have the same contents after spinning");
156-
}
157-
}
158-
166+
ArrayList<String> shuffledIcons = slotMachine.getIconList();
159167

168+
Collections.sort(originalIcons);
169+
Collections.sort(shuffledIcons);
160170

171+
assertEquals(
172+
originalIcons, shuffledIcons, "The icon list should have the same contents after spinning");
173+
}
174+
}

0 commit comments

Comments
 (0)