diff options
author | Bennet Gerlach <bennet_gerlach@web.de> | 2011-05-09 21:56:29 +0200 |
---|---|---|
committer | Bennet Gerlach <bennet_gerlach@web.de> | 2011-05-09 21:56:29 +0200 |
commit | 5767486e8317c22eee028606c49f2a4a8909de3c (patch) | |
tree | 2301c1555ff7b9978d2259b267e88a3b77f3842a | |
parent | c5374de06f0cf8a2bcf2bd43c4aabaa33cd36d01 (diff) | |
download | JRummikub-5767486e8317c22eee028606c49f2a4a8909de3c.tar JRummikub-5767486e8317c22eee028606c49f2a4a8909de3c.zip |
Test simple dropping on Hand
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@198 72836036-5685-4462-b002-a69064685172
-rw-r--r-- | src/jrummikub/model/Position.java | 30 | ||||
-rw-r--r-- | test/jrummikub/model/HandTest.java | 31 |
2 files changed, 59 insertions, 2 deletions
diff --git a/src/jrummikub/model/Position.java b/src/jrummikub/model/Position.java index 35cf45e..7396120 100644 --- a/src/jrummikub/model/Position.java +++ b/src/jrummikub/model/Position.java @@ -6,6 +6,7 @@ package jrummikub.model; */ public class Position { + private float x; private float y; @@ -13,9 +14,9 @@ public class Position { * Create a new position by specifying the coordinates * * @param x - * x coordinate + * x coordinate * @param y - * y coordinate + * y coordinate */ public Position(float x, float y) { this.x = x; @@ -45,4 +46,29 @@ public class Position { return "Position[x=" + x + ",y=" + y + "]"; } + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Position other = (Position) obj; + if (Float.floatToIntBits(x) != Float.floatToIntBits(other.x)) + return false; + if (Float.floatToIntBits(y) != Float.floatToIntBits(other.y)) + return false; + return true; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + Float.floatToIntBits(x); + result = prime * result + Float.floatToIntBits(y); + return result; + } + } diff --git a/test/jrummikub/model/HandTest.java b/test/jrummikub/model/HandTest.java new file mode 100644 index 0000000..25a9c18 --- /dev/null +++ b/test/jrummikub/model/HandTest.java @@ -0,0 +1,31 @@ +package jrummikub.model;
+
+import org.junit.Before;
+import org.junit.Test;
+import static jrummikub.model.StoneColor.*;
+import static org.junit.Assert.*;
+
+public class HandTest {
+
+ Hand hand;
+
+ @Before
+ public void setUp() {
+ hand = new Hand();
+ }
+
+ @Test
+ public void testSimpleDrop() {
+ Stone stone1 = new Stone(1, RED);
+ Stone stone2 = new Stone(5, RED);
+ Stone stone3 = new Stone(2, RED);
+
+ hand.drop(stone1, new Position(2, 0));
+ hand.drop(stone2, new Position(3, 0));
+ hand.drop(stone3, new Position(2.5f, 0));
+
+ assertEquals(new Position(1.5f, 0), hand.getPosition(stone1));
+ assertEquals(new Position(3.5f, 0), hand.getPosition(stone2));
+ assertEquals(new Position(2.5f, 0), hand.getPosition(stone3));
+ }
+}
|