[Cruce-commit] SF.net SVN: cruce:[104] Java/trunk/src/prc/bubulina/cruce
Status: Beta
Brought to you by:
caiusb
|
From: <ali...@us...> - 2010-04-07 18:09:24
|
Revision: 104
http://cruce.svn.sourceforge.net/cruce/?rev=104&view=rev
Author: alinposho
Date: 2010-04-07 18:09:17 +0000 (Wed, 07 Apr 2010)
Log Message:
-----------
Am adaugat teste pentru computeScore() din clasa Team. De asemenea in clasa Team am adaugat metoda addAnunt(int value) pentru a adauga anunturi echipei. De asemenea metoda este si testata.
Modified Paths:
--------------
Java/trunk/src/prc/bubulina/cruce/remote/Card.java
Java/trunk/src/prc/bubulina/cruce/server/Team.java
Java/trunk/src/prc/bubulina/cruce/tests/server/StartGameLogicTest.java
Added Paths:
-----------
Java/trunk/src/prc/bubulina/cruce/tests/server/TeamTest.java
Modified: Java/trunk/src/prc/bubulina/cruce/remote/Card.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/remote/Card.java 2010-04-07 17:31:52 UTC (rev 103)
+++ Java/trunk/src/prc/bubulina/cruce/remote/Card.java 2010-04-07 18:09:17 UTC (rev 104)
@@ -8,7 +8,13 @@
private static Color tromf;
public Card(int value, Color color) {
- this.color = color;
+ this.color = color;
+ if(value != 0 && value != 2 && value != 3 && value != 4 && value != 10 &&
+ value != 11)
+ {
+ throw new IllegalArgumentException("Card value is not within the set: " +
+ "{0 , 2, 3, 4, 10, 11}!\n");
+ }
this.value = value;
}
Modified: Java/trunk/src/prc/bubulina/cruce/server/Team.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/server/Team.java 2010-04-07 17:31:52 UTC (rev 103)
+++ Java/trunk/src/prc/bubulina/cruce/server/Team.java 2010-04-07 18:09:17 UTC (rev 104)
@@ -36,6 +36,16 @@
this.goal = goal;
}
+ public void addAnunt(int value)
+ {
+ if(value != 40 && value != 20)
+ {
+ throw new IllegalArgumentException("The value filed is not one of 20 or 40!\n");
+ }
+
+ anunturi += value;
+ }
+
public int computeScore() {
int result = anunturi;
@@ -61,4 +71,5 @@
goal = 0;
cardsTaken.clear();
}
+
}
\ No newline at end of file
Modified: Java/trunk/src/prc/bubulina/cruce/tests/server/StartGameLogicTest.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/tests/server/StartGameLogicTest.java 2010-04-07 17:31:52 UTC (rev 103)
+++ Java/trunk/src/prc/bubulina/cruce/tests/server/StartGameLogicTest.java 2010-04-07 18:09:17 UTC (rev 104)
@@ -8,7 +8,6 @@
import org.junit.Before;
import org.junit.Test;
-import prc.bubulina.cruce.remote.Player;
import prc.bubulina.cruce.server.ServerSidePlayer;
import prc.bubulina.cruce.server.StartGameLogic;
import prc.bubulina.cruce.server.Team;
@@ -127,10 +126,4 @@
}
}
- @Test
- public void testPlayerReady()
- {
- fail("Not yet implemented");
- }
-
}
Added: Java/trunk/src/prc/bubulina/cruce/tests/server/TeamTest.java
===================================================================
--- Java/trunk/src/prc/bubulina/cruce/tests/server/TeamTest.java (rev 0)
+++ Java/trunk/src/prc/bubulina/cruce/tests/server/TeamTest.java 2010-04-07 18:09:17 UTC (rev 104)
@@ -0,0 +1,157 @@
+package prc.bubulina.cruce.tests.server;
+
+import static org.junit.Assert.*;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import prc.bubulina.cruce.remote.Card;
+import prc.bubulina.cruce.remote.Color;
+import prc.bubulina.cruce.server.Team;
+
+public class TeamTest
+{
+ private Team team;
+ private List<Card> cardsTaken;
+ private int goal;
+
+ @Before
+ public void setUp() throws Exception
+ {
+ team = new Team();
+ cardsTaken = new ArrayList<Card>();
+ }
+
+ @Test
+ public void testComputeScore_NoAnunt_NoCardsTAken_NoGoal()
+ {
+ assertEquals(0, team.computeScore());
+ assertEquals(goal, team.getOverallScore());
+ }
+
+ @Test
+ public void testComputeScore_NoAnunt_NoCardsTAken_WithGoalUnfulfilled()
+ {
+ goal = 10;
+ team.setGoal(goal);
+ assertEquals(-goal, team.computeScore());
+ assertEquals(-goal, team.getOverallScore());
+ }
+
+ @Test
+ public void testComputeScore_NoAnunt_CardsTaken_WithGoalUnfulfilled()
+ {
+ goal = 2;
+ team.setGoal(goal);
+
+ int takenCardsValue = 0;
+
+ for(int i = 0; i < 11; i++)
+ {
+ Card card;
+ try
+ {
+ card = new Card(i * 2 % 3, Color.ROSU);
+ }
+ catch (IllegalArgumentException e)
+ {
+ card = new Card(0, Color.ROSU);
+ }
+
+ takenCardsValue += card.getValue();
+ team.addCard(card);
+ }
+
+ //Precondition check
+ assertTrue(takenCardsValue < 66);
+
+ //actual test
+ assertEquals(-goal, team.computeScore());
+ assertEquals(-goal, team.getOverallScore());
+ }
+
+ @Test
+ public void testComputeScore_Anunturi_CardsTaken_WithGoalFulfilled()
+ {
+ //set up
+ goal = 6;
+ team.setGoal(goal);
+
+ int takenCardsValue = 0;
+
+ //adding some cards to the team
+ for(int i = 0; i < 66; i++)
+ {
+ Card card;
+ try
+ {
+ card = new Card(i * 2 % 12, Color.ROSU);
+ }
+ catch (IllegalArgumentException e)
+ {
+ card = new Card(0, Color.ROSU);
+ }
+
+ takenCardsValue += card.getValue();
+ team.addCard(card);
+ }
+
+ //adding some anunturi - Notice how we do not check for only one 40 and
+ //maximum 3 20's
+ team.addAnunt(40);
+ takenCardsValue += 40;
+ team.addAnunt(20);
+ takenCardsValue += 20;
+ team.addAnunt(40);
+ takenCardsValue += 40;
+ team.addAnunt(20);
+ takenCardsValue += 20;
+ team.addAnunt(20);
+ takenCardsValue += 20;
+ team.addAnunt(40);
+ takenCardsValue += 40;
+
+ //Precondition check
+ assertTrue(takenCardsValue >= 33 * 6);
+
+ //actual test
+ int actual = team.computeScore();
+ assertTrue(goal <= actual);
+ assertEquals(takenCardsValue / 33, actual);
+ assertEquals(takenCardsValue / 33, team.getOverallScore());
+ }
+
+ @Test
+ public void testAddAnunt()
+ {
+ //trying to add an invalid anunt
+ try
+ {
+ team.addAnunt(100);
+ fail("100 is an invalid anunt value so an exception should have been raised.");
+ }
+ catch (IllegalArgumentException e)
+ {
+ String expected = "The value filed is not one of 20 or 40!\n";
+ assertEquals(expected, e.getMessage());
+ }
+
+ //Adding a 40 and a 20 anunt
+ team.addAnunt(40);
+ team.addAnunt(20);
+
+ //Notice how we can add more that one 40 and 3 20's
+ team = new Team();
+ team.addAnunt(40);
+ team.addAnunt(20);
+ team.addAnunt(20);
+ team.addAnunt(20);
+ team.addAnunt(40);
+ team.addAnunt(20);
+
+ }
+
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|