package com.definidev;

import org.junit.Assert;
import org.junit.Test;

public class CribbageCalculatorTest extends Assert {

	@Test
	public void testScorePairAndFifteens() {
		// {5C, 10S, 2S, 2D, AS} -> score of 6 (two fifteens, one pair)
		Card cards[] = {
				new Card(Rank.FIVE, Suit.CLUBS), 
				new Card(Rank.TEN, Suit.SPADES),
				new Card(Rank.TWO, Suit.SPADES),
				new Card(Rank.TWO, Suit.DIAMONDS),
				new Card(Rank.ACE, Suit.SPADES)
		};
		Deck deck = new Deck(cards);
		CribbageCalculator calc = new CribbageCalculator(deck);

		assertEquals(6, calc.score());
	}

	@Test
	public void testScoreDescriptions() {
		// {5C, 10S, 2S, 2D, AS} -> score of 6 (one pair, two fifteens)
		Card cards[] = {
				new Card(Rank.FIVE, Suit.CLUBS), 
				new Card(Rank.TEN, Suit.SPADES),
				new Card(Rank.TWO, Suit.SPADES),
				new Card(Rank.TWO, Suit.DIAMONDS),
				new Card(Rank.ACE, Suit.SPADES)
		};
		Deck deck = new Deck(cards);
		CribbageCalculator calc = new CribbageCalculator(deck);

		String scoresExpected[] = {
				"Pair for 2 : 2D 2S",
				"Fifteen for 2 : 5C 10S", 
				"Fifteen for 2 : 10S 2S 2D AS"
		};

		String scores[] = calc.scores();

		for(int i = 0; i < scoresExpected.length; i++) {
			assertEquals(scoresExpected[i], scores[i]);
		}
	}

	@Test
	public void testFlush() {
		// 10C JC 4C 2C 6H -> score of 4 (flush of size 4) 
		Card cards[] = {
				new Card(Rank.TEN, Suit.CLUBS),
				new Card(Rank.JACK, Suit.CLUBS), 
				new Card(Rank.FOUR, Suit.CLUBS),
				new Card(Rank.TWO, Suit.CLUBS),
				new Card(Rank.SIX, Suit.HEARTS)
		};
		Deck deck = new Deck(cards);
		CribbageCalculator calc = new CribbageCalculator(deck);

		assertEquals(4, calc.score());
	}

	@Test
	public void testRuns() {
		// 10H JD QH KC 2S -> score of 4 (run of size 4)
		Card cards[] = {
				new Card(Rank.TEN, Suit.HEARTS),
				new Card(Rank.JACK, Suit.DIAMONDS), 
				new Card(Rank.QUEEN, Suit.HEARTS),
				new Card(Rank.KING, Suit.CLUBS),
				new Card(Rank.TWO, Suit.SPADES)
		};
		Deck deck = new Deck(cards);
		CribbageCalculator calc = new CribbageCalculator(deck);

		assertEquals(4, calc.score());
	}
	
	@Test
	public void testMultipleRuns() {
		Deck deck = new Deck("AH AS AD 2S 3H"); // trible run of 3 and a triple (15 points)
		CribbageCalculator calc = new CribbageCalculator(deck);
		assertEquals(15, calc.score());
	}
}

@@ -175,35 +175,51 @@
 %7B%0A%09%09
-// %7B
+Deck deck = new Deck(%22
 5C
-,
  10S
-,
  2S
-,
  2D
-,
  AS
-%7D -%3E
+%22); //
  sco
@@ -255,250 +255,8 @@
 ir)%0A
-%09%09Card cards%5B%5D = %7B%0A%09%09%09%09new Card(Rank.FIVE, Suit.CLUBS), %0A%09%09%09%09new Card(Rank.TEN, Suit.SPADES),%0A%09%09%09%09new Card(Rank.TWO, Suit.SPADES),%0A%09%09%09%09new Card(Rank.TWO, Suit.DIAMONDS),%0A%09%09%09%09new Card(Rank.ACE, Suit.SPADES)%0A%09%09%7D;%0A%09%09Deck deck = new Deck(cards);%0A
 %09%09Cr
@@ -399,46 +399,52 @@
 %7B%0A%09%09
-// %7B
+Deck deck = new Deck(%22
 5C
-,
  10S
-,
  2S
-,
  2D
-,
  AS
-%7D -%3E score of 6
+%22);  //
  (on
@@ -469,250 +469,8 @@
 ns)%0A
-%09%09Card cards%5B%5D = %7B%0A%09%09%09%09new Card(Rank.FIVE, Suit.CLUBS), %0A%09%09%09%09new Card(Rank.TEN, Suit.SPADES),%0A%09%09%09%09new Card(Rank.TWO, Suit.SPADES),%0A%09%09%09%09new Card(Rank.TWO, Suit.DIAMONDS),%0A%09%09%09%09new Card(Rank.ACE, Suit.SPADES)%0A%09%09%7D;%0A%09%09Deck deck = new Deck(cards);%0A
 %09%09Cr
@@ -830,19 +830,38 @@
 h() %7B%0A%09%09
-// 
+Deck deck = new Deck(%22
 10C JC 4
@@ -867,19 +867,22 @@
 4C 2C 6H
- -%3E
+%22); //
  score o
@@ -906,247 +906,8 @@
 e 4)
- %0A%09%09Card cards%5B%5D = %7B%0A%09%09%09%09new Card(Rank.TEN, Suit.CLUBS),%0A%09%09%09%09new Card(Rank.JACK, Suit.CLUBS), %0A%09%09%09%09new Card(Rank.FOUR, Suit.CLUBS),%0A%09%09%09%09new Card(Rank.TWO, Suit.CLUBS),%0A%09%09%09%09new Card(Rank.SIX, Suit.HEARTS)%0A%09%09%7D;%0A%09%09Deck deck = new Deck(cards);
 %0A%09%09C
@@ -1034,19 +1034,38 @@
 s() %7B%0A%09%09
-// 
+Deck deck = new Deck(%22
 10H JD Q
@@ -1075,11 +1075,15 @@
 C 2S
- -%3E
+%22); // 
  sco
@@ -1110,253 +1110,8 @@
  4)%0A
-%09%09Card cards%5B%5D = %7B%0A%09%09%09%09new Card(Rank.TEN, Suit.HEARTS),%0A%09%09%09%09new Card(Rank.JACK, Suit.DIAMONDS), %0A%09%09%09%09new Card(Rank.QUEEN, Suit.HEARTS),%0A%09%09%09%09new Card(Rank.KING, Suit.CLUBS),%0A%09%09%09%09new Card(Rank.TWO, Suit.SPADES)%0A%09%09%7D;%0A%09%09Deck deck = new Deck(cards);%0A
 %09%09Cr

refactor test to use new Deck(String) constructor