package oving4.card;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

public class CardTest {

	private static void checkCard(Card card, char suit, int face) {
		assertEquals(card.getSuit(), suit);
		assertEquals(card.getFace(), face);
	}

	@Test
	@DisplayName("Check that the constructor creates Card objects with correct values")
	public void testConstructor() {
		CardTest.checkCard(new Card('S', 1), 'S', 1);
		CardTest.checkCard(new Card('S', 13), 'S', 13);
		CardTest.checkCard(new Card('H', 1), 'H', 1);
		CardTest.checkCard(new Card('H', 13), 'H', 13);
		CardTest.checkCard(new Card('D', 1), 'D', 1);
		CardTest.checkCard(new Card('D', 13), 'D', 13);
		CardTest.checkCard(new Card('C', 1), 'C', 1);
		CardTest.checkCard(new Card('C', 13), 'C', 13);

		assertThrows(IllegalArgumentException.class, () -> {
			new Card('X', 1);
		}, "Should not be able to create a card of type X");

		assertThrows(IllegalArgumentException.class, () -> {
			new Card('S', 0);
		}, "Should not be able to create a card with value 0");

		assertThrows(IllegalArgumentException.class, () -> {
			new Card('C', 14);
		}, "Should not be able to create a card with value 14");
	}

	@Test
	@DisplayName("Check that toString works as expected")
	public void testToString() {
		assertEquals("S1", new Card('S', 1).toString());
		assertEquals("H13", new Card('H', 13).toString());
	}
}
