-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
264 additions
and
185 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,121 +1,112 @@ | ||
package com.cse3310; | ||
//import static org.junit.Assert.assertArrayEquals; | ||
|
||
import static org.junit.Assert.assertArrayEquals; | ||
import org.java_websocket.WebSocket; | ||
|
||
import org.junit.Test; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Random; | ||
import java.util.Vector; | ||
|
||
import junit.framework.Test; | ||
import junit.framework.TestCase; | ||
import junit.framework.TestSuite; | ||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
/** | ||
* Unit test for simple App. | ||
*/ | ||
public class AppTest | ||
extends TestCase | ||
{ | ||
/** | ||
* Create the test case | ||
* | ||
* @param testName name of the test case | ||
*/ | ||
public AppTest( String testName ) | ||
{ | ||
super( testName ); | ||
} | ||
public class AppTest { | ||
public WebSocket conn; | ||
User user1 = new User(" ", conn); | ||
User user2 = new User(" ", conn); | ||
Vector<Game> ActiveGames = new Vector<Game>(); | ||
Vector<User> ActiveUsers = new Vector<User>(); | ||
|
||
public User findWinner(int GameId) { | ||
int totalWordCount = 0; | ||
Game g = ActiveGames.get(GameId); | ||
int most = 0; | ||
User winner = new User(); | ||
|
||
for (User u : ActiveUsers) { | ||
if (GameId == u.GameId) { | ||
if (u.wordCount > most) { | ||
most = u.wordCount; // Track user with highest score | ||
winner = u; | ||
} | ||
|
||
totalWordCount += u.wordCount; | ||
} | ||
} | ||
|
||
/** | ||
* @return the suite of tests being tested | ||
*/ | ||
public static Test suite() | ||
{ | ||
return new TestSuite( AppTest.class ); | ||
} | ||
if (totalWordCount == g.wordBank.size()) { | ||
return winner; | ||
} | ||
|
||
/** | ||
* Rigourous Test :-) | ||
*/ | ||
public void testApp() | ||
{ | ||
assertTrue( true ); | ||
return null; | ||
} | ||
|
||
public void testGame() | ||
{ | ||
assertTrue( true ); | ||
} | ||
@Test | ||
public void testFindWinner() { | ||
// Create game | ||
Game g = new Game(); | ||
g.GameId = 0; | ||
g.wordBank.add("A"); | ||
g.wordBank.add("B"); | ||
|
||
public void EndIdCase(Game G) | ||
{ | ||
ArrayList<Integer> array = new ArrayList<>(); | ||
for (int i = 0; i < 47; i++) { | ||
array.add(1); | ||
} | ||
assertEquals(2, g.wordBank.size()); | ||
|
||
G.endIds = array; | ||
ActiveGames.add(g); | ||
|
||
assertTrue(G.isEnd(1) == 0); | ||
} | ||
// Set stats | ||
user1.username = "user1"; | ||
user1.GameId = 0; | ||
user1.wordCount = 2; | ||
|
||
public void testEndIdCase() | ||
{ | ||
ArrayList<String> stringList = new ArrayList<>(); | ||
user2.username = "user2"; | ||
user2.GameId = 0; | ||
user2.wordCount = 0; | ||
|
||
// Add elements to the ArrayList | ||
stringList.add("Apple"); | ||
stringList.add("Banana"); | ||
stringList.add("Orange"); | ||
ActiveUsers.add(user1); | ||
ActiveUsers.add(user2); | ||
|
||
Game B = new Game(stringList, 1); | ||
|
||
EndIdCase(B); | ||
// Test for winner of the game | ||
assertEquals(user1, findWinner(g.GameId)); | ||
} | ||
|
||
public void gameWon(User winner) { | ||
ArrayList<User> disconnectUsers = new ArrayList<>(); | ||
|
||
public void getCompletedButtonsCase(Game G) | ||
{ | ||
ArrayList<Integer> array = new ArrayList<>(); | ||
array.add(6); | ||
array.add(7); | ||
array.add(8); | ||
array.add(9); | ||
array.add(10); | ||
array.add(11); | ||
|
||
ArrayList<Integer> result = G.getCompletedButtons(6, 11); | ||
int wonGameId = winner.GameId; | ||
|
||
for (User u : ActiveUsers) { | ||
if (u.GameId == wonGameId) { | ||
Winner e = new Winner(winner); | ||
disconnectUsers.add(u); | ||
} | ||
} | ||
|
||
assertTrue(result.containsAll(array) == array.containsAll(result)); | ||
for (User u : disconnectUsers) { | ||
ActiveUsers.remove(u); | ||
} | ||
} | ||
|
||
public void testGetCompletedButtons() | ||
{ | ||
ArrayList<String> stringList = new ArrayList<>(); | ||
stringList.add("Apple"); | ||
Game B = new Game(stringList, 1); | ||
|
||
getCompletedButtonsCase(B); | ||
} | ||
@Test | ||
public void testGameWon() { | ||
ActiveUsers.clear(); | ||
ActiveGames.clear(); | ||
|
||
User winner = new User(); | ||
winner.GameId = 0; | ||
user1.GameId = 0; | ||
user2.GameId = 0; | ||
|
||
public void GenerateGrid(Game G) { | ||
// Create a Game object | ||
ArrayList<String> stringList = new ArrayList<>(); | ||
|
||
// Add elements to the ArrayList | ||
stringList.add("CAT"); | ||
char[][] result = G.generateGrid(stringList, new ArrayList<>()); | ||
assertEquals(20, result.length); | ||
} | ||
|
||
public void testGenerateGrid() | ||
{ | ||
ArrayList<String> stringList = new ArrayList<>(); | ||
stringList.add("App"); | ||
Game B = new Game(stringList, 1); | ||
GenerateGrid(B); | ||
} | ||
ActiveUsers.add(user1); | ||
ActiveUsers.add(user2); | ||
ActiveUsers.add(winner); | ||
|
||
gameWon(winner); | ||
|
||
// Active users in the game should be cleared out | ||
assertEquals(0, ActiveUsers.size()); | ||
} | ||
} |
Oops, something went wrong.