add deathgame unittests
This commit is contained in:
parent
e477f42f82
commit
44fafd4e28
|
|
@ -1,4 +1,5 @@
|
||||||
using GameHandler.DeathGame;
|
using GameHandler.DeathGame;
|
||||||
|
using GameModel;
|
||||||
using GameModel.DeathGame;
|
using GameModel.DeathGame;
|
||||||
using NuGet.Frameworks;
|
using NuGet.Frameworks;
|
||||||
using System;
|
using System;
|
||||||
|
|
@ -72,8 +73,11 @@ namespace GameHandler.UnitTests.DeathGame
|
||||||
public void InvalidFirstThrow_RaisesExpense()
|
public void InvalidFirstThrow_RaisesExpense()
|
||||||
{
|
{
|
||||||
var gm = _gh.InitGameModel(_players, _settings);
|
var gm = _gh.InitGameModel(_players, _settings);
|
||||||
|
ExpenseTrigger tr = ExpenseTrigger.Circle;
|
||||||
var gmAfter = _gh.CalcNextModel(gm, 1, false, false);
|
_gh.ExpenseTriggered += (trigger) => tr = trigger;
|
||||||
|
var newGm = _gh.CalcNextModel(gm, 2, false, true);
|
||||||
|
|
||||||
|
Assert.That(tr, Is.EqualTo(ExpenseTrigger.FirstThrowFail));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -95,6 +99,31 @@ namespace GameHandler.UnitTests.DeathGame
|
||||||
Assert.That(newGm.Coffins.Last().XCount, Is.EqualTo(1));
|
Assert.That(newGm.Coffins.Last().XCount, Is.EqualTo(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void AfterThrowWithoutPins_SomeFirstPlayerHasAnLine()
|
||||||
|
{
|
||||||
|
var gm = _gh.InitGameModel(_players, _settings);
|
||||||
|
|
||||||
|
var newGm = _gh.CalcNextModel(gm, 0, false, false);
|
||||||
|
Assert.That(newGm.Coffins.Last().XCount, Is.EqualTo(1));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void ThirdX_ChangesToAddedLineAndZeroX()
|
||||||
|
{
|
||||||
|
var gm = _gh.InitGameModel(_players, _settings);
|
||||||
|
var coffins = gm.Coffins.ToList();
|
||||||
|
var first = gm.Coffins.First() with { XCount = 2 };
|
||||||
|
coffins.RemoveAt(0);
|
||||||
|
coffins.Insert(0, first);
|
||||||
|
var gm2 = gm with { Coffins = coffins.ToArray(), Id = 2 };
|
||||||
|
|
||||||
|
var newGm = _gh.CalcNextModel(gm2, 2, true, true);
|
||||||
|
|
||||||
|
Assert.That(newGm.Coffins.Last().XCount, Is.EqualTo(0));
|
||||||
|
Assert.That(newGm.Coffins.Last().LineCount, Is.EqualTo(first.LineCount + 1));
|
||||||
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void FirstPlayerIsLast_AfterModelUpdate()
|
public void FirstPlayerIsLast_AfterModelUpdate()
|
||||||
{
|
{
|
||||||
|
|
@ -120,5 +149,51 @@ namespace GameHandler.UnitTests.DeathGame
|
||||||
|
|
||||||
Assert.That(prevNew.LineCount, Is.EqualTo(prev.LineCount + 1));
|
Assert.That(prevNew.LineCount, Is.EqualTo(prev.LineCount + 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void LineLimit_CausesDeath()
|
||||||
|
{
|
||||||
|
var gm = _gh.InitGameModel(_players, _settings);
|
||||||
|
Coffin? deadCoffin = null;
|
||||||
|
_gh.CoffinCompleted += (c) => deadCoffin = c;
|
||||||
|
|
||||||
|
var coffins = gm.Coffins.ToList();
|
||||||
|
var first = gm.Coffins.First() with { LineCount = _settings.MaxCoffinSize };
|
||||||
|
coffins.RemoveAt(0);
|
||||||
|
coffins.Insert(0, first);
|
||||||
|
var gm2 = gm with { Coffins = coffins.ToArray(), Id = 2 };
|
||||||
|
|
||||||
|
var newGm = _gh.CalcNextModel(gm2, 0, false, false);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Assert.That(deadCoffin.PlayerId, Is.EqualTo(first.PlayerId));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void PreviousPlayerIsDead_WhenCurrentClearsBoard()
|
||||||
|
{
|
||||||
|
var gm = _gh.InitGameModel(_players, _settings);
|
||||||
|
Coffin? deadCoffin = null;
|
||||||
|
_gh.CoffinCompleted += (c) => deadCoffin = c;
|
||||||
|
|
||||||
|
var coffins = gm.Coffins.ToList();
|
||||||
|
var last = gm.Coffins.Last() with { LineCount = _settings.MaxCoffinSize };
|
||||||
|
coffins.RemoveAt(gm.Coffins.Length-1);
|
||||||
|
coffins.Insert(gm.Coffins.Length - 1, last);
|
||||||
|
var gm2 = gm with { Coffins = coffins.ToArray(), Id = 2 };
|
||||||
|
|
||||||
|
var newGm = _gh.CalcNextModel(gm2, 2, false, true);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Assert.That(deadCoffin.PlayerId, Is.EqualTo(last.PlayerId));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void NexxtPlayerIsDead_WhenCurrentCausesThirdX()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
using GameModel.DeathGame;
|
using GameModel;
|
||||||
|
using GameModel.DeathGame;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
@ -8,6 +9,7 @@ using System.Threading.Tasks;
|
||||||
namespace GameHandler.DeathGame
|
namespace GameHandler.DeathGame
|
||||||
{
|
{
|
||||||
public delegate void CoffinCompleted(Coffin coffin);
|
public delegate void CoffinCompleted(Coffin coffin);
|
||||||
|
public delegate void ExpenseTriggered(ExpenseTrigger expenseType);
|
||||||
public class DeathGameHandler
|
public class DeathGameHandler
|
||||||
{
|
{
|
||||||
const int MIN_PLAYER_COUNT = 3;
|
const int MIN_PLAYER_COUNT = 3;
|
||||||
|
|
@ -16,6 +18,7 @@ namespace GameHandler.DeathGame
|
||||||
const int MAX_COFFIN_SIZE = 12;
|
const int MAX_COFFIN_SIZE = 12;
|
||||||
|
|
||||||
public event CoffinCompleted CoffinCompleted;
|
public event CoffinCompleted CoffinCompleted;
|
||||||
|
public event ExpenseTriggered ExpenseTriggered;
|
||||||
|
|
||||||
private static Random random = new Random();
|
private static Random random = new Random();
|
||||||
|
|
||||||
|
|
@ -70,6 +73,7 @@ namespace GameHandler.DeathGame
|
||||||
incX = true;
|
incX = true;
|
||||||
if (pinCount < 3)
|
if (pinCount < 3)
|
||||||
{
|
{
|
||||||
|
ExpenseTriggered?.Invoke(ExpenseTrigger.FirstThrowFail);
|
||||||
incLine = true;
|
incLine = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -95,13 +99,6 @@ namespace GameHandler.DeathGame
|
||||||
var xCount = current.XCount;
|
var xCount = current.XCount;
|
||||||
var lineCount = current.LineCount;
|
var lineCount = current.LineCount;
|
||||||
|
|
||||||
|
|
||||||
if ((current.XCount == 2) && incX)
|
|
||||||
{
|
|
||||||
xCount = 0;
|
|
||||||
lineCount++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (incLine)
|
if (incLine)
|
||||||
{
|
{
|
||||||
lineCount++;
|
lineCount++;
|
||||||
|
|
@ -111,6 +108,12 @@ namespace GameHandler.DeathGame
|
||||||
{
|
{
|
||||||
xCount++;
|
xCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (xCount == 3)
|
||||||
|
{
|
||||||
|
xCount = 0;
|
||||||
|
lineCount++;
|
||||||
|
}
|
||||||
currentUpdated = current with { LineCount = lineCount, XCount = xCount };
|
currentUpdated = current with { LineCount = lineCount, XCount = xCount };
|
||||||
|
|
||||||
if (lineCount > gm.deathGameSettings.MaxCoffinSize)
|
if (lineCount > gm.deathGameSettings.MaxCoffinSize)
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,25 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace GameModel
|
||||||
|
{
|
||||||
|
public enum ExpenseTrigger
|
||||||
|
{
|
||||||
|
Sink, // Gosse
|
||||||
|
Bell, // Klingel
|
||||||
|
NoWood, // kein Holz
|
||||||
|
FirstThrowFail, // Anwurffehler
|
||||||
|
Circle, // Kranz
|
||||||
|
NinePins, // alle Neune
|
||||||
|
/// <summary>
|
||||||
|
/// Sink at first throw in round
|
||||||
|
/// </summary>
|
||||||
|
FullSink, // Gosse beim Anwurf
|
||||||
|
Eliminated, // Ausgeschieden
|
||||||
|
Absent, // Am Spieltag nicht teilgenommen
|
||||||
|
ExpensePoint // Strafpunkt, z.B. im "Scheißspiel"
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue