package scotlandyard;
import junit.framework.Assert;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import scotlandyard.engine.impl.Engine;
import scotlandyard.engine.impl.Game;
import scotlandyard.engine.spec.IBMap;
import scotlandyard.engine.spec.IUser;
import scotlandyard.servlets.beans.WebUserBean;
public class PlayerTest {
String mrxEmail = "something";
String detectiveEmail = "something else";
String mrxName = "random";
String detectiveName = "other random";
String mrxHash = Engine.md5(mrxEmail);
String detectiveHash = Engine.md5(detectiveEmail);
String gameId = "New Game";
public PlayerTest() throws Exception{
// TODO Auto-generated constructor stub
}
@Before
public void setup() throws Exception {
new WebUserBean();
String mp = "web/maps/palmerstonNorth.xml";
gameId=(gameId==null||"optional".equals(gameId)?System.currentTimeMillis()+"":gameId);
Game game = new Game(gameId,mp);
Engine.instance().games.put(game.getId(),game);
game.setMapPath("/maps/palmerstonNorth.xml");
IUser mrx = Engine.instance().login(mrxEmail,mrxName,"0");
IUser detective = Engine.instance().login(detectiveEmail,detectiveName,"1");
game.addPlayer(mrx,true);
game.addPlayer(detective,false);
game.start(game.getPlayer(mrxHash));
}
@After
public void tearDown() throws Exception{
Engine.instance().logout(mrxHash);
Engine.instance().logout(detectiveHash);
}
@Test
public void testGetTicket(){
Assert.assertTrue(Engine.instance().games.get(gameId).getPlayer(detectiveHash).getTickets(IBMap.BUS) == 8);
Assert.assertTrue(Engine.instance().games.get(gameId).getPlayer(detectiveHash).getTickets(IBMap.TAXI) == 10);
Assert.assertTrue(Engine.instance().games.get(gameId).getPlayer(detectiveHash).getTickets(IBMap.UG) == 4);
Assert.assertTrue(Engine.instance().games.get(gameId).getPlayer(detectiveHash).getTickets(IBMap.WATER) == 0);
Assert.assertTrue(Engine.instance().games.get(gameId).getPlayer(mrxHash).getTickets(IBMap.BUS) == 3);
Assert.assertTrue(Engine.instance().games.get(gameId).getPlayer(mrxHash).getTickets(IBMap.TAXI) == 4);
Assert.assertTrue(Engine.instance().games.get(gameId).getPlayer(mrxHash).getTickets(IBMap.UG) == 3);
Assert.assertTrue(Engine.instance().games.get(gameId).getPlayer(mrxHash).getTickets(IBMap.DOUBLE) == 2);
Assert.assertTrue(Engine.instance().games.get(gameId).getPlayer(mrxHash).getTickets(IBMap.WATER) == 3);
}
@Test
public void testIsMrX(){
Assert.assertTrue(Engine.instance().games.get(gameId).getPlayer(mrxHash).isMrx());
Assert.assertFalse(Engine.instance().games.get(gameId).getPlayer(detectiveHash).isMrx());
}
@Test
public void testConsumeTicket(){
Engine.instance().games.get(gameId).getPlayer(mrxHash).consumeTicket(IBMap.TAXI);
Assert.assertTrue(Engine.instance().games.get(gameId).getPlayer(mrxHash).getTickets(IBMap.TAXI)==3);
Engine.instance().games.get(gameId).getPlayer(mrxHash).consumeTicket(IBMap.TAXI);
Assert.assertTrue(Engine.instance().games.get(gameId).getPlayer(mrxHash).getTickets(IBMap.TAXI)==2);
Engine.instance().games.get(gameId).getPlayer(mrxHash).consumeTicket(IBMap.BUS);
Assert.assertTrue(Engine.instance().games.get(gameId).getPlayer(mrxHash).getTickets(IBMap.BUS)==2);
Engine.instance().games.get(gameId).getPlayer(mrxHash).consumeTicket(IBMap.WATER);
Assert.assertTrue(Engine.instance().games.get(gameId).getPlayer(mrxHash).getTickets(IBMap.WATER)==2);
Engine.instance().games.get(gameId).getPlayer(detectiveHash).consumeTicket(IBMap.TAXI);
Assert.assertTrue(Engine.instance().games.get(gameId).getPlayer(detectiveHash).getTickets(IBMap.TAXI)==9);
Engine.instance().games.get(gameId).getPlayer(detectiveHash).consumeTicket(IBMap.TAXI);
Assert.assertTrue(Engine.instance().games.get(gameId).getPlayer(detectiveHash).getTickets(IBMap.TAXI)==8);
}
@Test
public void testSetPosition(){
Engine.instance().games.get(gameId).getPlayer(mrxHash).setPosition(10);
Assert.assertTrue(Engine.instance().games.get(gameId).getPlayer(mrxHash).getPosition() == 10);
Engine.instance().games.get(gameId).getPlayer(detectiveHash).setPosition(5);
Assert.assertTrue(Engine.instance().games.get(gameId).getPlayer(detectiveHash).getPosition() == 5);
}
@Test
public void testSetTickets(){
Engine.instance().games.get(gameId).getPlayer(detectiveHash).setTickets(IBMap.TAXI, 2);
Assert.assertTrue(Engine.instance().games.get(gameId).getPlayer(detectiveHash).getTickets(IBMap.TAXI)==2);
Engine.instance().games.get(gameId).getPlayer(detectiveHash).setTickets(IBMap.BUS, 15);
Assert.assertTrue(Engine.instance().games.get(gameId).getPlayer(detectiveHash).getTickets(IBMap.BUS)==15);
Engine.instance().games.get(gameId).getPlayer(detectiveHash).setTickets(IBMap.WATER, 2);
Assert.assertTrue(Engine.instance().games.get(gameId).getPlayer(detectiveHash).getTickets(IBMap.WATER)==2);
Engine.instance().games.get(gameId).getPlayer(detectiveHash).setTickets(IBMap.UG, 5);
Assert.assertTrue(Engine.instance().games.get(gameId).getPlayer(detectiveHash).getTickets(IBMap.UG)==5);
Engine.instance().games.get(gameId).getPlayer(mrxHash).setTickets(IBMap.TAXI, 20);
Assert.assertTrue(Engine.instance().games.get(gameId).getPlayer(mrxHash).getTickets(IBMap.TAXI)==20);
Engine.instance().games.get(gameId).getPlayer(mrxHash).setTickets(IBMap.BUS, 3);
Assert.assertTrue(Engine.instance().games.get(gameId).getPlayer(mrxHash).getTickets(IBMap.BUS)==3);
Engine.instance().games.get(gameId).getPlayer(mrxHash).setTickets(IBMap.UG, 10);
Assert.assertTrue(Engine.instance().games.get(gameId).getPlayer(mrxHash).getTickets(IBMap.UG)==10);
Engine.instance().games.get(gameId).getPlayer(mrxHash).setTickets(IBMap.DOUBLE, 1);
Assert.assertTrue(Engine.instance().games.get(gameId).getPlayer(mrxHash).getTickets(IBMap.DOUBLE)==1);
Engine.instance().games.get(gameId).getPlayer(mrxHash).setTickets(IBMap.WATER, 4);
Assert.assertTrue(Engine.instance().games.get(gameId).getPlayer(mrxHash).getTickets(IBMap.WATER)==4);
}
}