From d5a8b2204c7b717e0b1f24fed0892091835356ed Mon Sep 17 00:00:00 2001 From: Jannis Harder Date: Tue, 24 May 2011 01:51:58 +0200 Subject: Test if initial melds are possible git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@265 72836036-5685-4462-b002-a69064685172 --- test/jrummikub/model/HandTest.java | 123 +++++++++++++++++++++++++++++++++++-- 1 file changed, 118 insertions(+), 5 deletions(-) (limited to 'test/jrummikub/model') diff --git a/test/jrummikub/model/HandTest.java b/test/jrummikub/model/HandTest.java index 5be48d6..5aa662c 100644 --- a/test/jrummikub/model/HandTest.java +++ b/test/jrummikub/model/HandTest.java @@ -1,9 +1,14 @@ package jrummikub.model; -import static jrummikub.model.StoneColor.*; +import static jrummikub.model.StoneColor.BLACK; +import static jrummikub.model.StoneColor.BLUE; +import static jrummikub.model.StoneColor.ORANGE; +import static jrummikub.model.StoneColor.RED; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import org.junit.Before; @@ -14,7 +19,7 @@ import org.junit.Test; */ public class HandTest { - Hand hand; + IHand hand; /** */ @Before @@ -104,14 +109,14 @@ public class HandTest { } Stone newStone = new Stone(RED); hand.drop(newStone, new Position(12.5f, 1)); - + for (int i = 0; i < 13; i++) { assertEquals(new Position(i, 1), hand.getPosition(rowStones.get(i))); } assertEquals(new Position(13, 1), hand.getPosition(newStone)); assertEquals(new Position(0, 2), hand.getPosition(rowStones.get(13))); } - + /** */ @Test public void testCountPoints() { @@ -123,7 +128,115 @@ public class HandTest { hand.drop(stone1, new Position(0, 0)); hand.drop(stone2, new Position(0, 0)); hand.drop(stone3, new Position(0, 0)); - + assertEquals(56, hand.getStonePoints()); } + + private void testInitialMeld(boolean possible, List handStones) { + for (Stone stone : handStones) { + hand.drop(stone, new Position(0, 0)); + } + assertTrue(possible == hand.isInitialMeldPossible()); + } + + /** */ + @Test + public void testNoValid() { + testInitialMeld(false, Arrays.asList(new Stone(8, RED), new Stone(9, + RED), new Stone(10, RED), new Stone(12, RED), + new Stone(13, RED))); + testInitialMeld(false, Arrays.asList(new Stone(10, RED), new Stone(10, + BLACK), new Stone(11, RED), new Stone(11, BLACK))); + testInitialMeld(false, Arrays.asList(new Stone(10, RED), new Stone(10, + RED), new Stone(10, BLACK), new Stone(11, RED), new Stone(11, + BLACK))); + + testInitialMeld(false, Arrays.asList(new Stone(10, RED), new Stone(11, + BLACK), new Stone(12, RED))); + } + + /** */ + @Test + public void testNotEnoughPoints() { + testInitialMeld(false, Arrays.asList(new Stone(8, RED), new Stone(9, + RED), new Stone(10, RED))); + testInitialMeld(false, Arrays.asList(new Stone(1, RED), new Stone(2, + RED), new Stone(3, RED), new Stone(4, RED))); + testInitialMeld(false, Arrays.asList(new Stone(1, RED), new Stone(2, + RED), new Stone(3, RED), new Stone(1, BLACK), new Stone(2, + BLACK), new Stone(3, BLACK))); + } + + /** */ + @Test + public void testNotEnoughPointsWithJoker() { + testInitialMeld(false, Arrays.asList(new Stone(8, RED), new Stone(9, + RED), new Stone(RED), new Stone(3, BLACK))); + testInitialMeld(false, Arrays.asList(new Stone(4, RED), new Stone(5, + RED), new Stone(4, BLACK), new Stone(5, BLACK), new Stone(RED))); + } + + /** */ + @Test + public void testNotEnoughPointsWithTwoJokers() { + testInitialMeld(false, Arrays.asList(new Stone(1, RED), new Stone(2, + BLUE), new Stone(3, BLACK), new Stone(RED), new Stone(BLACK))); + testInitialMeld(false, Arrays.asList(new Stone(8, RED), new Stone(RED), + new Stone(BLACK))); + } + + /** */ + @Test + public void testValid() { + testInitialMeld(true, Arrays.asList(new Stone(11, RED), new Stone(12, + RED), new Stone(13, RED))); + testInitialMeld(true, Arrays.asList(new Stone(4, RED), + new Stone(5, RED), new Stone(6, RED), new Stone(5, ORANGE), + new Stone(5, BLACK), new Stone(5, BLUE))); + testInitialMeld(true, Arrays.asList(new Stone(10, RED), new Stone(10, + BLACK), new Stone(10, ORANGE))); + } + + /** */ + @Test + public void testValidWithJoker() { + testInitialMeld(true, Arrays.asList(new Stone(11, RED), new Stone(RED), + new Stone(13, RED))); + testInitialMeld(true, Arrays.asList(new Stone(10, RED), + new Stone(BLACK), new Stone(10, ORANGE))); + testInitialMeld(true, Arrays.asList(new Stone(4, RED), + new Stone(5, RED), new Stone(6, RED), new Stone(5, BLACK), + new Stone(5, BLUE), new Stone(RED))); + } + + /** */ + @Test + public void testValidWithTwoJokers() { + testInitialMeld(true, Arrays.asList(new Stone(9, RED), new Stone(RED), + new Stone(BLACK))); + } + + /** */ + @Test + public void testValidHuge() { + List stones = new ArrayList(); + for (int i = 1; i <= 10; i++) { + stones.add(new Stone(i, RED)); + stones.add(new Stone(i, BLACK)); + } + testInitialMeld(true, stones); + } + + /** */ + @Test + public void testInvalidHuge() { + testInitialMeld(false, Arrays.asList(new Stone(1, RED), new Stone(2, + RED), new Stone(4, RED), new Stone(6, RED), new Stone(8, RED), + new Stone(10, RED), new Stone(13, RED), new Stone(1, BLACK), + new Stone(2, BLACK), new Stone(4, BLACK), new Stone(5, BLACK), + new Stone(8, BLACK), new Stone(9, BLACK), new Stone(12, BLACK), + new Stone(3, BLUE), new Stone(5, BLUE), new Stone(7, BLUE), + new Stone(11, BLUE), new Stone(RED))); + } + } -- cgit v1.2.3