Hello.
I’m having a issue where my Spare Test is failing, but the code is the same as what Ben has. I am running unity v 5.4.1f1. Here is my code. I have been starring at to for a day now, and I can not see what is wrong.
The error:
Expected: EndTurn
But was: Tidy
Edit: After a little more testing I have found that the bowl variable does not increase, but I am still not seeing why this is not happening. Any help at all would be greatly appreciated.
ActionMasterTest.cs
using UnityEngine;
using UnityEditor;
using NUnit.Framework;
using System.Collections.Generic;
[TestFixture]
public class ActionMasterTest{
private ActionMaster actionMaster;
private ActionMaster.Action endTurn = ActionMaster.Action.EndTurn;
private ActionMaster.Action tidy = ActionMaster.Action.Tidy;
private ActionMaster.Action endGame = ActionMaster.Action.EndGame;
[Test]
public void Setup()
{
actionMaster = new ActionMaster();
}
[Test]
public void T01_OneStrike_ReturnsEndTurn()
{
Assert.AreEqual(endTurn, actionMaster.Bowl(10));
}
[Test]
public void T02_Bowl8_ReturnsTidy()
{
Assert.AreEqual(tidy, actionMaster.Bowl(8));
}
[Test]
public void T03_BowlSpare_ReturnEndTurn()
{
actionMaster.Bowl(8);
Assert.AreEqual(endTurn, actionMaster.Bowl(2));
}
}
ActionMaster.cs
using UnityEngine;
using System.Collections;
public class ActionMaster {
public enum Action { Tidy, Reset, EndTurn, EndGame };
//private int[] bowls = new int[21];
private int bowl = 1;
public Action Bowl(int pins) {
if (pins < 0 || pins > 10) { throw new UnityException("Pins is out of range."); }
//Our Behaviour here.
if (pins == 10)
{
bowl += 2;
return Action.EndTurn;
}
if (bowl % 2 != 0)
{
bowl += 1;
return Action.Tidy;
} else if (bowl % 2 == 0)
{
bowl += 1;
return Action.EndTurn;
}
throw new UnityException("Not sure what to return");
}
}