Procházet zdrojové kódy

added three tests, one working

mpierse před 6 roky
rodič
revize
cdef37dc14

+ 5
- 1
src/main/java/com/zipcodewilmington/froilansfarm/Animals/Horse.java Zobrazit soubor

@@ -9,6 +9,7 @@ import com.zipcodewilmington.froilansfarm.Rider;
9 9
 public class Horse extends Amimal implements Ridable {
10 10
 
11 11
     Stable stable = new Stable(0);
12
+    private String result;
12 13
 
13 14
 
14 15
     public String makeNoise() {
@@ -20,7 +21,7 @@ public class Horse extends Amimal implements Ridable {
20 21
     }
21 22
 
22 23
     public String ride(Person rider) {
23
-        String result = "No riding today";
24
+        result = "No riding today";
24 25
         if (getIsRideable(rider)) {
25 26
             result = "";
26 27
             for (int i = 1; i <= stable.getHorses(); i++) {
@@ -31,4 +32,7 @@ public class Horse extends Amimal implements Ridable {
31 32
         return result;
32 33
     }
33 34
 
35
+    public String getRideResult() {
36
+        return result;
37
+    }
34 38
 }

+ 3
- 6
src/main/java/com/zipcodewilmington/froilansfarm/Holders/Farm.java Zobrazit soubor

@@ -27,9 +27,9 @@ public class Farm  {
27 27
     private ChickenCoop coop2 = new ChickenCoop(4);
28 28
     private ChickenCoop coop3 = new ChickenCoop(4);
29 29
     private ChickenCoop coop4 = new ChickenCoop(4);
30
-    private Stable stable1 = new Stable(0);
31
-    private Stable stable2 = new Stable(0);
32
-    private Stable stable3 = new Stable(0);
30
+    private Stable stable1 = new Stable(3);
31
+    private Stable stable2 = new Stable(3);
32
+    private Stable stable3 = new Stable(3);
33 33
     private Tractor tractor1 = new Tractor();
34 34
     private Tractor tractor2 = new Tractor();
35 35
     private CropDuster cropDuster = new CropDuster();
@@ -62,9 +62,6 @@ public class Farm  {
62 62
         field.addToField(row3);
63 63
         field.addToField(row4);
64 64
         field.addToField(row5);
65
-        stable1.setHorses(3);
66
-        stable2.setHorses(3);
67
-        stable3.setHorses(3);
68 65
     }
69 66
 
70 67
     public void morningRoutine(){

+ 24
- 18
src/test/java/com/zipcodewilmington/froilansfarm/SundayTest.java Zobrazit soubor

@@ -10,41 +10,47 @@ import org.junit.Test;
10 10
 public class SundayTest {
11 11
 
12 12
     Farm farm;
13
+  //  int cornFirstCount;
14
+  //  int tomatoFirstCount;
15
+
13 16
 
14 17
     @Before
15 18
     public void setup(){
16 19
         farm = new Farm();
20
+      //  cornFirstCount = farm.getCorn().getFoodCount();
21
+      //  tomatoFirstCount = farm.getTomato().getFoodCount();
22
+        //farm.populateFarm();
23
+      //  farm.morningRoutine();
17 24
 
18 25
     }
19 26
 
20
-    @Test
21
-    public void cornEatTest(){
22
-    int firstCount = farm.getCorn().getFoodCount();
23
-    farm.populateFarm();
24
-    farm.morningRoutine();
25
-    int secondCount = farm.getCorn().getFoodCount();
26
-    int expected = 30;
27
-    int actual = firstCount-secondCount;
28
-    Assert.assertEquals(expected, actual);
29
-    }
30 27
 
31 28
     @Test
32 29
     public void horseRidetest(){
33
-       // farm.populateFarm();
34
-       // farm.morningRoutine();
30
+        farm.populateFarm();
31
+        farm.morningRoutine();
35 32
         String expected = "Horse number 1 has been ridden today. \nHorse number 2 has been ridden today. \nHorse number 3 has been ridden today. \nHorse number 4 has been ridden today. \nHorse number 5 has been ridden today. \nHorse number 6 has been ridden today. \nHorse number 7 has been ridden today. \nHorse number 8 has been ridden today. \nHorse number 9 has been ridden today. \n";
36
-        farm.getFroilan().setIsMounted();
37
-        String actual = farm.getHorse().ride(farm.getFroilan());
33
+        String actual = farm.getHorse().getRideResult();
38 34
         Assert.assertEquals(expected, actual);
39 35
     }
40 36
     @Test
41 37
     public void tomatoEatTest(){
42
-        int firstCount = farm.getTomato().getFoodCount();
43
-       // farm.populateFarm();
44
-        //farm.morningRoutine();
38
+       int tomatoFirstCount = farm.getTomato().getFoodCount();
39
+       farm.populateFarm();
40
+        farm.morningRoutine();
45 41
         int secondCount = farm.getTomato().getFoodCount();
46 42
         int expected = 6;
47
-        int actual = firstCount-secondCount;
43
+        int actual = tomatoFirstCount-secondCount;
44
+        Assert.assertEquals(expected, actual);
45
+    }
46
+    @Test
47
+    public void cornEatTest(){
48
+       int cornFirstCount = farm.getCorn().getFoodCount();
49
+        farm.populateFarm();
50
+         farm.morningRoutine();
51
+        int secondCount = farm.getCorn().getFoodCount();
52
+        int expected = 30;
53
+        int actual = cornFirstCount-secondCount;
48 54
         Assert.assertEquals(expected, actual);
49 55
     }
50 56