package ru.alphatech.icfpc.cards.tests;

import junit.framework.Assert;

import org.junit.Test;

import ru.alphatech.icfpc.cards.Get;
import ru.alphatech.icfpc.cards.I;
import ru.alphatech.icfpc.game.ICFPCException;
import ru.alphatech.icfpc.game.IValue;
import ru.alphatech.icfpc.game.Player;
import ru.alphatech.icfpc.game.Value;

/**
 * @author indvdum (idea)
 * @author 0-range (implementation)
 * 18.06.2011 19:42:44
 *
 */
public class TestGet extends Assert
{
	@Test
	public final void testReturnValue()
	{
		Player opponent = new Player();
		Player proponent = new Player();

		IValue i = new Value(0);
		IValue value = new Value(99);

		proponent.getSlot(((Value)i).getValue()).putValue(value);
		assertEquals(value, new Get().returnValue(i, proponent, opponent));
	}

	@Test
	public final void testNotSlotNumber()
	{
		Player opponent = new Player();
		Player proponent = new Player();

		try
		{
			IValue i = new I();
			new Get().returnValue(i, proponent, opponent);
			assertTrue(false);
		}
		catch (ICFPCException e)
		{
			assertTrue(true);
		}
	}

	@Test
	public final void testInvalidSlotNumber()
	{
		Player opponent = new Player();
		Player proponent = new Player();

		try
		{
			IValue i = new Value(999);
			new Get().returnValue(i, proponent, opponent);
			assertTrue(false);
		}
		catch (ICFPCException e)
		{
			assertTrue(true);
		}
	}

	@Test
	public final void testIfSlotDead()
	{
		Player opponent = new Player();
		Player proponent = new Player();

		try
		{
			IValue i = new Value(0);
			proponent.getSlot(((Value)i).getValue()).setVitality(0);
			new Get().returnValue(i, proponent, opponent);
			assertTrue(false);
		}
		catch (ICFPCException e)
		{
			assertTrue(true);
		}
	}
}
