public void TestSatisfiabilityCombination() { var tally = new GridTally(1); tally[0] = 3; Assert.AreEqual(Satisfiability.VIOLATED, tally.GetSatisfiability(new int[1] { 1 }, new int[1] { 1 })); Assert.AreEqual(Satisfiability.SATISFIABLE, tally.GetSatisfiability(new int[1] { 1 }, new int[1] { 2 })); Assert.AreEqual(Satisfiability.SATISFIED, tally.GetSatisfiability(new int[1] { 3 }, new int[1] { 0 })); Assert.AreEqual(Satisfiability.SATISFIED, tally.GetSatisfiability(new int[1] { 3 }, new int[1] { 1 })); Assert.AreEqual(Satisfiability.VIOLATED, tally.GetSatisfiability(new int[1] { 4 }, new int[1] { 0 })); }
public void TestDefaultValueZero() { var tally = new GridTally(3); for (int i = 0; i < tally.Length; i++) { Assert.AreEqual(0, tally[i]); } }
public IGame GenerateEmptyGame(int numRows, int numColumns) { var rowTally = new GridTally(numRows); var columnTally = new GridTally(numColumns); var shipSettings = new ShipTarget(); var grid = new BimaruGrid(numRows, numColumns); return(new Game(rowTally, columnTally, shipSettings, grid)); }
public void TestSatisfiabilityMoreThanOne() { var tally = new GridTally(2); tally[0] = 1; tally[1] = 2; Assert.AreEqual(Satisfiability.SATISFIABLE, tally.GetSatisfiability(new int[2] { 0, 0 }, new int[2] { 1, 2 })); Assert.AreEqual(Satisfiability.SATISFIABLE, tally.GetSatisfiability(new int[2] { 1, 0 }, new int[2] { 0, 2 })); Assert.AreEqual(Satisfiability.SATISFIABLE, tally.GetSatisfiability(new int[2] { 0, 2 }, new int[2] { 1, 0 })); Assert.AreEqual(Satisfiability.SATISFIED, tally.GetSatisfiability(new int[2] { 1, 2 }, new int[2] { 0, 0 })); Assert.AreEqual(Satisfiability.VIOLATED, tally.GetSatisfiability(new int[2] { 2, 1 }, new int[2] { 0, 1 })); Assert.AreEqual(Satisfiability.VIOLATED, tally.GetSatisfiability(new int[2] { 0, 3 }, new int[2] { 1, 0 })); Assert.AreEqual(Satisfiability.VIOLATED, tally.GetSatisfiability(new int[2] { 2, 2 }, new int[2] { 0, 0 })); Assert.AreEqual(Satisfiability.VIOLATED, tally.GetSatisfiability(new int[2] { 1, 3 }, new int[2] { 0, 0 })); Assert.AreEqual(Satisfiability.VIOLATED, tally.GetSatisfiability(new int[2] { 2, 3 }, new int[2] { 0, 0 })); }
public void TestValueSet() { var tally = new GridTally(3); tally[0] = 7; tally[1] = 5; tally[2] = 0; Assert.AreEqual(7, tally[0]); Assert.AreEqual(5, tally[1]); Assert.AreEqual(0, tally[2]); }
public void TestValueRange() { var tally = new GridTally(3); Assert.ThrowsException <ArgumentOutOfRangeException>(() => tally[0] = -10); Assert.ThrowsException <ArgumentOutOfRangeException>(() => tally[1] = -2); Assert.ThrowsException <ArgumentOutOfRangeException>(() => tally[2] = -1); tally[0] = 0; tally[1] = 1; tally[2] = 10; }
public void TestSatisfiabilityLengthRange() { var tally = new GridTally(3); Assert.ThrowsException <ArgumentOutOfRangeException>(() => tally.GetSatisfiability(new int[2], new int[2])); Assert.ThrowsException <ArgumentOutOfRangeException>(() => tally.GetSatisfiability(new int[2], new int[3])); Assert.ThrowsException <ArgumentOutOfRangeException>(() => tally.GetSatisfiability(new int[3], new int[2])); tally.GetSatisfiability(new int[3], new int[3]); Assert.ThrowsException <ArgumentOutOfRangeException>(() => tally.GetSatisfiability(new int[3], new int[4])); Assert.ThrowsException <ArgumentOutOfRangeException>(() => tally.GetSatisfiability(new int[4], new int[3])); Assert.ThrowsException <ArgumentOutOfRangeException>(() => tally.GetSatisfiability(new int[4], new int[4])); }
public void TestLength() { GridTally tally; tally = new GridTally(1); Assert.AreEqual(1, tally.Length); tally = new GridTally(2); Assert.AreEqual(2, tally.Length); tally = new GridTally(10); Assert.AreEqual(10, tally.Length); }
public void TestNullArguments() { int numRows = 4; int numColumns = 3; var rowTally = new GridTally(numRows); var columnTally = new GridTally(numColumns); var shipTarget = new ShipTarget(); var grid = new BimaruGrid(numRows, numColumns); Assert.ThrowsException <ArgumentNullException>(() => new Game(null, columnTally, shipTarget, grid)); Assert.ThrowsException <ArgumentNullException>(() => new Game(rowTally, null, shipTarget, grid)); Assert.ThrowsException <ArgumentNullException>(() => new Game(rowTally, columnTally, null, grid)); Assert.ThrowsException <ArgumentNullException>(() => new Game(rowTally, columnTally, shipTarget, null)); }
public void TestColumnTallyGridMismatch() { GridTally rowTally = new GridTally(4); GridTally columnTally; var shipTarget = new ShipTarget(); var grid = new BimaruGrid(4, 3); columnTally = new GridTally(2); Assert.ThrowsException <ArgumentOutOfRangeException>(() => new Game(rowTally, columnTally, shipTarget, grid)); columnTally = new GridTally(3); new Game(rowTally, columnTally, shipTarget, grid); columnTally = new GridTally(4); Assert.ThrowsException <ArgumentOutOfRangeException>(() => new Game(rowTally, columnTally, shipTarget, grid)); }
public void TestTotal() { var tally = new GridTally(3); Assert.AreEqual(0, tally.Total); tally[0] = 7; Assert.AreEqual(7, tally.Total); tally[1] = 5; Assert.AreEqual(12, tally.Total); tally[2] = 0; Assert.AreEqual(12, tally.Total); }
public void TestIndex() { int length = 3; var tally = new GridTally(length); Assert.ThrowsException <IndexOutOfRangeException>(() => tally[-10]); Assert.ThrowsException <IndexOutOfRangeException>(() => tally[-2]); Assert.ThrowsException <IndexOutOfRangeException>(() => tally[-1]); int dummy; dummy = tally[0]; dummy = tally[length - 1]; Assert.ThrowsException <IndexOutOfRangeException>(() => tally[length]); Assert.ThrowsException <IndexOutOfRangeException>(() => tally[length + 1]); Assert.ThrowsException <IndexOutOfRangeException>(() => tally[length + 10]); }
public void TestEnumerator() { var tally = new GridTally(3); tally[0] = 7; tally[1] = 5; tally[2] = 0; Assert.AreEqual(tally.Length, tally.Count()); int index = 0; foreach (int t in tally) { Assert.AreEqual(tally[index], t); index++; } }