/********************************************************************* * This is a constructor. It initializes the Logic class and the images * for cross and circle. * INPUT: none. * OUTPUT: none. *********************************************************************/ public Form1() { InitializeComponent(); logic = new Logic(); cross = Properties.Resources.kross; circle = Properties.Resources.hringur; }
public void TestDataReader() { // 1. Arrange: Logic logic = new Logic(); // 2. Act: // 3. Assert: Assert.IsNotNull(logic.dataReader); }
public void TestCurrentPlayer() { // 1. Arrange: Logic logic = new Logic(); // 2. Act: // 3. Assert: Assert.AreEqual(logic.currentPlayer, Global.PLAYER1); }
public void TestInitializedMatrix() { // 1. Arrange: Logic logic = new Logic(); // 2. Act: // 3. Assert: for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { Assert.AreEqual(logic.matrix[i][j], "E"); } } }
public void TestChangePlayer() { // 1. Arrange: Logic logic = new Logic(); // 2. Act: logic.ChangePlayers(); // 3. Assert: Assert.AreEqual(logic.currentPlayer, Global.PLAYER2); // 4. Act Again: logic.ChangePlayers(); // 5. Assert Again: Assert.AreEqual(logic.currentPlayer, Global.PLAYER1); }
public void TestTie() { // 1. Arrange: Logic logic = new Logic(); // 2. Act. // 3. Assert: Assert.IsFalse(logic.Tie() ); // 2. Act. logic.moveCounter = 9; // 3. Assert: Assert.IsTrue(logic.Tie() ); }
public void TestMoveCounter() { // 1. Arrange: Logic logic = new Logic(); // 2. Act: // 3. Assert: Assert.IsNotNull(logic.moveCounter); Assert.AreEqual(logic.moveCounter, 0); }
public void TestMarkMatrix() { // 1. Arrange: Logic logic = new Logic(); int x1 = 1, y1 = 2; int x2 = 2, y2 = 1; // 2. Act: logic.MarkMatrix(x1, y1); logic.currentPlayer = Global.PLAYER2; logic.MarkMatrix(x2, y2); // 3. Assert: Assert.AreEqual(logic.matrix[x1][y1], "X"); Assert.AreEqual(logic.matrix[x2][y2], "O"); Assert.AreEqual(logic.moveCounter, 2); for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { if (!(x1 == i && y1 == j || x2 == i && y2 == j)) { Assert.AreEqual(logic.matrix[i][j], "E"); } } } }
public void TestIsWonInTopHorizonalPositionForX() { // 1. Arrange: Logic logic = new Logic(); // 2. Act: logic.matrix[0][0] = "X"; logic.matrix[0][1] = "X"; logic.matrix[0][2] = "X"; // 3. Assert: Assert.IsTrue(logic.IsWon()); }
public void TestIsWonInRightVerticalPositionForO() { // 1. Arrange: Logic logic = new Logic(); // 2. Act: logic.matrix[2][0] = "O"; logic.matrix[2][1] = "O"; logic.matrix[2][2] = "O"; //3. Assert: Assert.IsTrue(logic.IsWon()); }
public void TestIsWonInLeftVerticalPositionForX() { // 1. Arrange: Logic logic = new Logic(); // 2. Act: logic.matrix[0][0] = "X"; logic.matrix[1][0] = "X"; logic.matrix[2][0] = "X"; //3. Assert: Assert.IsTrue(logic.IsWon()); }
public void TestIsWonInDiagonalPositionForXTopLeftToBottomRight() { // 1. Arrange: Logic logic = new Logic(); // 2. Act: logic.matrix[0][0] = "X"; logic.matrix[1][1] = "X"; logic.matrix[2][2] = "X"; //3. Assert: Assert.IsTrue(logic.IsWon()); }
public void TestIsWonForRandomGameWhereThereIsATie() { // 1. Arrange: Logic logic = new Logic(); // 2. Act: logic.matrix[0][0] = "X"; logic.matrix[0][1] = "O"; logic.matrix[0][2] = "X"; logic.matrix[1][0] = "X"; logic.matrix[1][1] = "O"; logic.matrix[1][2] = "X"; logic.matrix[2][0] = "O"; logic.matrix[2][1] = "X"; logic.matrix[2][2] = "O"; // 3. Assert: Assert.IsFalse(logic.IsWon()); }
public void TestIsAvailable() { // 1. Arrange: Logic logic = new Logic(); // 2. Act: logic.matrix[0][0] = Global.PLAYER1; logic.matrix[1][1] = Global.PLAYER2; // 3. Assert: Assert.IsTrue(logic.IsAvailable(2, 2)); Assert.IsFalse(logic.IsAvailable(1, 1)); Assert.IsFalse(logic.IsAvailable(0, 0)); }