Commit 7fb576f1 authored by Corentin Guillevic's avatar Corentin Guillevic
Browse files

Refactoring of GameTest

parent 62263f09
......@@ -185,7 +185,7 @@ public class Game implements GameInterface {
this.playersMap.put(pair.getKey(), traque);
}
else {
this.creature = new Creature("Player" + creatureId, creatureId);
this.creature = new Creature(pair.getValue(), pair.getKey());
this.playersMap.put(creatureId, this.creature);
}
}
......@@ -815,7 +815,7 @@ public class Game implements GameInterface {
canPlay = false;
}
}
canPlay = canPlay && creature.getHand().trackingCardPlayedSize() + toPlay.size() > creature.getMaxTrackingCardPlayable();
canPlay = canPlay && creature.getHand().trackingCardPlayedSize() + toPlay.size() <= creature.getMaxTrackingCardPlayable();
return canPlay && creature.getTrackingCardHand().containsAll(toPlay);
}
......
......@@ -8,7 +8,7 @@ import javassist.NotFoundException;
import java.util.*;
public class Reserve {
private Map<Integer, Pair<PlaceCard, Integer>> placeCards;
private final Map<Integer, Pair<PlaceCard, Integer>> placeCards;
public Reserve(List<PlaceCard> cards, int playerNumber) {
placeCards = new HashMap<>();
......@@ -112,10 +112,40 @@ public class Reserve {
public void add(PlaceCard placeCard) {
int cardNumber = placeCard.getNumber();
if(cardNumber<= 5 && cardNumber > 10) {
if(cardNumber<= 5 || cardNumber > 10) {
throw new IllegalArgumentException("PlaceCard in reserve are place cards 6 to 10");
}
int number = placeCards.get(cardNumber).getValue() + 1;
placeCards.put(cardNumber, new Pair<>(placeCard, number));
}
@Override
public boolean equals(Object obj) {
if(obj == this){
return true;
}
if(obj == null || ! (obj instanceof Reserve)){
return false;
}
System.out.println("ok");
Reserve reserve = (Reserve) obj;
return placeCards.equals(reserve.getPlaceCards());
}
@Override
public String toString() {
String res = "Reserve(";
Iterator<Map.Entry<Integer, Pair<PlaceCard, Integer>>> iterator = placeCards.entrySet().iterator();
Map.Entry<Integer, Pair<PlaceCard, Integer>> aux;
while (iterator.hasNext()) {
aux = iterator.next();
res += aux.getValue().getKey() + "(" + aux.getValue().getValue() + ")";
if(iterator.hasNext()) {
res += ", ";
}
}
res += ")";
return res;
}
}
package fr.univnantes.alma.server.game;
import fr.univnantes.alma.server.game.item.Phase;
import fr.univnantes.alma.server.game.item.board.Board;
import fr.univnantes.alma.server.game.utilitary.request.*;
import fr.univnantes.alma.server.user.User;
import fr.univnantes.alma.thrift.GameNotFound;
import fr.univnantes.alma.thrift.InvalidOperationException;
import fr.univnantes.alma.thrift.Response;
import org.checkerframework.checker.units.qual.A;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
......@@ -42,7 +40,7 @@ class RoomServiceControllerTest {
}
@Test
void testAddRoom_alreadyExist() throws InvalidOperationException {
void testAddRoom_alreadyExist() {
Room room = mock(Room.class);
when(room.getRoomId()).thenReturn("900");
assertFalse(roomServiceController.addRoom(room));
......@@ -93,7 +91,7 @@ class RoomServiceControllerTest {
}
@Test
void testStartGame_playerNotInARoom() throws GameNotFound {
void testStartGame_playerNotInARoom() {
Response response = roomServiceController.startGame(user1, 1, null, null);
assertEquals(new Response(false, "Player is not in a room"), response);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment