mirror of
https://github.com/Earth-Genesis-Games/Ajedrez_Purgatorio.git
synced 2026-09-11 09:47:35 +00:00
- Duel flow: mating piece vs boss while board collapses (PurgatoryDuelManager/Rules/UI/MuerteQuotes) - GameState.PurgatoryDuel + CampaignManager rescue/restart hooks + SquareClick routing - Dice-based rescue of most valuable dead identity; final defeat restarts Chapter 1 - 6 SFX clips wired in Ch1/2/3 via AudioClipAssigner - OptionsMenuController runtime audio/graphics panel, wired to MainMenu - Tests migrated to Assets/Tests/EditMode subfolders + PurgatoryDuelRulesTests (200 total) - Editor tools: DiagAssign, SpeakerDatabaseSetup, PurgatoryCanvasMaintenance
243 lines
7.3 KiB
C#
243 lines
7.3 KiB
C#
using NUnit.Framework;
|
|
using UnityEngine;
|
|
|
|
namespace AjedrezPurgatorio.Tests.Unit.Purgatory
|
|
{
|
|
[TestFixture]
|
|
[Category("Unit")]
|
|
[Category("Purgatory")]
|
|
[Category("DiceSystem")]
|
|
[Category("FastTests")]
|
|
public class DiceSystemTests
|
|
{
|
|
private GameObject _root;
|
|
private DiceSystem _diceSystem;
|
|
|
|
[SetUp]
|
|
public void Setup()
|
|
{
|
|
_root = new GameObject("DiceTestRoot");
|
|
_diceSystem = _root.AddComponent<DiceSystem>();
|
|
}
|
|
|
|
[TearDown]
|
|
public void Teardown()
|
|
{
|
|
Object.DestroyImmediate(_root);
|
|
}
|
|
|
|
#region Roll2d6 Tests
|
|
|
|
[Test]
|
|
public void Roll2d6_ReturnsValueBetween2And12()
|
|
{
|
|
for (int i = 0; i < 100; i++)
|
|
{
|
|
int result = _diceSystem.Roll2d6();
|
|
Assert.GreaterOrEqual(result, 2, "Minimum 2d6 result is 2");
|
|
Assert.LessOrEqual(result, 12, "Maximum 2d6 result is 12");
|
|
}
|
|
}
|
|
|
|
[Test]
|
|
public void Roll2d6_DistributionCoversFullRange()
|
|
{
|
|
bool sawMin = false;
|
|
bool sawMax = false;
|
|
|
|
for (int i = 0; i < 500; i++)
|
|
{
|
|
int result = _diceSystem.Roll2d6();
|
|
if (result == 2) sawMin = true;
|
|
if (result == 12) sawMax = true;
|
|
}
|
|
|
|
Assert.IsTrue(sawMin, "Should see minimum roll of 2 in 500 attempts");
|
|
Assert.IsTrue(sawMax, "Should see maximum roll of 12 in 500 attempts");
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region DetermineWinner Tests
|
|
|
|
[Test]
|
|
public void DetermineWinner_PlayerHigher_ReturnsPlayer()
|
|
{
|
|
Assert.AreEqual(PurgatoryWinner.Player, _diceSystem.DetermineWinner(10, 5));
|
|
}
|
|
|
|
[Test]
|
|
public void DetermineWinner_DeathHigher_ReturnsDeath()
|
|
{
|
|
Assert.AreEqual(PurgatoryWinner.Death, _diceSystem.DetermineWinner(5, 10));
|
|
}
|
|
|
|
[Test]
|
|
public void DetermineWinner_Tie_ReturnsDeath()
|
|
{
|
|
Assert.AreEqual(PurgatoryWinner.Death, _diceSystem.DetermineWinner(7, 7));
|
|
}
|
|
|
|
[Test]
|
|
public void DetermineWinner_BothZero_ReturnsDeath()
|
|
{
|
|
Assert.AreEqual(PurgatoryWinner.Death, _diceSystem.DetermineWinner(0, 0));
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region RollForDeath Tests
|
|
|
|
[Test]
|
|
public void RollForDeath_BaseRollInRange()
|
|
{
|
|
var result = _diceSystem.RollForDeath();
|
|
|
|
Assert.GreaterOrEqual(result.baseRoll, 2);
|
|
Assert.LessOrEqual(result.baseRoll, 12);
|
|
}
|
|
|
|
[Test]
|
|
public void RollForDeath_NoModifiers()
|
|
{
|
|
var result = _diceSystem.RollForDeath();
|
|
|
|
Assert.AreEqual(0, result.pieceBonus);
|
|
Assert.AreEqual(0, result.desperationBonus);
|
|
Assert.AreEqual(0, result.penalty);
|
|
Assert.AreEqual(result.baseRoll, result.finalResult);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region RollForPlayer Tests
|
|
|
|
[Test]
|
|
public void RollForPlayer_QueenGivesBonus()
|
|
{
|
|
var queenIdentity = ScriptableObject.CreateInstance<PieceIdentity>();
|
|
queenIdentity.pieceType = PieceType.Queen;
|
|
|
|
var result = _diceSystem.RollForPlayer(queenIdentity, 0);
|
|
|
|
Assert.AreEqual(2, result.pieceBonus);
|
|
Object.DestroyImmediate(queenIdentity);
|
|
}
|
|
|
|
[Test]
|
|
public void RollForPlayer_RookGivesBonus()
|
|
{
|
|
var rookIdentity = ScriptableObject.CreateInstance<PieceIdentity>();
|
|
rookIdentity.pieceType = PieceType.Rook;
|
|
|
|
var result = _diceSystem.RollForPlayer(rookIdentity, 0);
|
|
|
|
Assert.AreEqual(1, result.pieceBonus);
|
|
Object.DestroyImmediate(rookIdentity);
|
|
}
|
|
|
|
[Test]
|
|
public void RollForPlayer_BishopGivesBonus()
|
|
{
|
|
var bishopIdentity = ScriptableObject.CreateInstance<PieceIdentity>();
|
|
bishopIdentity.pieceType = PieceType.Bishop;
|
|
|
|
var result = _diceSystem.RollForPlayer(bishopIdentity, 0);
|
|
|
|
Assert.AreEqual(1, result.pieceBonus);
|
|
Object.DestroyImmediate(bishopIdentity);
|
|
}
|
|
|
|
[Test]
|
|
public void RollForPlayer_KnightGivesBonus()
|
|
{
|
|
var knightIdentity = ScriptableObject.CreateInstance<PieceIdentity>();
|
|
knightIdentity.pieceType = PieceType.Knight;
|
|
|
|
var result = _diceSystem.RollForPlayer(knightIdentity, 0);
|
|
|
|
Assert.AreEqual(1, result.pieceBonus);
|
|
Object.DestroyImmediate(knightIdentity);
|
|
}
|
|
|
|
[Test]
|
|
public void RollForPlayer_PawnGivesNoBonus()
|
|
{
|
|
var pawnIdentity = ScriptableObject.CreateInstance<PieceIdentity>();
|
|
pawnIdentity.pieceType = PieceType.Pawn;
|
|
|
|
var result = _diceSystem.RollForPlayer(pawnIdentity, 0);
|
|
|
|
Assert.AreEqual(0, result.pieceBonus);
|
|
Object.DestroyImmediate(pawnIdentity);
|
|
}
|
|
|
|
[Test]
|
|
public void RollForPlayer_PurgatoryPenaltyIncreases()
|
|
{
|
|
var identity = ScriptableObject.CreateInstance<PieceIdentity>();
|
|
identity.pieceType = PieceType.Pawn;
|
|
|
|
var result0 = _diceSystem.RollForPlayer(identity, 0);
|
|
var result3 = _diceSystem.RollForPlayer(identity, 3);
|
|
|
|
Assert.AreEqual(0, result0.penalty);
|
|
Assert.AreEqual(3, result3.penalty);
|
|
|
|
// Comparar dos tiradas RNG independientes es no determinista;
|
|
// validar la fórmula por tirada usando su propia base:
|
|
// finalResult = max(2, baseRoll + bonus - penalty).
|
|
int expected0 = Mathf.Max(2, result0.baseRoll + result0.pieceBonus + result0.desperationBonus - 0);
|
|
int expected3 = Mathf.Max(2, result3.baseRoll + result3.pieceBonus + result3.desperationBonus - 3);
|
|
|
|
Assert.AreEqual(expected0, result0.finalResult,
|
|
"Sin visitas la penalización es 0 y finalResult refleja la base.");
|
|
Assert.AreEqual(expected3, result3.finalResult,
|
|
"Con 3 visitas la penalización se aplica sobre la misma tirada.");
|
|
|
|
Object.DestroyImmediate(identity);
|
|
}
|
|
|
|
[Test]
|
|
public void RollForPlayer_FinalResultNeverBelow2()
|
|
{
|
|
var identity = ScriptableObject.CreateInstance<PieceIdentity>();
|
|
identity.pieceType = PieceType.Pawn;
|
|
|
|
for (int i = 0; i < 100; i++)
|
|
{
|
|
var result = _diceSystem.RollForPlayer(identity, 10);
|
|
Assert.GreaterOrEqual(result.finalResult, 2, "Final result should never be below 2");
|
|
}
|
|
|
|
Object.DestroyImmediate(identity);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region DiceRollResult ToString Tests
|
|
|
|
[Test]
|
|
public void DiceRollResult_ToString_ContainsAllParts()
|
|
{
|
|
var result = new DiceRollResult
|
|
{
|
|
baseRoll = 7,
|
|
pieceBonus = 2,
|
|
desperationBonus = 1,
|
|
penalty = 1,
|
|
finalResult = 9
|
|
};
|
|
|
|
string str = result.ToString();
|
|
|
|
StringAssert.Contains("7", str);
|
|
StringAssert.Contains("2", str);
|
|
StringAssert.Contains("1", str);
|
|
StringAssert.Contains("9", str);
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|