Skip to content

Instantly share code, notes, and snippets.

@QuantumFractal
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save QuantumFractal/9777013 to your computer and use it in GitHub Desktop.
Save QuantumFractal/9777013 to your computer and use it in GitHub Desktop.
ComS 227 Game Tester
package hw2;
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Random;
import java.util.Scanner;
public class GameTest
{
Game gameNormal;
Game gameWithPunctuation;
@Before
public void setup() throws FileNotFoundException
{
boolean playAgain = true;
gameNormal = new Game("TesTinG",5);
gameWithPunctuation = new Game("#T3STing!");
}
@Test
public void testBadGuesser()
{
for(int i = 0; i < 6; i++)
{
gameNormal.guessLetter('z');
}
String msg = "Guessed 'z' 5 times. The game should be over.";
assertEquals(msg,true,gameNormal.gameOver());
msg = "But you're a bad guesser so you lost :(";
assertEquals(msg,false,gameNormal.won());
}
@Test
public void testGoodGuesser()
{
String guesses = "TesTinG";
for(int i = 0; i < guesses.length(); i++)
{
gameNormal.guessLetter(guesses.charAt(i));
}
String msg = "Guessed the letters in the word The game should be over";
assertEquals(msg,true,gameNormal.gameOver());
}
@Test
public void testUnhideNonAlpha()
{
String msg = "Non alpha characters should be revealed when game is created.";
assertEquals(msg,true,"# 3 !".equals(getWord(gameWithPunctuation.getDisplayedWord())));
}
private String getWord(HideableChar[] chars)
{
String word = "";
for (int i = 0; i < chars.length; ++i)
{
if (chars[i].isHidden())
{
word+=" ";
}
else
{
word+=chars[i].getDisplayedChar();
}
}
return word;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment