package poker.domain

import poker.domain.Valor._
import poker.domain.Naipe._
import org.testng.annotations._
import org.junit.Assert._
//import org.hamcrest.MatcherAssert.assertThat
//import org.hamcrest.Matchers._

class CartaTest {
  
  @Test
  def letrasDevemIndicarValorCorrespondente() {
    assertEquals(new Carta(14, PAUS), new Carta(AS, PAUS))
    assertEquals(new Carta(11, PAUS), new Carta(J, PAUS))
    assertEquals(new Carta(12, PAUS), new Carta(Q, PAUS))
    assertEquals(new Carta(13, PAUS), new Carta(K, PAUS))
  }
    
  @Test
  def toStringDeveImprimirValorENaipe() {
    assertEquals("[2 Copas]", new Carta(2, COPAS).toString())
    assertEquals("[AS Copas]", new Carta(AS, COPAS).toString())
    assertEquals("[J Copas]", new Carta(J, COPAS).toString())
  }
  
  @Test
  def duasCartasSaoIguaisSeTiveremMesmoValorENaipe() {
    assertEquals(new Carta(AS, COPAS), new Carta(AS, COPAS))
    assertEquals(new Carta(AS, COPAS).hashCode, new Carta(AS, COPAS).hashCode)
  }
  
  @Test
  def duasCartasSaoDiferentesSeTiveremValorDiferente() {
    def as = new Carta(AS, COPAS)
    def rei = new Carta(K, COPAS)
    assertTrue(as != rei)
  }
  
  @Test
  def duasCartasSaoDiferentesSeTiveremNaipeDiferente() {
    def paus = new Carta(AS, PAUS)
    def copas = new Carta(AS, COPAS)
    assertTrue(paus != copas)
  }
  
  @Test
  def duasCartasSaoDiferentesSeTiveremValorENaipeDiferente() {
    def as = new Carta(AS, PAUS)
    def oito = new Carta(8, COPAS)
    assertTrue(as != oito)
  }
  
  @Test
  def umaCartaEMaiorQueOutraSeSeuValorEMaior() {
    def quatro = new Carta(4, PAUS)
    def tres = new Carta(3, COPAS)
    assertTrue(quatro > tres)
    assertTrue(tres < quatro)
    assertTrue((tres compare tres) == 0)
    assertTrue((tres.compare(quatro)) != 0)
  }
  
  @Test
  def cartasInvalidasLancamExcecao() {
    testaCartaInvalida(1, PAUS)
    testaCartaInvalida(AS+1, PAUS)
    testaCartaInvalida(AS, PAUS-1)
    testaCartaInvalida(AS, OUROS+1)
  }
  
  private def testaCartaInvalida(valor:Int, naipe:Int) {
    try {
      new Carta(valor, naipe)
      fail("ops")
    } catch {
      case e:RuntimeException => assertTrue(true)
      case _ => fail("ops")
    }
  }
  
}
