summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2011-05-10 00:28:06 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2011-05-10 00:28:06 +0200
commit3338af2d439019fedced4be5b105ce06129a3712 (patch)
tree6c071a18fcabb1e2f8f0af7d8d323b7dc4a1148c /test
parent8e73d1ab3734b4e5b88edcf024ffc37bd03225e6 (diff)
downloadJRummikub-3338af2d439019fedced4be5b105ce06129a3712.tar
JRummikub-3338af2d439019fedced4be5b105ce06129a3712.zip
Add tests for hand auto-sort
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@203 72836036-5685-4462-b002-a69064685172
Diffstat (limited to 'test')
-rw-r--r--test/jrummikub/control/TurnControlTest.java107
1 files changed, 107 insertions, 0 deletions
diff --git a/test/jrummikub/control/TurnControlTest.java b/test/jrummikub/control/TurnControlTest.java
index fdc43fc..b4766b6 100644
--- a/test/jrummikub/control/TurnControlTest.java
+++ b/test/jrummikub/control/TurnControlTest.java
@@ -10,6 +10,7 @@ import static org.junit.Assert.assertTrue;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collections;
import java.util.Iterator;
import java.util.List;
@@ -909,4 +910,110 @@ public class TurnControlTest {
checkTableDisplay(table);
checkHandDisplay(mockHand);
}
+
+ @Test
+ public void testSortByGroups() {
+ Stone red1 = new Stone(1, StoneColor.RED);
+ Stone blue2 = new Stone(2, StoneColor.BLUE);
+ Stone red4 = new Stone(4, StoneColor.RED);
+ Stone red3 = new Stone(3, StoneColor.RED);
+ Stone orange10 = new Stone(10, StoneColor.ORANGE);
+ Stone blue1 = new Stone(1, StoneColor.BLUE);
+ Stone blue4 = new Stone(4, StoneColor.BLUE);
+ Stone blue4a = new Stone(4, StoneColor.BLUE);
+ Stone joker = new Stone(StoneColor.BLACK);
+ Stone black5 = new Stone(5, StoneColor.BLACK);
+ Stone orange13 = new Stone(13, StoneColor.ORANGE);
+ Stone red11 = new Stone(11, StoneColor.RED);
+ Stone black10 = new Stone(10, StoneColor.BLACK);
+ mockHand.drop(red1, new Position(0, 0));
+ mockHand.drop(blue2, new Position(0, 0));
+ mockHand.drop(red4, new Position(0, 0));
+ mockHand.drop(red3, new Position(0, 0));
+ mockHand.drop(orange10, new Position(0, 0));
+ mockHand.drop(blue1, new Position(0, 0));
+ mockHand.drop(blue4, new Position(0, 0));
+ mockHand.drop(blue4a, new Position(0, 0));
+ mockHand.drop(joker, new Position(0, 0));
+ mockHand.drop(black5, new Position(0, 0));
+ mockHand.drop(orange13, new Position(0, 0));
+ mockHand.drop(red11, new Position(0, 0));
+ mockHand.drop(black10, new Position(0, 0));
+
+ mockView.playerPanel.sortByGroupsEvent.emit();
+
+ List<Pair<Stone, Position>> stones = new ArrayList<Pair<Stone, Position>>(mockHand.stones);
+ Collections.sort(stones, new TurnControl.HandStonePositionComparator());
+
+ assertEquals(stones.size(), 13);
+
+ assertSame(stones.get(0).getFirst(), blue1);
+ assertSame(stones.get(1).getFirst(), red1);
+ assertSame(stones.get(2).getFirst(), blue2);
+ assertSame(stones.get(3).getFirst(), red3);
+
+ assertTrue(stones.get(4).getFirst() == blue4 || stones.get(4).getFirst() == blue4a);
+ assertTrue(stones.get(5).getFirst() == blue4 || stones.get(5).getFirst() == blue4a);
+
+ assertSame(stones.get(6).getFirst(), red4);
+ assertSame(stones.get(7).getFirst(), black5);
+ assertSame(stones.get(8).getFirst(), black10);
+ assertSame(stones.get(9).getFirst(), orange10);
+ assertSame(stones.get(10).getFirst(), red11);
+ assertSame(stones.get(11).getFirst(), orange13);
+ assertSame(stones.get(12).getFirst(), joker);
+ }
+
+ @Test
+ public void testSortByRuns() {
+ Stone red1 = new Stone(1, StoneColor.RED);
+ Stone blue2 = new Stone(2, StoneColor.BLUE);
+ Stone red4 = new Stone(4, StoneColor.RED);
+ Stone red3 = new Stone(3, StoneColor.RED);
+ Stone orange10 = new Stone(10, StoneColor.ORANGE);
+ Stone blue1 = new Stone(1, StoneColor.BLUE);
+ Stone blue4 = new Stone(4, StoneColor.BLUE);
+ Stone blue4a = new Stone(4, StoneColor.BLUE);
+ Stone joker = new Stone(StoneColor.BLACK);
+ Stone black5 = new Stone(5, StoneColor.BLACK);
+ Stone orange13 = new Stone(13, StoneColor.ORANGE);
+ Stone red11 = new Stone(11, StoneColor.RED);
+ Stone black10 = new Stone(10, StoneColor.BLACK);
+ mockHand.drop(red1, new Position(0, 0));
+ mockHand.drop(blue2, new Position(0, 0));
+ mockHand.drop(red4, new Position(0, 0));
+ mockHand.drop(red3, new Position(0, 0));
+ mockHand.drop(orange10, new Position(0, 0));
+ mockHand.drop(blue1, new Position(0, 0));
+ mockHand.drop(blue4, new Position(0, 0));
+ mockHand.drop(blue4a, new Position(0, 0));
+ mockHand.drop(joker, new Position(0, 0));
+ mockHand.drop(black5, new Position(0, 0));
+ mockHand.drop(orange13, new Position(0, 0));
+ mockHand.drop(red11, new Position(0, 0));
+ mockHand.drop(black10, new Position(0, 0));
+
+ mockView.playerPanel.sortByRunsEvent.emit();
+
+ List<Pair<Stone, Position>> stones = new ArrayList<Pair<Stone, Position>>(mockHand.stones);
+ Collections.sort(stones, new TurnControl.HandStonePositionComparator());
+
+ assertEquals(stones.size(), 13);
+
+ assertSame(stones.get(0).getFirst(), black5);
+ assertSame(stones.get(1).getFirst(), black10);
+ assertSame(stones.get(2).getFirst(), orange10);
+ assertSame(stones.get(3).getFirst(), orange13);
+ assertSame(stones.get(4).getFirst(), blue1);
+ assertSame(stones.get(5).getFirst(), blue2);
+
+ assertTrue(stones.get(6).getFirst() == blue4 || stones.get(6).getFirst() == blue4a);
+ assertTrue(stones.get(7).getFirst() == blue4 || stones.get(7).getFirst() == blue4a);
+
+ assertSame(stones.get(8).getFirst(), red1);
+ assertSame(stones.get(9).getFirst(), red3);
+ assertSame(stones.get(10).getFirst(), red4);
+ assertSame(stones.get(11).getFirst(), red11);
+ assertSame(stones.get(12).getFirst(), joker);
+ }
}