diff options
author | Ida Massow <massow@informatik.uni-luebeck.de> | 2011-05-09 21:19:04 +0200 |
---|---|---|
committer | Ida Massow <massow@informatik.uni-luebeck.de> | 2011-05-09 21:19:04 +0200 |
commit | 223f6d7e858021d9d08e8d074c06bf9804518ee4 (patch) | |
tree | db51ba129a83789c6a384e3fb1740ea92bda6add | |
parent | a6a5388560692b59a20a82a4b22a231d6705d9d0 (diff) | |
download | JRummikub-223f6d7e858021d9d08e8d074c06bf9804518ee4.tar JRummikub-223f6d7e858021d9d08e8d074c06bf9804518ee4.zip |
Testfall für rangeclick auf der Hand
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@196 72836036-5685-4462-b002-a69064685172
-rw-r--r-- | mock/jrummikub/view/MockHandPanel.java | 8 | ||||
-rw-r--r-- | test/jrummikub/control/TurnControlTest.java | 159 |
2 files changed, 136 insertions, 31 deletions
diff --git a/mock/jrummikub/view/MockHandPanel.java b/mock/jrummikub/view/MockHandPanel.java index 7864240..6069019 100644 --- a/mock/jrummikub/view/MockHandPanel.java +++ b/mock/jrummikub/view/MockHandPanel.java @@ -13,6 +13,7 @@ import jrummikub.util.Pair; public class MockHandPanel implements IHandPanel { public Event2<Stone, Boolean> stoneClickEvent = new Event2<Stone, Boolean>(); public List<Pair<Stone, Position>> stones; + public Event2<Stone, Boolean> rangeClickEvent = new Event2<Stone, Boolean>(); @Override public IEvent2<Stone, Boolean> getStoneClickEvent() { @@ -21,8 +22,7 @@ public class MockHandPanel implements IHandPanel { @Override public IEvent2<Stone, Boolean> getRangeClickEvent() { - // TODO Auto-generated method stub - return null; + return rangeClickEvent; } @Override @@ -49,13 +49,13 @@ public class MockHandPanel implements IHandPanel { @Override public void setHandWidth(int width) { // TODO Auto-generated method stub - + } @Override public void setHandHeight(int height) { // TODO Auto-generated method stub - + } } diff --git a/test/jrummikub/control/TurnControlTest.java b/test/jrummikub/control/TurnControlTest.java index 6178ec4..fdc43fc 100644 --- a/test/jrummikub/control/TurnControlTest.java +++ b/test/jrummikub/control/TurnControlTest.java @@ -111,9 +111,10 @@ public class TurnControlTest { public void showInitialHand() { mockView.displayStartTurnPanel = true; - List<Pair<Stone, Position>> stones = Arrays.asList( - new Pair<Stone, Position>(new Stone(RED), new Position(0, 0)), - new Pair<Stone, Position>(new Stone(BLACK), new Position(1, 0))); + List<Pair<Stone, Position>> stones = Arrays + .asList(new Pair<Stone, Position>(new Stone(RED), new Position( + 0, 0)), new Pair<Stone, Position>(new Stone(BLACK), + new Position(1, 0))); mockHand.iterable = stones; @@ -239,8 +240,8 @@ public class TurnControlTest { mockView.playerPanel.handPanel.stoneClickEvent.emit(firstStone, true); mockView.playerPanel.handPanel.stoneClickEvent.emit(secondStone, true); - mockView.tablePanel.stoneCollectionPanel.stoneClickEvent.emit(firstStone, - false); + mockView.tablePanel.stoneCollectionPanel.stoneClickEvent.emit( + firstStone, false); assertCollection(Arrays.asList(secondStone)); } @@ -255,8 +256,8 @@ public class TurnControlTest { mockView.playerPanel.handPanel.stoneClickEvent.emit(firstStone, true); mockView.playerPanel.handPanel.stoneClickEvent.emit(secondStone, true); - mockView.tablePanel.stoneCollectionPanel.stoneClickEvent.emit(firstStone, - true); + mockView.tablePanel.stoneCollectionPanel.stoneClickEvent.emit( + firstStone, true); assertCollection(Arrays.asList(secondStone, firstStone)); } @@ -271,8 +272,8 @@ public class TurnControlTest { mockView.playerPanel.handPanel.stoneClickEvent.emit(firstStone, true); mockView.playerPanel.handPanel.stoneClickEvent.emit(secondStone, true); - mockView.tablePanel.stoneCollectionPanel.stoneClickEvent.emit(firstStone, - true); + mockView.tablePanel.stoneCollectionPanel.stoneClickEvent.emit( + firstStone, true); mockView.tablePanel.stoneCollectionPanel.setClickEvent.emit(firstStone, true); @@ -374,7 +375,8 @@ public class TurnControlTest { Stone stone2 = new Stone(2, StoneColor.RED); Stone stone3 = new Stone(3, StoneColor.RED); Stone stone4 = new Stone(4, StoneColor.RED); - StoneSet set1 = new StoneSet(Arrays.asList(stone1, stone2, stone3, stone4)); + StoneSet set1 = new StoneSet(Arrays.asList(stone1, stone2, stone3, + stone4)); mockTable.findStoneSet.put(stone1, set1); mockTable.findStoneSet.put(stone3, set1); @@ -385,7 +387,7 @@ public class TurnControlTest { assertCollection(Arrays.asList(stone1, stone2, stone3)); } - + @Test public void rangeSelectOnTable() { testControl.startTurn(); @@ -394,7 +396,8 @@ public class TurnControlTest { Stone stone2 = new Stone(2, StoneColor.RED); Stone stone3 = new Stone(3, StoneColor.RED); Stone stone4 = new Stone(4, StoneColor.RED); - StoneSet set1 = new StoneSet(Arrays.asList(stone1, stone2, stone3, stone4)); + StoneSet set1 = new StoneSet(Arrays.asList(stone1, stone2, stone3, + stone4)); mockTable.findStoneSet.put(stone1, set1); mockTable.findStoneSet.put(stone3, set1); @@ -416,7 +419,8 @@ public class TurnControlTest { Stone stone2 = new Stone(2, StoneColor.RED); Stone stone3 = new Stone(3, StoneColor.RED); Stone stone4 = new Stone(4, StoneColor.RED); - StoneSet set1 = new StoneSet(Arrays.asList(stone1, stone2, stone3, stone4)); + StoneSet set1 = new StoneSet(Arrays.asList(stone1, stone2, stone3, + stone4)); mockTable.findStoneSet.put(stone1, set1); mockTable.findStoneSet.put(stone3, set1); @@ -476,6 +480,107 @@ public class TurnControlTest { assertCollection(Arrays.asList(stone1, stone2)); } + @Test + public void rangeSelectOnHandReverse() { + testControl.startTurn(); + + Stone stone1 = new Stone(1, StoneColor.RED); + Stone stone2 = new Stone(2, StoneColor.RED); + Stone stone3 = new Stone(3, StoneColor.RED); + Stone stone4 = new Stone(4, StoneColor.RED); + mockHand.drop(stone1, new Position(0, 0)); + mockHand.drop(stone2, new Position(1.5f, 0)); + mockHand.drop(stone3, new Position(0, 1)); + mockHand.drop(stone4, new Position(1, 1)); + + mockView.playerPanel.handPanel.stoneClickEvent.emit(stone3, false); + mockView.playerPanel.handPanel.rangeClickEvent.emit(stone1, true); + + assertCollection(Arrays.asList(stone1, stone2, stone3)); + } + + @Test + public void rangeSelectOnHand() { + testControl.startTurn(); + + Stone stone1 = new Stone(1, StoneColor.RED); + Stone stone2 = new Stone(2, StoneColor.RED); + Stone stone3 = new Stone(3, StoneColor.RED); + Stone stone4 = new Stone(4, StoneColor.RED); + mockHand.drop(stone1, new Position(0, 0)); + mockHand.drop(stone2, new Position(1.5f, 0)); + mockHand.drop(stone3, new Position(0, 1)); + mockHand.drop(stone4, new Position(1, 1)); + + mockView.playerPanel.handPanel.stoneClickEvent.emit(stone1, false); + mockView.playerPanel.handPanel.rangeClickEvent.emit(stone3, true); + + assertCollection(Arrays.asList(stone1, stone2, stone3)); + } + + @Test + public void rangeCollectOnHand() { + testControl.startTurn(); + + Stone extraStone = new Stone(StoneColor.RED); + + Stone stone1 = new Stone(1, StoneColor.RED); + Stone stone2 = new Stone(2, StoneColor.RED); + Stone stone3 = new Stone(3, StoneColor.RED); + Stone stone4 = new Stone(4, StoneColor.RED); + mockHand.drop(stone1, new Position(0, 0)); + mockHand.drop(stone2, new Position(1.5f, 0)); + mockHand.drop(stone3, new Position(0, 1)); + mockHand.drop(stone4, new Position(1, 1)); + + mockView.playerPanel.handPanel.stoneClickEvent.emit(extraStone, false); + + mockView.playerPanel.handPanel.stoneClickEvent.emit(stone1, true); + mockView.playerPanel.handPanel.rangeClickEvent.emit(stone3, false); + assertCollection(Arrays.asList(extraStone, stone1, stone2, stone3)); + } + + @Test + public void rangeFailSelectHand() { + testControl.startTurn(); + + Stone stone1 = new Stone(1, StoneColor.RED); + Stone stone2 = new Stone(2, StoneColor.RED); + StoneSet set1 = new StoneSet(Arrays.asList(stone1)); + mockTable.findStoneSet.put(stone1, set1); + mockHand.drop(stone2, new Position(0, 0)); + // Select first stone + mockView.tablePanel.stoneClickEvent.emit(stone1, false); + + assertCollection(Arrays.asList(stone1)); + + // Select second stone + mockView.playerPanel.handPanel.rangeClickEvent.emit(stone2, false); + + assertCollection(Arrays.asList(stone2)); + + } + + @Test + public void rangeFailCollectHand() { + testControl.startTurn(); + + Stone stone1 = new Stone(1, StoneColor.RED); + Stone stone2 = new Stone(2, StoneColor.RED); + StoneSet set1 = new StoneSet(Arrays.asList(stone1)); + mockTable.findStoneSet.put(stone1, set1); + mockHand.drop(stone2, new Position(0, 0)); + // Select first stone + mockView.tablePanel.stoneClickEvent.emit(stone1, false); + + assertCollection(Arrays.asList(stone1)); + + // Select second stone + mockView.playerPanel.handPanel.rangeClickEvent.emit(stone2, true); + + assertCollection(Arrays.asList(stone1, stone2)); + } + private void assertCollection(List<Stone> expected) { ArrayList<Stone> selectedStones = new ArrayList<Stone>( mockView.selectedStones); @@ -502,10 +607,10 @@ public class TurnControlTest { Stone blackThree = new Stone(3, BLACK); Stone blackFour = new Stone(4, BLACK); Stone blackFive = new Stone(5, BLACK); - StoneSet oldSet1 = new StoneSet(Arrays.asList(blueOne, redOne, blackOne, - redTwo, redThree, redFour, blackTwo, blackThree)); - StoneSet oldSet2 = new StoneSet( - Arrays.asList(blueTwo, blackFour, blackFive)); + StoneSet oldSet1 = new StoneSet(Arrays.asList(blueOne, redOne, + blackOne, redTwo, redThree, redFour, blackTwo, blackThree)); + StoneSet oldSet2 = new StoneSet(Arrays.asList(blueTwo, blackFour, + blackFive)); table.drop(oldSet1, new Position(0, 0)); table.drop(oldSet2, new Position(0, 0)); mockHand.drop(blueThree, new Position(0, 0)); @@ -575,7 +680,7 @@ public class TurnControlTest { mockView.playerPanel.handPanel.stoneClickEvent.emit(blueFour, false); mockView.tablePanel.stoneClickEvent.emit(redOne, true); mockView.tablePanel.leftConnectorClickEvent.emit(newSet2); - + // handcheck assertEquals(0, mockHand.getSize()); // tablecheck @@ -618,10 +723,10 @@ public class TurnControlTest { Stone blackThree = new Stone(3, BLACK); Stone blackFour = new Stone(4, BLACK); Stone blackFive = new Stone(5, BLACK); - StoneSet oldSet1 = new StoneSet(Arrays.asList(blueOne, redOne, blackOne, - redTwo, redThree, redFour, blackTwo, blackThree)); - StoneSet oldSet2 = new StoneSet( - Arrays.asList(blueTwo, blackFour, blackFive)); + StoneSet oldSet1 = new StoneSet(Arrays.asList(blueOne, redOne, + blackOne, redTwo, redThree, redFour, blackTwo, blackThree)); + StoneSet oldSet2 = new StoneSet(Arrays.asList(blueTwo, blackFour, + blackFive)); table.drop(oldSet1, new Position(0, 0)); table.drop(oldSet2, new Position(0, 0)); mockHand.drop(blueThree, new Position(0, 0)); @@ -691,7 +796,7 @@ public class TurnControlTest { mockView.playerPanel.handPanel.stoneClickEvent.emit(blueFour, false); mockView.tablePanel.stoneClickEvent.emit(redThree, true); mockView.tablePanel.rightConnectorClickEvent.emit(newSet2); - + // handcheck assertEquals(0, mockHand.getSize()); // tablecheck @@ -734,10 +839,10 @@ public class TurnControlTest { Stone blackThree = new Stone(3, BLACK); Stone blackFour = new Stone(4, BLACK); Stone blackFive = new Stone(5, BLACK); - StoneSet oldSet1 = new StoneSet(Arrays.asList(blueOne, redOne, blackOne, - redTwo, redThree, redFour, blackTwo, blackThree)); - StoneSet oldSet2 = new StoneSet( - Arrays.asList(blueTwo, blackFour, blackFive)); + StoneSet oldSet1 = new StoneSet(Arrays.asList(blueOne, redOne, + blackOne, redTwo, redThree, redFour, blackTwo, blackThree)); + StoneSet oldSet2 = new StoneSet(Arrays.asList(blueTwo, blackFour, + blackFive)); table.drop(oldSet1, new Position(0, 0)); table.drop(oldSet2, new Position(0, 0)); mockHand.drop(blueThree, new Position(0, 0)); |