package test.util.proc;
import net.sf.nebulacards.comm.*;
import net.sf.nebulacards.game.*;
import net.sf.nebulacards.main.*;
import net.sf.nebulacards.util.*;
import net.sf.nebulacards.util.proc.*;
import junit.framework.*;
import OneProcGame;
public class BidProcTest
extends TestCase
{
OneProcGame opg;
int[][] bids = {
{2, 100},
{8, 98, 110},
{400, 200, 100, 0, 50}
};
int whichBid[] = {0, 0, 0};
Communicator[] coms = new Communicator[3];
public BidProcTest(String s) { super(s); }
class MyBidProc extends BidProc
{
public MyBidProc(TrumpGame g) { super(g); }
protected int reportBid(int pos, int bid)
{
assertEquals(bid, bids[pos][whichBid[pos]++]);
return (bid / 2);
}
protected boolean shouldBid(int pos)
{
return (whichBid[pos] < bids[pos].length);
}
}
class MyBidder extends UIAdapter
{
public void yourTurnToBid()
{
getCallbacks().submitBid(
bids[getPosition()][whichBid[getPosition()]]);
}
public void setBid(int who, int bid)
{
assertEquals(bids[who][whichBid[who] - 1] / 2, bid);
}
}
public void setUp()
{
opg = new OneProcGame("BidProc Test", bids.length);
opg.setProc(new MyBidProc(opg));
ComManager.AddResult cmar;
while ((cmar = opg.add(new MyBidder())) != null)
{
cmar.publicize();
coms[cmar.getPosition()] = opg.getCom(cmar.getPosition());
}
}
public void testRun()
throws InterruptedException
{
GameProcedure gp = opg.getNextProcedure();
gp.reconnect(0, coms[0]);
gp.runProcedure(coms, opg.getBroadcastCommunicator());
for (int i = 0; i < bids.length; i++)
{
assertEquals(whichBid[i], bids[i].length);
}
gp.reconnect(0, coms[0]);
}
}