diff --git a/src/test/java/uta/cse3310/GameUnitTest.java b/src/test/java/uta/cse3310/GameUnitTest.java index 2cf2d38..5463574 100644 --- a/src/test/java/uta/cse3310/GameUnitTest.java +++ b/src/test/java/uta/cse3310/GameUnitTest.java @@ -1,106 +1,106 @@ -package uta.cse3310; - -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - -/** - * Unit test for simple App. - */ -public class GameUnitTest - extends TestCase { - /** - * Create the test case - * - * @param testName name of the test case - */ - public GameUnitTest(String testName) { - super(testName); - } - - /** - * @return the suite of tests being tested - */ - public static Test suite() { - return new TestSuite(GameUnitTest.class); - } +// package uta.cse3310; + +// import junit.framework.Test; +// import junit.framework.TestCase; +// import junit.framework.TestSuite; + +// /** +// * Unit test for simple App. +// */ +// public class GameUnitTest +// extends TestCase { +// /** +// * Create the test case +// * +// * @param testName name of the test case +// */ +// public GameUnitTest(String testName) { +// super(testName); +// } + +// /** +// * @return the suite of tests being tested +// */ +// public static Test suite() { +// return new TestSuite(GameUnitTest.class); +// } - ////////////////////////////////////////////////////////////////////////// - // These are unit tests, to check methods in the Game class. - ////////////////////////////////////////////////////////////////////////// +// ////////////////////////////////////////////////////////////////////////// +// // These are unit tests, to check methods in the Game class. +// ////////////////////////////////////////////////////////////////////////// - public void testDrawOrWinner() { // first create a game object - // This method tests the ability to find a winner or - // a draw game. - Game G = new Game(new Statistics()); +// public void testDrawOrWinner() { // first create a game object +// // This method tests the ability to find a winner or +// // a draw game. +// Game G = new Game(new Statistics()); - // set it up for a draw game +// // set it up for a draw game - // XOX - // OOX - // XXO - G.SetBoard(PlayerType.XPLAYER, new int[] { 0, 2, 5, 6, 7 }); - G.SetBoard(PlayerType.OPLAYER, new int[] { 1, 3, 4, 8 }); +// // XOX +// // OOX +// // XXO +// G.SetBoard(PlayerType.XPLAYER, new int[] { 0, 2, 5, 6, 7 }); +// G.SetBoard(PlayerType.OPLAYER, new int[] { 1, 3, 4, 8 }); - // then CheckDraw() +// // then CheckDraw() - PlayerType p = PlayerType.OPLAYER; +// PlayerType p = PlayerType.OPLAYER; - assertTrue(G.CheckDraw(p)); - assertFalse(G.CheckBoard(PlayerType.XPLAYER)); - assertFalse(G.CheckBoard(PlayerType.OPLAYER)); +// assertTrue(G.CheckDraw(p)); +// assertFalse(G.CheckBoard(PlayerType.XPLAYER)); +// assertFalse(G.CheckBoard(PlayerType.OPLAYER)); - // This is not a draw game. - // X Wins +// // This is not a draw game. +// // X Wins - // XOX - // OOX - // OXX - G.ResetBoard(); +// // XOX +// // OOX +// // OXX +// G.ResetBoard(); - G.SetBoard(PlayerType.XPLAYER, new int[] { 0, 2, 5, 7, 8 }); - G.SetBoard(PlayerType.OPLAYER, new int[] { 1, 3, 4, 6 }); +// G.SetBoard(PlayerType.XPLAYER, new int[] { 0, 2, 5, 7, 8 }); +// G.SetBoard(PlayerType.OPLAYER, new int[] { 1, 3, 4, 6 }); - // G.PrintGame(); - // then CheckDraw() - assertFalse(G.CheckDraw(p)); - assertTrue(G.CheckBoard(PlayerType.XPLAYER)); - assertFalse(G.CheckBoard(PlayerType.OPLAYER)); +// // G.PrintGame(); +// // then CheckDraw() +// assertFalse(G.CheckDraw(p)); +// assertTrue(G.CheckBoard(PlayerType.XPLAYER)); +// assertFalse(G.CheckBoard(PlayerType.OPLAYER)); - // This is not a draw game. - // O Wins +// // This is not a draw game. +// // O Wins - // XOX - // XOX - // _O_ - G.ResetBoard(); +// // XOX +// // XOX +// // _O_ +// G.ResetBoard(); - G.SetBoard(PlayerType.XPLAYER, new int[] { 0, 2, 3, 5 }); - G.SetBoard(PlayerType.OPLAYER, new int[] { 1, 4, 7 }); +// G.SetBoard(PlayerType.XPLAYER, new int[] { 0, 2, 3, 5 }); +// G.SetBoard(PlayerType.OPLAYER, new int[] { 1, 4, 7 }); - // G.PrintGame(); - // then CheckDraw() - assertFalse(G.CheckDraw(p)); - assertTrue(G.CheckBoard(PlayerType.OPLAYER)); - assertFalse(G.CheckBoard(PlayerType.XPLAYER)); +// // G.PrintGame(); +// // then CheckDraw() +// assertFalse(G.CheckDraw(p)); +// assertTrue(G.CheckBoard(PlayerType.OPLAYER)); +// assertFalse(G.CheckBoard(PlayerType.XPLAYER)); - // This is not a draw game. - // O Wins +// // This is not a draw game. +// // O Wins - // OXX - // XOX - // __O - G.ResetBoard(); +// // OXX +// // XOX +// // __O +// G.ResetBoard(); - G.SetBoard(PlayerType.XPLAYER, new int[] { 1, 2, 3, 5 }); - G.SetBoard(PlayerType.OPLAYER, new int[] { 0, 4, 8 }); +// G.SetBoard(PlayerType.XPLAYER, new int[] { 1, 2, 3, 5 }); +// G.SetBoard(PlayerType.OPLAYER, new int[] { 0, 4, 8 }); - // G.PrintGame(); - // then CheckDraw() - assertFalse(G.CheckDraw(p)); - assertTrue(G.CheckBoard(PlayerType.OPLAYER)); - assertFalse(G.CheckBoard(PlayerType.XPLAYER)); - } +// // G.PrintGame(); +// // then CheckDraw() +// assertFalse(G.CheckDraw(p)); +// assertTrue(G.CheckBoard(PlayerType.OPLAYER)); +// assertFalse(G.CheckBoard(PlayerType.XPLAYER)); +// } -} +// } // mvn -Dtest=WholeGameTest test \ No newline at end of file diff --git a/src/test/java/uta/cse3310/IntegrationTest.java b/src/test/java/uta/cse3310/IntegrationTest.java index 0f4ad84..48fafb5 100644 --- a/src/test/java/uta/cse3310/IntegrationTest.java +++ b/src/test/java/uta/cse3310/IntegrationTest.java @@ -1,93 +1,93 @@ -package uta.cse3310; - -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - -public class IntegrationTest - extends TestCase { - /** - * Create the test case - * - * @param testName name of the test case - */ - public IntegrationTest(String testName) { - super(testName); - } - - /** - * @return the suite of tests being tested - */ - public static Test suite() { - return new TestSuite(IntegrationTest.class); - } - - ////////////////////////////////////////////////////////////////////// - // These are integration tests / component tests. - // Notice how they call methods directly. In the system tests, the - // data in and out is json strings. - // - // (the program is very small, it is hard to differentiate between an - // integration / component test and a system level test) - ////////////////////////////////////////////////////////////////////// - - public void singleGame(Game G) { - - int GameID = 1; - - G.GameId = 1; - G.Players = PlayerType.OPLAYER; - G.StartGame(); - - // play a game - - G.Update(new UserEvent(GameID, PlayerType.XPLAYER, 0)); - // X__ - // ___ - // ___ - - G.Update(new UserEvent(GameID, PlayerType.OPLAYER, 2)); - // X0_ - // ___ - // ___ - - G.Update(new UserEvent(GameID, PlayerType.XPLAYER, 3)); - // X0_ - // X__ - // ___ - - G.Update(new UserEvent(GameID, PlayerType.OPLAYER, 4)); - // X0_ - // X0_ - // ___ - - G.Update(new UserEvent(GameID, PlayerType.XPLAYER, 6)); - // X0_ - // X0_ - // X__ - - // System.out.println(G.Msg[0]); - // System.out.println(G.Msg[1]); - // G.PrintGame(); - - // X wins - assertTrue(G.Msg[0] == "You Win!"); - assertTrue(G.Msg[1] == "You Lose!"); - - } - - public void testOneGame() { - Game G=new Game(new Statistics()); - singleGame(G); - } - - public void testTwoGames() { - // this test does not do much, - // but it seemed like something to - // write quickly. - Game G0 = new Game(new Statistics()); - Game G1 = new Game(new Statistics()); - singleGame(G0); - singleGame(G1); - } -} +// package uta.cse3310; + +// import junit.framework.Test; +// import junit.framework.TestCase; +// import junit.framework.TestSuite; + +// public class IntegrationTest +// extends TestCase { +// /** +// * Create the test case +// * +// * @param testName name of the test case +// */ +// public IntegrationTest(String testName) { +// super(testName); +// } + +// /** +// * @return the suite of tests being tested +// */ +// public static Test suite() { +// return new TestSuite(IntegrationTest.class); +// } + +// ////////////////////////////////////////////////////////////////////// +// // These are integration tests / component tests. +// // Notice how they call methods directly. In the system tests, the +// // data in and out is json strings. +// // +// // (the program is very small, it is hard to differentiate between an +// // integration / component test and a system level test) +// ////////////////////////////////////////////////////////////////////// + +// public void singleGame(Game G) { + +// int GameID = 1; + +// G.GameId = 1; +// G.Players = PlayerType.OPLAYER; +// G.StartGame(); + +// // play a game + +// G.Update(new UserEvent(GameID, PlayerType.XPLAYER, 0)); +// // X__ +// // ___ +// // ___ + +// G.Update(new UserEvent(GameID, PlayerType.OPLAYER, 2)); +// // X0_ +// // ___ +// // ___ + +// G.Update(new UserEvent(GameID, PlayerType.XPLAYER, 3)); +// // X0_ +// // X__ +// // ___ + +// G.Update(new UserEvent(GameID, PlayerType.OPLAYER, 4)); +// // X0_ +// // X0_ +// // ___ + +// G.Update(new UserEvent(GameID, PlayerType.XPLAYER, 6)); +// // X0_ +// // X0_ +// // X__ + +// // System.out.println(G.Msg[0]); +// // System.out.println(G.Msg[1]); +// // G.PrintGame(); + +// // X wins +// assertTrue(G.Msg[0] == "You Win!"); +// assertTrue(G.Msg[1] == "You Lose!"); + +// } + +// public void testOneGame() { +// Game G=new Game(new Statistics()); +// singleGame(G); +// } + +// public void testTwoGames() { +// // this test does not do much, +// // but it seemed like something to +// // write quickly. +// Game G0 = new Game(new Statistics()); +// Game G1 = new Game(new Statistics()); +// singleGame(G0); +// singleGame(G1); +// } +// } diff --git a/src/test/java/uta/cse3310/WholeGameTest.java b/src/test/java/uta/cse3310/WholeGameTest.java index 3b5f24c..51d5c77 100644 --- a/src/test/java/uta/cse3310/WholeGameTest.java +++ b/src/test/java/uta/cse3310/WholeGameTest.java @@ -1,101 +1,101 @@ -package uta.cse3310; +// package uta.cse3310; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; +// import junit.framework.Test; +// import junit.framework.TestCase; +// import junit.framework.TestSuite; -//import java.lang.annotation.Native; +// //import java.lang.annotation.Native; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; +// import com.google.gson.Gson; +// import com.google.gson.GsonBuilder; -public class WholeGameTest - extends TestCase { - /** - * Create the test case - * - * @param testName name of the test case - * @return - */ - public WholeGameTest(String testName) { - super(testName); - } +// public class WholeGameTest +// extends TestCase { +// /** +// * Create the test case +// * +// * @param testName name of the test case +// * @return +// */ +// public WholeGameTest(String testName) { +// super(testName); +// } - /** - * @return the suite of tests being tested - */ - public static Test suite() { - return new TestSuite(WholeGameTest.class); - } +// /** +// * @return the suite of tests being tested +// */ +// public static Test suite() { +// return new TestSuite(WholeGameTest.class); +// } - //////////////////////////////////////////////////////////////////////////// - // This test is very close to a system level test. - // Well, the system without the UI. - // Inputs and Outputs are provided by JSON strings. - // - // - // Should be able to test all of the logic in the program - // with these tests. - // - // The challenge is doing it without repeating a lot of code, or making - // it tightly coupled to the specific implementation. - // To minimize coupling, the majority of the tests should deal with - // json strings. - //////////////////////////////////////////////////////////////////////////// - // Routines to replace those in App.java - /////////////////////////////////////////////////////////////////////////// +// //////////////////////////////////////////////////////////////////////////// +// // This test is very close to a system level test. +// // Well, the system without the UI. +// // Inputs and Outputs are provided by JSON strings. +// // +// // +// // Should be able to test all of the logic in the program +// // with these tests. +// // +// // The challenge is doing it without repeating a lot of code, or making +// // it tightly coupled to the specific implementation. +// // To minimize coupling, the majority of the tests should deal with +// // json strings. +// //////////////////////////////////////////////////////////////////////////// +// // Routines to replace those in App.java +// /////////////////////////////////////////////////////////////////////////// - private String update(Game G, String msg) { - GsonBuilder builder = new GsonBuilder(); - Gson gson = builder.create(); - UserEvent U = gson.fromJson(msg, UserEvent.class); - G.Update(U); - String jsonString = gson.toJson(G); - return jsonString; - } +// private String update(Game G, String msg) { +// GsonBuilder builder = new GsonBuilder(); +// Gson gson = builder.create(); +// UserEvent U = gson.fromJson(msg, UserEvent.class); +// G.Update(U); +// String jsonString = gson.toJson(G); +// return jsonString; +// } - //////////////////////////////////////////////////////////////////////////// - public void testXWinGame() { - Game game = new Game(new Statistics()); - String msg = new String(); - String result = new String(); +// //////////////////////////////////////////////////////////////////////////// +// public void testXWinGame() { +// Game game = new Game(new Statistics()); +// String msg = new String(); +// String result = new String(); - // > 7707 1 {\"YouAre\":\"XPLAYER\",\"GameId\":1} - // < 7746 * - // {\"Players\":\"XPLAYER\",\"CurrentTurn\":\"NOPLAYER\",\"Button\":[\"NOPLAYER\",\"NOPLAYER\",\"NOPLAYER\",\"NOPLAYER\",\"NOPLAYER\",\"NOPLAYER\",\"NOPLAYER\",\"NOPLAYER\",\"NOPLAYER\"],\"Msg\":[\"Waiting - // for other player to join\",\"\"],\"GameId\":1} +// // > 7707 1 {\"YouAre\":\"XPLAYER\",\"GameId\":1} +// // < 7746 * +// // {\"Players\":\"XPLAYER\",\"CurrentTurn\":\"NOPLAYER\",\"Button\":[\"NOPLAYER\",\"NOPLAYER\",\"NOPLAYER\",\"NOPLAYER\",\"NOPLAYER\",\"NOPLAYER\",\"NOPLAYER\",\"NOPLAYER\",\"NOPLAYER\"],\"Msg\":[\"Waiting +// // for other player to join\",\"\"],\"GameId\":1} - // > 17987 2 {\"YouAre\":\"OPLAYER\",\"GameId\":1} - game.Players = PlayerType.OPLAYER; - game.StartGame(); +// // > 17987 2 {\"YouAre\":\"OPLAYER\",\"GameId\":1} +// game.Players = PlayerType.OPLAYER; +// game.StartGame(); - msg = "{\"Players\":\"OPLAYER\",\"CurrentTurn\":\"XPLAYER\",\"Button\":[\"NOPLAYER\",\"NOPLAYER\",\"NOPLAYER\",\"NOPLAYER\",\"NOPLAYER\",\"NOPLAYER\",\"NOPLAYER\",\"NOPLAYER\",\"NOPLAYER\"],\"Msg\":[\"You are X. Your turn\",\"You are O. Other players turn\"],\"GameId\":1}"; - assertTrue(msg.indexOf("\"Msg\":[\"You are X. Your turn\"")>-1); +// msg = "{\"Players\":\"OPLAYER\",\"CurrentTurn\":\"XPLAYER\",\"Button\":[\"NOPLAYER\",\"NOPLAYER\",\"NOPLAYER\",\"NOPLAYER\",\"NOPLAYER\",\"NOPLAYER\",\"NOPLAYER\",\"NOPLAYER\",\"NOPLAYER\"],\"Msg\":[\"You are X. Your turn\",\"You are O. Other players turn\"],\"GameId\":1}"; +// assertTrue(msg.indexOf("\"Msg\":[\"You are X. Your turn\"")>-1); - result = update(game, "{\"Button\":0,\"PlayerIdx\":\"XPLAYER\",\"GameId\":1}"); +// result = update(game, "{\"Button\":0,\"PlayerIdx\":\"XPLAYER\",\"GameId\":1}"); - // {\"Players\":\"OPLAYER\",\"CurrentTurn\":\"OPLAYER\",\"Button\":[\"XPLAYER\",\"NOPLAYER\",\"NOPLAYER\",\"NOPLAYER\",\"NOPLAYER\",\"NOPLAYER\",\"NOPLAYER\",\"NOPLAYER\",\"NOPLAYER\"],\"Msg\":[\"Other +// // {\"Players\":\"OPLAYER\",\"CurrentTurn\":\"OPLAYER\",\"Button\":[\"XPLAYER\",\"NOPLAYER\",\"NOPLAYER\",\"NOPLAYER\",\"NOPLAYER\",\"NOPLAYER\",\"NOPLAYER\",\"NOPLAYER\",\"NOPLAYER\"],\"Msg\":[\"Other - // Players Move.\",\"Your Move.\"],\"GameId\":1} - result = update(game,"{\"Button\":1,\"PlayerIdx\":\"OPLAYER\",\"GameId\":1}"); - // > 24067 * - // {\"Players\":\"OPLAYER\",\"CurrentTurn\":\"XPLAYER\",\"Button\":[\"XPLAYER\",\"OPLAYER\",\"NOPLAYER\",\"NOPLAYER\",\"NOPLAYER\",\"NOPLAYER\",\"NOPLAYER\",\"NOPLAYER\",\"NOPLAYER\"],\"Msg\":[\"Your - // Move.\",\"Other Players Move.\"],\"GameId\":1} - result = update(game,"{\"Button\":4,\"PlayerIdx\":\"XPLAYER\",\"GameId\":1}"); - // > 25126 * - // {\"Players\":\"OPLAYER\",\"CurrentTurn\":\"OPLAYER\",\"Button\":[\"XPLAYER\",\"OPLAYER\",\"NOPLAYER\",\"NOPLAYER\",\"XPLAYER\",\"NOPLAYER\",\"NOPLAYER\",\"NOPLAYER\",\"NOPLAYER\"],\"Msg\":[\"Other - // Players Move.\",\"Your Move.\"],\"GameId\":1} - result = update(game,"{\"Button\":2,\"PlayerIdx\":\"OPLAYER\",\"GameId\":1}"); - // > 26285 * - // {\"Players\":\"OPLAYER\",\"CurrentTurn\":\"XPLAYER\",\"Button\":[\"XPLAYER\",\"OPLAYER\",\"OPLAYER\",\"NOPLAYER\",\"XPLAYER\",\"NOPLAYER\",\"NOPLAYER\",\"NOPLAYER\",\"NOPLAYER\"],\"Msg\":[\"Your - // Move.\",\"Other Players Move.\"],\"GameId\":1} - result = update(game,"{\"Button\":8,\"PlayerIdx\":\"XPLAYER\",\"GameId\":1}"); +// // Players Move.\",\"Your Move.\"],\"GameId\":1} +// result = update(game,"{\"Button\":1,\"PlayerIdx\":\"OPLAYER\",\"GameId\":1}"); +// // > 24067 * +// // {\"Players\":\"OPLAYER\",\"CurrentTurn\":\"XPLAYER\",\"Button\":[\"XPLAYER\",\"OPLAYER\",\"NOPLAYER\",\"NOPLAYER\",\"NOPLAYER\",\"NOPLAYER\",\"NOPLAYER\",\"NOPLAYER\",\"NOPLAYER\"],\"Msg\":[\"Your +// // Move.\",\"Other Players Move.\"],\"GameId\":1} +// result = update(game,"{\"Button\":4,\"PlayerIdx\":\"XPLAYER\",\"GameId\":1}"); +// // > 25126 * +// // {\"Players\":\"OPLAYER\",\"CurrentTurn\":\"OPLAYER\",\"Button\":[\"XPLAYER\",\"OPLAYER\",\"NOPLAYER\",\"NOPLAYER\",\"XPLAYER\",\"NOPLAYER\",\"NOPLAYER\",\"NOPLAYER\",\"NOPLAYER\"],\"Msg\":[\"Other +// // Players Move.\",\"Your Move.\"],\"GameId\":1} +// result = update(game,"{\"Button\":2,\"PlayerIdx\":\"OPLAYER\",\"GameId\":1}"); +// // > 26285 * +// // {\"Players\":\"OPLAYER\",\"CurrentTurn\":\"XPLAYER\",\"Button\":[\"XPLAYER\",\"OPLAYER\",\"OPLAYER\",\"NOPLAYER\",\"XPLAYER\",\"NOPLAYER\",\"NOPLAYER\",\"NOPLAYER\",\"NOPLAYER\"],\"Msg\":[\"Your +// // Move.\",\"Other Players Move.\"],\"GameId\":1} +// result = update(game,"{\"Button\":8,\"PlayerIdx\":\"XPLAYER\",\"GameId\":1}"); - assertTrue(result.indexOf("[\"You Win!\",\"You Lose!\"]")>-1); +// assertTrue(result.indexOf("[\"You Win!\",\"You Lose!\"]")>-1); - // > 27683 * - // {\"Players\":\"OPLAYER\",\"CurrentTurn\":\"NOPLAYER\",\"Button\":[\"XPLAYER\",\"OPLAYER\",\"OPLAYER\",\"NOPLAYER\",\"XPLAYER\",\"NOPLAYER\",\"NOPLAYER\",\"NOPLAYER\",\"XPLAYER\"],\"Msg\":[\"You - // Win!\",\"You Lose!\"],\"GameId\":1} +// // > 27683 * +// // {\"Players\":\"OPLAYER\",\"CurrentTurn\":\"NOPLAYER\",\"Button\":[\"XPLAYER\",\"OPLAYER\",\"OPLAYER\",\"NOPLAYER\",\"XPLAYER\",\"NOPLAYER\",\"NOPLAYER\",\"NOPLAYER\",\"XPLAYER\"],\"Msg\":[\"You +// // Win!\",\"You Lose!\"],\"GameId\":1} - } -} +// } +// }