Skip to content

Commit 5ece839

Browse files
authored
Merge pull request ZipCodeCore#2 from TimothyRager/dev
Pot and PotTest
2 parents 9aa0f1d + 36bd984 commit 5ece839

File tree

2 files changed

+56
-3
lines changed
  • src
    • main/java/io/zipcoder/casino/nuts_n_bolts
    • test/java/io/zipcoder/casino/nuts_n_bolts

2 files changed

+56
-3
lines changed

src/main/java/io/zipcoder/casino/nuts_n_bolts/Pot.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,22 @@ public Double getMoney() {
1111
}
1212

1313
public void addToPot(Double money) {
14-
this.money = money;
14+
if (money>0) {
15+
this.money += money;
16+
}
1517
}
1618

1719
public Double takeOutOfPot (Double money){
18-
return null; //check request < pot
20+
if (money>0 && money<=this.money){
21+
this.money-=money;
22+
return money;
23+
}
24+
return 0.0;
1925
}
2026

2127
public Double takeAllOutOfPot(){
22-
return null;
28+
double moneyHolder = this.money;
29+
this.money=0.0;
30+
return moneyHolder;
2331
}
2432
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,49 @@
11
package io.zipcoder.casino.nuts_n_bolts;
22

3+
import org.junit.Test;
4+
import org.junit.Assert;
5+
import java.util.Random;
6+
37
public class PotTest {
8+
9+
private Random rando = new Random();
10+
11+
@Test
12+
public void testAddToPotAndGetMoney(){
13+
Pot testPot = new Pot();
14+
Double amountToAdd = rando.nextDouble();
15+
Double actual;
16+
testPot.addToPot(amountToAdd);
17+
actual=testPot.getMoney();
18+
Assert.assertEquals(amountToAdd, actual, 0.0001);
19+
}
20+
21+
@Test
22+
public void testTakeOutOfPot(){
23+
Pot testPot = new Pot();
24+
Double amountToRemove = rando.nextDouble();
25+
Double actual;
26+
Double expected;
27+
28+
testPot.addToPot(rando.nextDouble());
29+
if (amountToRemove<testPot.getMoney())
30+
expected = amountToRemove;
31+
else
32+
expected=0.0;
33+
actual=testPot.takeOutOfPot(amountToRemove);
34+
Assert.assertEquals(expected, actual, 0.0001);
35+
}
36+
37+
@Test
38+
public void testTakeAllOutOfPot(){
39+
Pot testPot = new Pot();
40+
testPot.addToPot(rando.nextDouble());
41+
Double expected=testPot.getMoney();
42+
Double actual = testPot.takeAllOutOfPot();
43+
44+
Assert.assertEquals(expected, actual, 0.0001);
45+
Assert.assertEquals(0.0, testPot.getMoney(), 0.0001);
46+
}
47+
48+
449
}

0 commit comments

Comments
 (0)