summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--test/jrummikub/control/TurnControlTest.java142
1 files changed, 79 insertions, 63 deletions
diff --git a/test/jrummikub/control/TurnControlTest.java b/test/jrummikub/control/TurnControlTest.java
index 20534f0..7edc921 100644
--- a/test/jrummikub/control/TurnControlTest.java
+++ b/test/jrummikub/control/TurnControlTest.java
@@ -4,6 +4,7 @@ import static org.junit.Assert.*;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.HashMap;
import java.util.List;
import jrummikub.model.MockHand;
@@ -12,6 +13,7 @@ import jrummikub.model.Position;
import jrummikub.model.Stone;
import jrummikub.model.StoneColor;
import jrummikub.model.StoneSet;
+import jrummikub.model.Table;
import jrummikub.util.Event;
import jrummikub.util.IEvent;
import jrummikub.util.IListener;
@@ -24,6 +26,11 @@ import org.junit.Test;
import static jrummikub.model.StoneColor.*;
public class TurnControlTest {
+ static class AccessibleTable extends Table{
+ StoneSet[] getSetArray(){
+ return objects.keySet().toArray(new StoneSet[0]);
+ }
+ }
class MockTimer implements ITurnTimer {
public boolean timerRunning = false;
@@ -406,6 +413,9 @@ public class TurnControlTest {
@Test
public void testAddLeft() {
+ AccessibleTable table=new AccessibleTable();
+ TurnControl turnControl=new TurnControl(mockHand, table, mockView, mockTimer);
+ turnControl.startTurn();
Stone blueOne = new Stone(1, BLUE);
Stone redOne = new Stone(1, RED);
Stone blackOne = new Stone(1, BLACK);
@@ -423,8 +433,8 @@ public class TurnControlTest {
blackOne, redTwo, redThree, redFour, blackTwo, blackThree));
StoneSet oldSet2 = new StoneSet(Arrays.asList(blueTwo, blackFour,
blackFive));
- mockTable.drop(oldSet1, new Position(0, 0));
- mockTable.drop(oldSet2, new Position(0, 0));
+ table.drop(oldSet1, new Position(0, 0));
+ table.drop(oldSet2, new Position(0, 0));
mockHand.drop(blueThree, new Position(0, 0));
mockHand.drop(blueFour, new Position(0, 0));
mockView.playerPanel.handPanel.stoneClickEvent.emit(blueThree, false);
@@ -435,14 +445,14 @@ public class TurnControlTest {
assertEquals(1, mockHand.getSize());
assertSame(mockHand.stones.get(0), blueFour);
// tablecheck
- assertEquals(2, mockTable.getSize());
+ assertEquals(2, table.getSize());
StoneSet newSet1, newSet2;
- if (mockTable.sets.get(0).getFirst().size() == 3) {
- newSet2 = mockTable.sets.get(0).getFirst();
- newSet1 = mockTable.sets.get(1).getFirst();
+ if (table.getSetArray()[0].size() == 3) {
+ newSet2 = table.getSetArray()[0];
+ newSet1 = table.getSetArray()[1];
} else {
- newSet1 = mockTable.sets.get(0).getFirst();
- newSet2 = mockTable.sets.get(1).getFirst();
+ newSet1 = table.getSetArray()[0];
+ newSet2 = table.getSetArray()[1];
}
assertSame(oldSet2, newSet2);
// setcheck
@@ -464,13 +474,13 @@ public class TurnControlTest {
assertEquals(1, mockHand.getSize());
assertSame(mockHand.stones.get(0), blueFour);
// tablecheck
- assertEquals(2, mockTable.getSize());
- if (mockTable.sets.get(0).getFirst().size() == 5) {
- newSet2 = mockTable.sets.get(0).getFirst();
- newSet1 = mockTable.sets.get(1).getFirst();
+ assertEquals(2, table.getSize());
+ if (table.getSetArray()[0].size() == 5) {
+ newSet2 =table.getSetArray()[0];
+ newSet1 =table.getSetArray()[1];
} else {
- newSet1 = mockTable.sets.get(0).getFirst();
- newSet2 = mockTable.sets.get(1).getFirst();
+ newSet1 = table.getSetArray()[0];
+ newSet2 = table.getSetArray()[1];
}
// setcheck1
assertEquals(7, newSet1.size());
@@ -494,13 +504,13 @@ public class TurnControlTest {
// handcheck
assertEquals(0, mockHand.getSize());
// tablecheck
- assertEquals(2, mockTable.getSize());
- if (mockTable.sets.get(0).getFirst().size() == 6) {
- newSet2 = mockTable.sets.get(0).getFirst();
- newSet1 = mockTable.sets.get(1).getFirst();
+ assertEquals(2, table.getSize());
+ if (table.getSetArray()[0].size() == 6) {
+ newSet2 = table.getSetArray()[0];
+ newSet1 = table.getSetArray()[1];
} else {
- newSet1 = mockTable.sets.get(0).getFirst();
- newSet2 = mockTable.sets.get(1).getFirst();
+ newSet1 = table.getSetArray()[0];
+ newSet2 = table.getSetArray()[1];
}
// setcheck1
assertEquals(7, newSet1.size());
@@ -516,6 +526,9 @@ public class TurnControlTest {
@Test
public void testAddRight() {
+ AccessibleTable table=new AccessibleTable();
+ TurnControl turnControl=new TurnControl(mockHand, table, mockView, mockTimer);
+ turnControl.startTurn();
Stone blueOne = new Stone(1, BLUE);
Stone redOne = new Stone(1, RED);
Stone blackOne = new Stone(1, BLACK);
@@ -533,8 +546,8 @@ public class TurnControlTest {
blackOne, redTwo, redThree, redFour, blackTwo, blackThree));
StoneSet oldSet2 = new StoneSet(Arrays.asList(blueTwo, blackFour,
blackFive));
- mockTable.drop(oldSet1, new Position(0, 0));
- mockTable.drop(oldSet2, new Position(0, 0));
+ table.drop(oldSet1, new Position(0, 0));
+ table.drop(oldSet2, new Position(0, 0));
mockHand.drop(blueThree, new Position(0, 0));
mockHand.drop(blueFour, new Position(0, 0));
mockView.playerPanel.handPanel.stoneClickEvent.emit(blueThree, false);
@@ -545,14 +558,14 @@ public class TurnControlTest {
assertEquals(1, mockHand.getSize());
assertSame(mockHand.stones.get(0), blueFour);
// tablecheck
- assertEquals(2, mockTable.getSize());
+ assertEquals(2, table.getSize());
StoneSet newSet1, newSet2;
- if (mockTable.sets.get(0).getFirst().size() == 3) {
- newSet2 = mockTable.sets.get(0).getFirst();
- newSet1 = mockTable.sets.get(1).getFirst();
+ if (table.getSetArray()[0].size() == 3) {
+ newSet2 = table.getSetArray()[0];
+ newSet1 = table.getSetArray()[1];
} else {
- newSet1 = mockTable.sets.get(0).getFirst();
- newSet2 = mockTable.sets.get(1).getFirst();
+ newSet1 = table.getSetArray()[0];
+ newSet2 = table.getSetArray()[1];
}
assertSame(oldSet2, newSet2);
// setcheck
@@ -574,13 +587,13 @@ public class TurnControlTest {
assertEquals(1, mockHand.getSize());
assertSame(mockHand.stones.get(0), blueFour);
// tablecheck
- assertEquals(2, mockTable.getSize());
- if (mockTable.sets.get(0).getFirst().size() == 5) {
- newSet2 = mockTable.sets.get(0).getFirst();
- newSet1 = mockTable.sets.get(1).getFirst();
+ assertEquals(2, table.getSize());
+ if (table.getSetArray()[0].size() == 5) {
+ newSet2 = table.getSetArray()[0];
+ newSet1 = table.getSetArray()[1];
} else {
- newSet1 = mockTable.sets.get(0).getFirst();
- newSet2 = mockTable.sets.get(1).getFirst();
+ newSet1 = table.getSetArray()[0];
+ newSet2 = table.getSetArray()[1];
}
// setcheck1
assertEquals(7, newSet1.size());
@@ -604,13 +617,13 @@ public class TurnControlTest {
// handcheck
assertEquals(0, mockHand.getSize());
// tablecheck
- assertEquals(2, mockTable.getSize());
- if (mockTable.sets.get(0).getFirst().size() == 6) {
- newSet2 = mockTable.sets.get(0).getFirst();
- newSet1 = mockTable.sets.get(1).getFirst();
+ assertEquals(2, table.getSize());
+ if (table.getSetArray()[0].size() == 6) {
+ newSet2 = table.getSetArray()[0];
+ newSet1 = table.getSetArray()[1];
} else {
- newSet1 = mockTable.sets.get(0).getFirst();
- newSet2 = mockTable.sets.get(1).getFirst();
+ newSet1 = table.getSetArray()[0];
+ newSet2 = table.getSetArray()[1];
}
// setcheck1
assertEquals(7, newSet1.size());
@@ -626,6 +639,9 @@ public class TurnControlTest {
@Test
public void testAddNewSet() {
+ AccessibleTable table=new AccessibleTable();
+ TurnControl turnControl=new TurnControl(mockHand, table, mockView, mockTimer);
+ turnControl.startTurn();
Stone blueOne = new Stone(1, BLUE);
Stone redOne = new Stone(1, RED);
Stone blackOne = new Stone(1, BLACK);
@@ -643,8 +659,8 @@ public class TurnControlTest {
blackOne, redTwo, redThree, redFour, blackTwo, blackThree));
StoneSet oldSet2 = new StoneSet(Arrays.asList(blueTwo, blackFour,
blackFive));
- mockTable.drop(oldSet1, new Position(0, 0));
- mockTable.drop(oldSet2, new Position(0, 0));
+ table.drop(oldSet1, new Position(0, 0));
+ table.drop(oldSet2, new Position(0, 0));
mockHand.drop(blueThree, new Position(0, 0));
mockHand.drop(blueFour, new Position(0, 0));
mockView.playerPanel.handPanel.stoneClickEvent.emit(blueThree, false);
@@ -657,33 +673,33 @@ public class TurnControlTest {
assertSame(blueFour, mockHand.stones.get(0));
// tablecheck
StoneSet newSet1, newSet2, newSet3;
- assertEquals(2, mockTable.getSize());
- if (mockTable.sets.get(0).getFirst().size() == 2) {
- newSet2 = mockTable.sets.get(0).getFirst();
- if (mockTable.sets.get(1).getFirst().size() == 4) {
- newSet3 = mockTable.sets.get(1).getFirst();
- newSet1 = mockTable.sets.get(2).getFirst();
+ assertEquals(2, table.getSize());
+ if (table.getSetArray()[0].size() == 2) {
+ newSet2 = table.getSetArray()[0];
+ if (table.getSetArray()[1].size() == 4) {
+ newSet3 = table.getSetArray()[1];
+ newSet1 = table.getSetArray()[2];
} else {
- newSet3 = mockTable.sets.get(2).getFirst();
- newSet1 = mockTable.sets.get(1).getFirst();
+ newSet3 = table.getSetArray()[2];
+ newSet1 = table.getSetArray()[1];
}
- } else if (mockTable.sets.get(0).getFirst().size() == 4) {
- newSet3 = mockTable.sets.get(0).getFirst();
- if (mockTable.sets.get(1).getFirst().size() == 2) {
- newSet2 = mockTable.sets.get(1).getFirst();
- newSet1 = mockTable.sets.get(2).getFirst();
+ } else if (table.getSetArray()[0].size() == 4) {
+ newSet3 = table.getSetArray()[0];
+ if (table.getSetArray()[1].size() == 2) {
+ newSet2 = table.getSetArray()[1];
+ newSet1 = table.getSetArray()[2];
} else {
- newSet2 = mockTable.sets.get(2).getFirst();
- newSet1 = mockTable.sets.get(1).getFirst();
+ newSet2 = table.getSetArray()[2];
+ newSet1 = table.getSetArray()[1];
}
} else {
- newSet1 = mockTable.sets.get(0).getFirst();
- if (mockTable.sets.get(1).getFirst().size() == 2) {
- newSet2 = mockTable.sets.get(1).getFirst();
- newSet3 = mockTable.sets.get(2).getFirst();
+ newSet1 = table.getSetArray()[0];
+ if (table.getSetArray()[1].size() == 2) {
+ newSet2 = table.getSetArray()[1];
+ newSet3 = table.getSetArray()[2];
} else {
- newSet2 = mockTable.sets.get(2).getFirst();
- newSet3 = mockTable.sets.get(1).getFirst();
+ newSet2 =table.getSetArray()[2];
+ newSet3 = table.getSetArray()[1];
}
}