Selecting/collecting on table (without range)
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@124 72836036-5685-4462-b002-a69064685172
This commit is contained in:
parent
fe019e5eae
commit
88766c6df2
3 changed files with 159 additions and 0 deletions
|
@ -7,8 +7,10 @@ import java.util.List;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
import jrummikub.model.MockTable;
|
||||||
import jrummikub.model.Stone;
|
import jrummikub.model.Stone;
|
||||||
import jrummikub.model.StoneColor;
|
import jrummikub.model.StoneColor;
|
||||||
|
import jrummikub.model.StoneSet;
|
||||||
import jrummikub.util.Event;
|
import jrummikub.util.Event;
|
||||||
import jrummikub.util.IEvent;
|
import jrummikub.util.IEvent;
|
||||||
import jrummikub.util.IListener;
|
import jrummikub.util.IListener;
|
||||||
|
@ -42,12 +44,14 @@ public class TurnControlTest {
|
||||||
|
|
||||||
MockView mockView;
|
MockView mockView;
|
||||||
MockTimer mockTimer;
|
MockTimer mockTimer;
|
||||||
|
MockTable mockTable;
|
||||||
boolean eventFired;
|
boolean eventFired;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
mockView = new MockView();
|
mockView = new MockView();
|
||||||
mockTimer = new MockTimer();
|
mockTimer = new MockTimer();
|
||||||
|
mockTable = new MockTable();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -186,6 +190,91 @@ public class TurnControlTest {
|
||||||
assertCollection(new ArrayList<Stone>());
|
assertCollection(new ArrayList<Stone>());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void selectStoneOnTable() {
|
||||||
|
TurnControl testControl = new TurnControl(null, null, mockView,
|
||||||
|
mockTimer);
|
||||||
|
|
||||||
|
Stone firstStone = new Stone(StoneColor.RED);
|
||||||
|
|
||||||
|
// Select first stone
|
||||||
|
mockView.tablePanel.stoneClickEvent.emit(firstStone, false);
|
||||||
|
|
||||||
|
assertCollection(Arrays.asList(firstStone));
|
||||||
|
|
||||||
|
// Select second stone
|
||||||
|
Stone secondStone = new Stone(StoneColor.BLACK);
|
||||||
|
mockView.tablePanel.stoneClickEvent.emit(secondStone, false);
|
||||||
|
|
||||||
|
assertCollection(Arrays.asList(secondStone));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void collectStoneOnTable() {
|
||||||
|
TurnControl testControl = new TurnControl(null, null, mockView,
|
||||||
|
mockTimer);
|
||||||
|
|
||||||
|
Stone firstStone = new Stone(StoneColor.RED);
|
||||||
|
|
||||||
|
// Select first stone
|
||||||
|
mockView.tablePanel.stoneClickEvent.emit(firstStone, true);
|
||||||
|
|
||||||
|
assertCollection(Arrays.asList(firstStone));
|
||||||
|
|
||||||
|
// Select second stone
|
||||||
|
Stone secondStone = new Stone(StoneColor.BLACK);
|
||||||
|
mockView.tablePanel.stoneClickEvent.emit(secondStone, true);
|
||||||
|
|
||||||
|
assertCollection(Arrays.asList(firstStone, secondStone));
|
||||||
|
|
||||||
|
// De-select first stone
|
||||||
|
mockView.tablePanel.stoneClickEvent.emit(firstStone, true);
|
||||||
|
|
||||||
|
assertCollection(Arrays.asList(secondStone));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void selectSetOnTable() {
|
||||||
|
TurnControl testControl = new TurnControl(null, mockTable, mockView,
|
||||||
|
mockTimer);
|
||||||
|
|
||||||
|
Stone stone1 = new Stone(StoneColor.RED);
|
||||||
|
Stone stone2 = new Stone(StoneColor.BLACK);
|
||||||
|
StoneSet set1 = new StoneSet(Arrays.asList(stone1, stone2));
|
||||||
|
Stone stone3 = new Stone(1, StoneColor.RED);
|
||||||
|
Stone stone4 = new Stone(1, StoneColor.BLACK);
|
||||||
|
StoneSet set2 = new StoneSet(Arrays.asList(stone3, stone4));
|
||||||
|
|
||||||
|
mockTable.findStoneSet.put(stone1, set1);
|
||||||
|
mockTable.findStoneSet.put(stone4, set2);
|
||||||
|
|
||||||
|
mockView.tablePanel.setClickEvent.emit(stone1, false);
|
||||||
|
assertCollection(Arrays.asList(stone1, stone2));
|
||||||
|
mockView.tablePanel.setClickEvent.emit(stone4, false);
|
||||||
|
assertCollection(Arrays.asList(stone3, stone4));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void collectSetOnTable() {
|
||||||
|
TurnControl testControl = new TurnControl(null, mockTable, mockView,
|
||||||
|
mockTimer);
|
||||||
|
|
||||||
|
Stone stone1 = new Stone(StoneColor.RED);
|
||||||
|
Stone stone2 = new Stone(StoneColor.BLACK);
|
||||||
|
StoneSet set1 = new StoneSet(Arrays.asList(stone1, stone2));
|
||||||
|
Stone stone3 = new Stone(1, StoneColor.RED);
|
||||||
|
Stone stone4 = new Stone(1, StoneColor.BLACK);
|
||||||
|
StoneSet set2 = new StoneSet(Arrays.asList(stone3, stone4));
|
||||||
|
|
||||||
|
mockTable.findStoneSet.put(stone1, set1);
|
||||||
|
mockTable.findStoneSet.put(stone4, set2);
|
||||||
|
|
||||||
|
mockView.tablePanel.setClickEvent.emit(stone1, true);
|
||||||
|
assertCollection(Arrays.asList(stone1, stone2));
|
||||||
|
mockView.tablePanel.setClickEvent.emit(stone4, true);
|
||||||
|
assertCollection(Arrays.asList(stone1, stone2, stone3, stone4));
|
||||||
|
}
|
||||||
|
|
||||||
private void assertCollection(List<Stone> expected) {
|
private void assertCollection(List<Stone> expected) {
|
||||||
ArrayList<Stone> selectedStones = new ArrayList<Stone>(
|
ArrayList<Stone> selectedStones = new ArrayList<Stone>(
|
||||||
|
|
64
test/jrummikub/model/MockTable.java
Normal file
64
test/jrummikub/model/MockTable.java
Normal file
|
@ -0,0 +1,64 @@
|
||||||
|
package jrummikub.model;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import jrummikub.util.Pair;
|
||||||
|
import jrummikub.view.MockStoneCollectionPanel;
|
||||||
|
|
||||||
|
public class MockTable implements ITable {
|
||||||
|
public Map<Stone, StoneSet> findStoneSet = new HashMap<Stone, StoneSet>();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void pickUpStone(Stone stone) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isValid() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public StoneSet pickUp(Position position) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void drop(StoneSet object, Position position) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Position getPosition(StoneSet object) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void pickUp(StoneSet object) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Iterator<Pair<StoneSet, Position>> iterator() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public StoneSet findStoneSet(Stone stone) {
|
||||||
|
return findStoneSet.get(stone);
|
||||||
|
}
|
||||||
|
|
||||||
|
public MockTable clone() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -6,16 +6,22 @@ import jrummikub.model.Position;
|
||||||
import jrummikub.model.Stone;
|
import jrummikub.model.Stone;
|
||||||
import jrummikub.model.StoneSet;
|
import jrummikub.model.StoneSet;
|
||||||
import jrummikub.util.Event1;
|
import jrummikub.util.Event1;
|
||||||
|
import jrummikub.util.Event2;
|
||||||
import jrummikub.util.IEvent1;
|
import jrummikub.util.IEvent1;
|
||||||
import jrummikub.util.IEvent2;
|
import jrummikub.util.IEvent2;
|
||||||
|
|
||||||
public class MockTablePanel implements ITablePanel {
|
public class MockTablePanel implements ITablePanel {
|
||||||
|
|
||||||
|
public Event2<Stone, Boolean> stoneClickEvent = new Event2<Stone, Boolean>();
|
||||||
|
public Event2<Stone, Boolean> setClickEvent = new Event2<Stone, Boolean>();
|
||||||
|
|
||||||
public MockStoneCollectionPanel stoneCollectionPanel = new MockStoneCollectionPanel();
|
public MockStoneCollectionPanel stoneCollectionPanel = new MockStoneCollectionPanel();
|
||||||
public String leftPlayerName;
|
public String leftPlayerName;
|
||||||
public String topPlayerName;
|
public String topPlayerName;
|
||||||
public String rightPlayerName;
|
public String rightPlayerName;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IEvent2<Stone, Boolean> getStoneClickEvent() {
|
public IEvent2<Stone, Boolean> getStoneClickEvent() {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
|
|
Reference in a new issue