Skip to content

Instantly share code, notes, and snippets.

@joshalanwagner
Last active September 25, 2015 06:43
Show Gist options
  • Select an option

  • Save joshalanwagner/54a30bec5e19048941b1 to your computer and use it in GitHub Desktop.

Select an option

Save joshalanwagner/54a30bec5e19048941b1 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using NUnit.Framework;
using UnityEngine;
[TestFixture]
public class ActionMasterTest
{
private ActionMaster.Action endTurn = ActionMaster.Action.EndTurn;
private ActionMaster.Action tidy = ActionMaster.Action.Tidy;
private ActionMaster.Action endGame = ActionMaster.Action.EndGame;
private ActionMaster.Action reset = ActionMaster.Action.Reset;
private ActionMaster actionMaster;
[SetUp]
public void Setup ()
{
actionMaster = new ActionMaster ();
}
// Misc Tests
[Test]
public void MT01SpareGivesSpareResult ()
{
actionMaster.Bowl (6);
actionMaster.Bowl (4);
Assert.AreEqual (actionMaster.result, "spare");
}
[Test]
public void MT02StrikeGivesStrikeResult ()
{
actionMaster.Bowl (10);
Assert.AreEqual (actionMaster.result, "strike");
}
// RETURN ACTION Tests
[Test]
public void T01OneStrikeReturnsEndTurn ()
{
Assert.AreEqual (endTurn, actionMaster.Bowl(10));
}
[Test]
public void T02Bowl8ReturnsTidy ()
{
Assert.AreEqual (tidy, actionMaster.Bowl(8));
}
[Test]
public void T03Bowl28SpareReturnsEndTurn ()
{
actionMaster.Bowl (2);
Assert.AreEqual (endTurn, actionMaster.Bowl(8));
}
[Test]
public void T04DoneOnTwenty () // Never get a spare or strike, then you get 20 bowls.
{
for (int i = 0; i < 19; i++)
{
actionMaster.Bowl (2);
}
Assert.AreEqual (endGame, actionMaster.Bowl(3)); // don't get a spare or strike
}
[Test]
public void T05Frame10Ball1StrikeReset ()
{
for (int i = 0; i < 9; i++)
{
actionMaster.Bowl (10);
}
Assert.AreEqual (reset, actionMaster.Bowl(10)); // One more turn.
}
[Test]
public void T06Frame10Ball2StrikeReset () // Only return tidy if last two bowls are strikes.
{
for (int i = 0; i < 9; i++)
{
actionMaster.Bowl (10);
}
actionMaster.Bowl (10); // frame 10 ball 1 strike
Assert.AreEqual (reset, actionMaster.Bowl(10)); // One more turn.
}
[Test]
public void T07Frame10Ball3StrikeEndsGame () // Make sure game ends when all 12 strikes.
{
for (int i = 0; i < 10; i++)
{
actionMaster.Bowl (10);
}
actionMaster.Bowl (10); // frame 10 ball 2 strike
Assert.AreEqual (endGame, actionMaster.Bowl(10));
}
[Test]
public void T08Frame11SpareGetsReset ()
{
for (int i = 0; i < 18; i++)
{
actionMaster.Bowl (3);
}
actionMaster.Bowl (7); // frame 10 ball 1
Assert.AreEqual (reset, actionMaster.Bowl(3)); // Spare gets one more turn.
}
[Test] // Need to test for end game when no spare or strike at end.
public void T09Frame10NoSpareGetsEndGame ()
{
for (int i = 0; i < 18; i++)
{
actionMaster.Bowl (3);
}
actionMaster.Bowl (7); // frame 10 ball 1
Assert.AreEqual (endGame, actionMaster.Bowl(2)); // Game over
}
// FRAME SCORE Tests
[Test]
public void ST01BowlTwiceNoSpareNoStrikeFrameScoreAdded ()
{
actionMaster.Bowl (4);
actionMaster.Bowl (3);
Assert.AreEqual (4 + 3, actionMaster.frameScore[1]);
}
[Test]
public void ST02StrikePlus7Plus3Equals20 ()
{
int[] rolls = {10, 7,3};
foreach (int roll in rolls)
{
actionMaster.Bowl (roll);
}
Assert.AreEqual (20, actionMaster.frameScore[1]);
}
[Test]
public void ST03SparePlus7Plus3Equals17 ()
{
int[] rolls = {6,4 , 7};
foreach (int roll in rolls)
{
actionMaster.Bowl (roll);
}
Assert.AreEqual (17, actionMaster.frameScore[1]);
}
[Test]
public void ST04TurkeyEquals30InFirstFrame ()
{
int[] rolls = {10, 10, 10};
foreach (int roll in rolls)
{
actionMaster.Bowl (roll);
}
Assert.AreEqual (30, actionMaster.frameScore[1]);
}
// bowls: X,X,7,3,2 scores: 27, 47, 59,
[Test]
public void ST05BowlXX732FirstFrameIs27 ()
{
int[] rolls = {10, 10, 7, 3, 2};
foreach (int roll in rolls)
{
actionMaster.Bowl (roll);
}
Assert.AreEqual (27, actionMaster.frameScore[1]);
}
[Test]
public void ST06BowlXX732SecondFrameIs47 ()
{
int[] rolls = {10, 10, 7, 3, 2};
foreach (int roll in rolls)
{
actionMaster.Bowl (roll);
}
Assert.AreEqual (47, actionMaster.frameScore[2]);
}
[Test]
public void ST07BowlXX732ThirdFrameIs59 ()
{
int[] rolls = {10, 10, 7, 3, 2};
foreach (int roll in rolls)
{
actionMaster.Bowl (roll);
}
Assert.AreEqual (59, actionMaster.frameScore[3]);
}
// bowls: 3,0,X,9,1,2,1 frame scores: 3, 23, 35, 38
[Test]
public void ST08Bowl30X9121SecondFrame ()
{
int[] rolls = {3, 0, 10, 9, 1, 2, 1};
foreach (int roll in rolls)
{
actionMaster.Bowl (roll);
}
Assert.AreEqual (23, actionMaster.frameScore[2]);
}
[Test]
public void ST09Bowl30X9121ThirdFrame ()
{
int[] rolls = {3, 0, 10, 9, 1, 2, 1};
foreach (int roll in rolls)
{
actionMaster.Bowl (roll);
}
Assert.AreEqual (35, actionMaster.frameScore[3]);
}
[Test]
public void ST10Bowl30X9121ForthFrame ()
{
int[] rolls = {3, 0, 10, 9, 1, 2, 1};
foreach (int roll in rolls)
{
actionMaster.Bowl (roll);
}
Assert.AreEqual (38, actionMaster.frameScore[4]);
}
[Test]
public void ST11PerfectGameScore () // 300
{
for (int i = 0; i < 10; i++)
{
actionMaster.Bowl (10);
}
actionMaster.Bowl (10); // frame 10 ball 2 strike
actionMaster.Bowl (10); // frame 10 ball 3 strike
Assert.AreEqual (300, actionMaster.frameScore[10]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment