dev
This commit is contained in:
parent
cc45183efc
commit
4785f62650
|
|
@ -180,5 +180,13 @@ namespace GameHandler.UnitTests
|
||||||
Assert.That(p9.DownCount, Is.EqualTo(8));
|
Assert.That(p9.DownCount, Is.EqualTo(8));
|
||||||
Assert.That(p10.DownCount, Is.EqualTo(9));
|
Assert.That(p10.DownCount, Is.EqualTo(9));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void DownCount_MatchesDownState()
|
||||||
|
{
|
||||||
|
var p = PinPicture.Create(2,PinState.Down);
|
||||||
|
Assert.That(p.DownCount, Is.EqualTo(1));
|
||||||
|
Assert.That(p.UpCount, Is.EqualTo(8));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
using System;
|
using GameModel;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
@ -6,7 +7,48 @@ using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace GameHandler.UnitTests
|
namespace GameHandler.UnitTests
|
||||||
{
|
{
|
||||||
|
[TestFixture]
|
||||||
public class ThrowHandlerTests
|
public class ThrowHandlerTests
|
||||||
{
|
{
|
||||||
|
ThrowHandler _th;
|
||||||
|
|
||||||
|
[SetUp]
|
||||||
|
public void SetUp()
|
||||||
|
{
|
||||||
|
_th = new ThrowHandler();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void CreateFullPicAfterEachThrowInRepositionMode()
|
||||||
|
{
|
||||||
|
var bs = _th.Init(ThrowMode.Reposition);
|
||||||
|
|
||||||
|
var bs2 = _th.Update(bs, new PinThrow(PinPicture.Create(2,PinState.Down),false,false));
|
||||||
|
|
||||||
|
Assert.That(bs.PinPicture.UpCount, Is.EqualTo(9));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void SinkThrowReturnsSameGameStateAsBefore()
|
||||||
|
{
|
||||||
|
var bs = _th.Init(ThrowMode.Reposition);
|
||||||
|
|
||||||
|
var bs2 = _th.Update(bs, new PinThrow(PinPicture.Create(2, PinState.Down), false, false));
|
||||||
|
var bs3 = _th.Update(bs, new PinThrow(PinPicture.Create(2, PinState.Down), false, true));
|
||||||
|
|
||||||
|
Assert.That(bs2, Is.EqualTo(bs3));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void CreateFullPicAfterBoardIsClearedInDecreaseMode()
|
||||||
|
{
|
||||||
|
var bs = _th.Init(ThrowMode.Decrease);
|
||||||
|
|
||||||
|
var bs2 = _th.Update(bs, new PinThrow(PinPicture.Create(2, PinState.Down), false, false));
|
||||||
|
Assert.That(bs2.PinPicture.DownCount, Is.EqualTo(1));
|
||||||
|
|
||||||
|
var bs3 = _th.Update(bs, new PinThrow(PinPicture.CreateAllPins(), false, false));
|
||||||
|
Assert.That(bs3.PinPicture.DownCount, Is.EqualTo(0));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -37,8 +37,16 @@ namespace GameHandler
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return currentState with { PinPicture = currentState.PinPicture + pinThrow };
|
var result = currentState with { PinPicture = currentState.PinPicture + pinThrow };
|
||||||
|
if (result.PinPicture.UpCount == 0)
|
||||||
|
{
|
||||||
|
return currentState with { PinPicture = PinPicture.Create() };
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net.NetworkInformation;
|
using System.Net.NetworkInformation;
|
||||||
|
using System.Numerics;
|
||||||
using System.Reflection.Metadata.Ecma335;
|
using System.Reflection.Metadata.Ecma335;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
@ -61,17 +62,12 @@ namespace GameModel
|
||||||
// throw new InvalidPinPictureException();
|
// throw new InvalidPinPictureException();
|
||||||
//}
|
//}
|
||||||
//}
|
//}
|
||||||
|
|
||||||
List<PinState>? _pins = null;
|
|
||||||
private List<PinState> pins
|
private List<PinState> pins
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
if (_pins == null)
|
return new List<PinState>(new[] { PinState1, PinState2, PinState3, PinState4, PinState5, PinState6, PinState7, PinState8, PinState9 });
|
||||||
{
|
|
||||||
_pins = new List<PinState>(new[] { PinState1, PinState2, PinState3, PinState4, PinState5, PinState6, PinState7, PinState8, PinState9 });
|
|
||||||
}
|
|
||||||
return _pins;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -182,5 +178,11 @@ namespace GameModel
|
||||||
{
|
{
|
||||||
return PinPicture.Create(states[0], states[1], states[2], states[3], states[4], states[5], states[6], states[7], states[8]);
|
return PinPicture.Create(states[0], states[1], states[2], states[3], states[4], states[5], states[6], states[7], states[8]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static PinPicture CreateAllPins()
|
||||||
|
{
|
||||||
|
var states = new List<PinState>(new[] { PinState.Down, PinState.Down, PinState.Down, PinState.Down, PinState.Down, PinState.Down, PinState.Down, PinState.Down, PinState.Down }).ToArray();
|
||||||
|
return PinPicture.Create(states);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue