Skip to content

Commit

Permalink
Added tests for App.java in AppTest.java
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan45RS committed May 2, 2024
1 parent 90a11dd commit 0c900ea
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
12 changes: 1 addition & 11 deletions src/main/java/uta/cse3310/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class App extends WebSocketServer implements GameEventListener {
// Create an appendable map to store players
private Map<String, Player> playerMap = new HashMap<>();
// Create an appendable map to store games
public Map<String, Game> gameMap = new HashMap<>();
private Map<String, Game> gameMap = new HashMap<>();
// Create a map to store the connection and the username
private Map<WebSocket, String> connectionUserMap = new HashMap<>();

Expand Down Expand Up @@ -570,16 +570,6 @@ public void broadcastScore(String roomId) {
}
}

public Map getGameMap()
{
return gameMap;
}

public void setGameMap(Map gameMap)
{
this.gameMap = gameMap;
}

public static void main(String[] args) {
int httpPort = 9018;
String httpPortEnv = System.getenv("HTTP_PORT");
Expand Down
11 changes: 8 additions & 3 deletions src/test/java/uta/cse3310/AppTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.java_websocket.WebSocket;
import org.java_websocket.exceptions.WebsocketNotConnectedException;


public class AppTest extends TestCase {
Expand All @@ -24,19 +26,22 @@ public void testApp() {

// // Test case 2: Ensure gameMap is empty initially
// assertTrue(app.getGameMap().isEmpty());

// App Testing
App A = new App(8070);
assertTrue(A.gameMap.size() == 5);
assertTrue(A.getGameMap().size() == 5);
assertTrue(A.getPlayerMap().size() == 0);
assertTrue(A.getConnectionUserMap().isEmpty());

// Player testing
Player P = new Player("abcd", null);
P.setInGameScore(0);
P.incrementScore();
P.setColorChoice("Blue");
P.setGamesWon(1);
assertTrue(P.getUsername() != null);
assertTrue(P.getGamesWon() != 0);
assertTrue(P.getInGameScore() != 0);
assertTrue(P.getInGameScore() == 1); // checks if score has been

// Chat testing
Chat C = new Chat();
Expand Down

0 comments on commit 0c900ea

Please sign in to comment.