Testfall für rangeclick auf der Hand

git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@196 72836036-5685-4462-b002-a69064685172
This commit is contained in:
Ida Massow 2011-05-09 21:19:04 +02:00
parent a6a5388560
commit 223f6d7e85
2 changed files with 136 additions and 31 deletions

View file

@ -13,6 +13,7 @@ import jrummikub.util.Pair;
public class MockHandPanel implements IHandPanel { public class MockHandPanel implements IHandPanel {
public Event2<Stone, Boolean> stoneClickEvent = new Event2<Stone, Boolean>(); public Event2<Stone, Boolean> stoneClickEvent = new Event2<Stone, Boolean>();
public List<Pair<Stone, Position>> stones; public List<Pair<Stone, Position>> stones;
public Event2<Stone, Boolean> rangeClickEvent = new Event2<Stone, Boolean>();
@Override @Override
public IEvent2<Stone, Boolean> getStoneClickEvent() { public IEvent2<Stone, Boolean> getStoneClickEvent() {
@ -21,8 +22,7 @@ public class MockHandPanel implements IHandPanel {
@Override @Override
public IEvent2<Stone, Boolean> getRangeClickEvent() { public IEvent2<Stone, Boolean> getRangeClickEvent() {
// TODO Auto-generated method stub return rangeClickEvent;
return null;
} }
@Override @Override
@ -49,13 +49,13 @@ public class MockHandPanel implements IHandPanel {
@Override @Override
public void setHandWidth(int width) { public void setHandWidth(int width) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
} }
@Override @Override
public void setHandHeight(int height) { public void setHandHeight(int height) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
} }
} }

View file

@ -111,9 +111,10 @@ public class TurnControlTest {
public void showInitialHand() { public void showInitialHand() {
mockView.displayStartTurnPanel = true; mockView.displayStartTurnPanel = true;
List<Pair<Stone, Position>> stones = Arrays.asList( List<Pair<Stone, Position>> stones = Arrays
new Pair<Stone, Position>(new Stone(RED), new Position(0, 0)), .asList(new Pair<Stone, Position>(new Stone(RED), new Position(
new Pair<Stone, Position>(new Stone(BLACK), new Position(1, 0))); 0, 0)), new Pair<Stone, Position>(new Stone(BLACK),
new Position(1, 0)));
mockHand.iterable = stones; mockHand.iterable = stones;
@ -239,8 +240,8 @@ public class TurnControlTest {
mockView.playerPanel.handPanel.stoneClickEvent.emit(firstStone, true); mockView.playerPanel.handPanel.stoneClickEvent.emit(firstStone, true);
mockView.playerPanel.handPanel.stoneClickEvent.emit(secondStone, true); mockView.playerPanel.handPanel.stoneClickEvent.emit(secondStone, true);
mockView.tablePanel.stoneCollectionPanel.stoneClickEvent.emit(firstStone, mockView.tablePanel.stoneCollectionPanel.stoneClickEvent.emit(
false); firstStone, false);
assertCollection(Arrays.asList(secondStone)); assertCollection(Arrays.asList(secondStone));
} }
@ -255,8 +256,8 @@ public class TurnControlTest {
mockView.playerPanel.handPanel.stoneClickEvent.emit(firstStone, true); mockView.playerPanel.handPanel.stoneClickEvent.emit(firstStone, true);
mockView.playerPanel.handPanel.stoneClickEvent.emit(secondStone, true); mockView.playerPanel.handPanel.stoneClickEvent.emit(secondStone, true);
mockView.tablePanel.stoneCollectionPanel.stoneClickEvent.emit(firstStone, mockView.tablePanel.stoneCollectionPanel.stoneClickEvent.emit(
true); firstStone, true);
assertCollection(Arrays.asList(secondStone, firstStone)); assertCollection(Arrays.asList(secondStone, firstStone));
} }
@ -271,8 +272,8 @@ public class TurnControlTest {
mockView.playerPanel.handPanel.stoneClickEvent.emit(firstStone, true); mockView.playerPanel.handPanel.stoneClickEvent.emit(firstStone, true);
mockView.playerPanel.handPanel.stoneClickEvent.emit(secondStone, true); mockView.playerPanel.handPanel.stoneClickEvent.emit(secondStone, true);
mockView.tablePanel.stoneCollectionPanel.stoneClickEvent.emit(firstStone, mockView.tablePanel.stoneCollectionPanel.stoneClickEvent.emit(
true); firstStone, true);
mockView.tablePanel.stoneCollectionPanel.setClickEvent.emit(firstStone, mockView.tablePanel.stoneCollectionPanel.setClickEvent.emit(firstStone,
true); true);
@ -374,7 +375,8 @@ public class TurnControlTest {
Stone stone2 = new Stone(2, StoneColor.RED); Stone stone2 = new Stone(2, StoneColor.RED);
Stone stone3 = new Stone(3, StoneColor.RED); Stone stone3 = new Stone(3, StoneColor.RED);
Stone stone4 = new Stone(4, 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(stone1, set1);
mockTable.findStoneSet.put(stone3, set1); mockTable.findStoneSet.put(stone3, set1);
@ -385,7 +387,7 @@ public class TurnControlTest {
assertCollection(Arrays.asList(stone1, stone2, stone3)); assertCollection(Arrays.asList(stone1, stone2, stone3));
} }
@Test @Test
public void rangeSelectOnTable() { public void rangeSelectOnTable() {
testControl.startTurn(); testControl.startTurn();
@ -394,7 +396,8 @@ public class TurnControlTest {
Stone stone2 = new Stone(2, StoneColor.RED); Stone stone2 = new Stone(2, StoneColor.RED);
Stone stone3 = new Stone(3, StoneColor.RED); Stone stone3 = new Stone(3, StoneColor.RED);
Stone stone4 = new Stone(4, 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(stone1, set1);
mockTable.findStoneSet.put(stone3, set1); mockTable.findStoneSet.put(stone3, set1);
@ -416,7 +419,8 @@ public class TurnControlTest {
Stone stone2 = new Stone(2, StoneColor.RED); Stone stone2 = new Stone(2, StoneColor.RED);
Stone stone3 = new Stone(3, StoneColor.RED); Stone stone3 = new Stone(3, StoneColor.RED);
Stone stone4 = new Stone(4, 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(stone1, set1);
mockTable.findStoneSet.put(stone3, set1); mockTable.findStoneSet.put(stone3, set1);
@ -476,6 +480,107 @@ public class TurnControlTest {
assertCollection(Arrays.asList(stone1, stone2)); 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) { private void assertCollection(List<Stone> expected) {
ArrayList<Stone> selectedStones = new ArrayList<Stone>( ArrayList<Stone> selectedStones = new ArrayList<Stone>(
mockView.selectedStones); mockView.selectedStones);
@ -502,10 +607,10 @@ public class TurnControlTest {
Stone blackThree = new Stone(3, BLACK); Stone blackThree = new Stone(3, BLACK);
Stone blackFour = new Stone(4, BLACK); Stone blackFour = new Stone(4, BLACK);
Stone blackFive = new Stone(5, BLACK); Stone blackFive = new Stone(5, BLACK);
StoneSet oldSet1 = new StoneSet(Arrays.asList(blueOne, redOne, blackOne, StoneSet oldSet1 = new StoneSet(Arrays.asList(blueOne, redOne,
redTwo, redThree, redFour, blackTwo, blackThree)); blackOne, redTwo, redThree, redFour, blackTwo, blackThree));
StoneSet oldSet2 = new StoneSet( StoneSet oldSet2 = new StoneSet(Arrays.asList(blueTwo, blackFour,
Arrays.asList(blueTwo, blackFour, blackFive)); blackFive));
table.drop(oldSet1, new Position(0, 0)); table.drop(oldSet1, new Position(0, 0));
table.drop(oldSet2, new Position(0, 0)); table.drop(oldSet2, new Position(0, 0));
mockHand.drop(blueThree, 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.playerPanel.handPanel.stoneClickEvent.emit(blueFour, false);
mockView.tablePanel.stoneClickEvent.emit(redOne, true); mockView.tablePanel.stoneClickEvent.emit(redOne, true);
mockView.tablePanel.leftConnectorClickEvent.emit(newSet2); mockView.tablePanel.leftConnectorClickEvent.emit(newSet2);
// handcheck // handcheck
assertEquals(0, mockHand.getSize()); assertEquals(0, mockHand.getSize());
// tablecheck // tablecheck
@ -618,10 +723,10 @@ public class TurnControlTest {
Stone blackThree = new Stone(3, BLACK); Stone blackThree = new Stone(3, BLACK);
Stone blackFour = new Stone(4, BLACK); Stone blackFour = new Stone(4, BLACK);
Stone blackFive = new Stone(5, BLACK); Stone blackFive = new Stone(5, BLACK);
StoneSet oldSet1 = new StoneSet(Arrays.asList(blueOne, redOne, blackOne, StoneSet oldSet1 = new StoneSet(Arrays.asList(blueOne, redOne,
redTwo, redThree, redFour, blackTwo, blackThree)); blackOne, redTwo, redThree, redFour, blackTwo, blackThree));
StoneSet oldSet2 = new StoneSet( StoneSet oldSet2 = new StoneSet(Arrays.asList(blueTwo, blackFour,
Arrays.asList(blueTwo, blackFour, blackFive)); blackFive));
table.drop(oldSet1, new Position(0, 0)); table.drop(oldSet1, new Position(0, 0));
table.drop(oldSet2, new Position(0, 0)); table.drop(oldSet2, new Position(0, 0));
mockHand.drop(blueThree, 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.playerPanel.handPanel.stoneClickEvent.emit(blueFour, false);
mockView.tablePanel.stoneClickEvent.emit(redThree, true); mockView.tablePanel.stoneClickEvent.emit(redThree, true);
mockView.tablePanel.rightConnectorClickEvent.emit(newSet2); mockView.tablePanel.rightConnectorClickEvent.emit(newSet2);
// handcheck // handcheck
assertEquals(0, mockHand.getSize()); assertEquals(0, mockHand.getSize());
// tablecheck // tablecheck
@ -734,10 +839,10 @@ public class TurnControlTest {
Stone blackThree = new Stone(3, BLACK); Stone blackThree = new Stone(3, BLACK);
Stone blackFour = new Stone(4, BLACK); Stone blackFour = new Stone(4, BLACK);
Stone blackFive = new Stone(5, BLACK); Stone blackFive = new Stone(5, BLACK);
StoneSet oldSet1 = new StoneSet(Arrays.asList(blueOne, redOne, blackOne, StoneSet oldSet1 = new StoneSet(Arrays.asList(blueOne, redOne,
redTwo, redThree, redFour, blackTwo, blackThree)); blackOne, redTwo, redThree, redFour, blackTwo, blackThree));
StoneSet oldSet2 = new StoneSet( StoneSet oldSet2 = new StoneSet(Arrays.asList(blueTwo, blackFour,
Arrays.asList(blueTwo, blackFour, blackFive)); blackFive));
table.drop(oldSet1, new Position(0, 0)); table.drop(oldSet1, new Position(0, 0));
table.drop(oldSet2, new Position(0, 0)); table.drop(oldSet2, new Position(0, 0));
mockHand.drop(blueThree, new Position(0, 0)); mockHand.drop(blueThree, new Position(0, 0));