Lauren Green 6 年前
父节点
当前提交
5c7c3f2e8d

+ 24
- 1
src/main/java/rocks/zipcode/io/quiz3/objectorientation/enums/RockPaperScissorHandSign.java 查看文件

@@ -4,13 +4,36 @@ package rocks.zipcode.io.quiz3.objectorientation.enums;
4 4
  * @author leon on 09/12/2018.
5 5
  */
6 6
 public enum RockPaperScissorHandSign {
7
-    ADD_ENUMERATIONS_HERE;
7
+    ROCK,
8
+    PAPER,
9
+    SCISSORS;
10
+
11
+    RockPaperScissorHandSign() {
12
+    }
8 13
 
9 14
     public RockPaperScissorHandSign getWinner() {
15
+        if(this.equals(ROCK))
16
+            return PAPER;
17
+        if(this.equals(PAPER))
18
+            return SCISSORS;
19
+        if(this.equals(SCISSORS))
20
+            return ROCK;
21
+
10 22
         return null;
23
+
11 24
     }
12 25
 
13 26
     public RockPaperScissorHandSign getLoser() {
27
+
28
+        if(this.equals(ROCK))
29
+            return SCISSORS;
30
+        if(this.equals(PAPER))
31
+            return ROCK;
32
+        if(this.equals(SCISSORS))
33
+            return PAPER;
34
+
14 35
         return null;
15 36
     }
37
+
38
+
16 39
 }

+ 3
- 2
src/test/java/rocks/zipcode/io/quiz3/objectorientation/enums/rockpaperscissors/ScissorTest.java 查看文件

@@ -1,6 +1,7 @@
1 1
 package rocks.zipcode.io.quiz3.objectorientation.enums.rockpaperscissors;
2 2
 
3 3
 import org.junit.Assert;
4
+import org.junit.Before;
4 5
 import org.junit.Test;
5 6
 import rocks.zipcode.io.quiz3.objectorientation.enums.RockPaperScissorHandSign;
6 7
 
@@ -10,10 +11,10 @@ import rocks.zipcode.io.quiz3.objectorientation.enums.RockPaperScissorHandSign;
10 11
 public class ScissorTest {
11 12
     private RockPaperScissorHandSign sign;
12 13
 
13
-    @Test
14
+    @Before
14 15
     public void setup() {
15 16
         // given
16
-        this.sign = RockPaperScissorHandSign.valueOf("SCISSOR");
17
+        this.sign = RockPaperScissorHandSign.valueOf("SCISSORS");
17 18
     }
18 19
 
19 20