-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Cambio en la interfaz de Jugada - Agregada Implementación de CartaAlta - Agregados test de CartaAlta
- Loading branch information
Showing
4 changed files
with
78 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
namespace Poker12.Core.Test; | ||
public class CartaTest | ||
{ | ||
Carta _seisTrebol = new Carta(EPalo.Trebol, EValor.Seis); | ||
Carta _seisTrebol = new(EPalo.Trebol, EValor.Seis); | ||
|
||
[Fact] | ||
public void ToStringOK() | ||
=> Assert.Equal("Seis Trebol", _seisTrebol.ToString()); | ||
=> Assert.Equal("Carta { Palo = Trebol, Valor = Seis }", _seisTrebol.ToString()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using Poker12.Core.Jugadas; | ||
|
||
namespace Poker12.Core.Test.Jugadas; | ||
public class CartaAltaTest | ||
{ | ||
private IJugada _cartaAlta; | ||
public CartaAltaTest() => _cartaAlta = new CartaAlta(); | ||
|
||
[Fact] | ||
public void FallaPorJugadaSinCartas() | ||
{ | ||
var jugada = new List<Carta>(); | ||
|
||
Assert.Throws<ArgumentException>(() => _cartaAlta.Aplicar(jugada)); | ||
} | ||
|
||
[Fact] | ||
public void PruebaConAS() | ||
{ | ||
var jugada = new List<Carta>() | ||
{ | ||
new(EPalo.Corazon, EValor.Diez), | ||
new(EPalo.Picas, EValor.As), | ||
new(EPalo.Corazon, EValor.Tres) | ||
}; | ||
|
||
var resultado = _cartaAlta.Aplicar(jugada); | ||
|
||
Assert.Equal(14, resultado.Valor); | ||
} | ||
|
||
[Theory] | ||
[InlineData(EValor.Dos)] | ||
[InlineData(EValor.Cinco)] | ||
[InlineData(EValor.J)] | ||
public void CasoTrivialUnaCarta(EValor valor) | ||
{ | ||
var jugada = new List<Carta>() | ||
{ | ||
new(EPalo.Corazon, valor) | ||
}; | ||
|
||
var resultado = _cartaAlta.Aplicar(jugada); | ||
|
||
Assert.Equal((byte)valor, resultado.Valor); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
namespace Poker12.Core.Jugadas; | ||
public class CartaAlta : IJugada | ||
{ | ||
public string Nombre => "Carta Alta"; | ||
public byte Prioridad => 10; | ||
public Resultado Aplicar(List<Carta> cartas) | ||
{ | ||
if (cartas.Count == 0) | ||
throw new ArgumentException("No hay cartas"); | ||
|
||
var ordenadasPorValor = cartas.OrderBy(c => c.Valor); | ||
|
||
var valor = ordenadasPorValor.First().Valor == EValor.As ? | ||
(byte)14 : // Aca use el valor 'Alto' del As | ||
(byte)ordenadasPorValor.Last().Valor; // Como estan ordenadas, la ultima es la mayor | ||
|
||
return new Resultado(Prioridad, valor); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,14 @@ | ||
namespace Poker12.Core.Jugadas; | ||
/// <summary> | ||
/// Esta estructura, representa el resultado de aplicar una Jugada a una colección de cartas | ||
/// </summary> | ||
/// <param name="Prioridad">Representa la importancia de la jugada, en base 1 desde Escalera Real en adelante.</param> | ||
/// <param name="Valor">Si la jugada no se puede aplicar vale 0, caso contrario un valor mayor.</param> | ||
public readonly record struct Resultado(byte Prioridad, byte Valor = 0); | ||
|
||
public interface IJugada | ||
{ | ||
public string Nombre { get; } | ||
public byte? Valor { get; } | ||
public bool PuedeAplicar (List<Carta> cartas); | ||
} | ||
public byte Prioridad { get; } | ||
public Resultado Aplicar (List<Carta> cartas); | ||
} |