Skip to content

Commit

Permalink
+ Assignment 3 submission
Browse files Browse the repository at this point in the history
  • Loading branch information
osamaz26 committed Mar 8, 2019
1 parent e28af02 commit db82012
Show file tree
Hide file tree
Showing 6 changed files with 196 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/oz222am_hangman/HangmanTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package oz222am_hangman;

import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.mockito.Mock;
import oz222am_hangman.Models.Words.Word;


public class HangmanTest {
@BeforeAll
public void setUp() throws Exception {
}

@AfterAll
public void tearDown() throws Exception {

}

@Mock
Word word;

}
68 changes: 68 additions & 0 deletions src/oz222am_hangman/Models/Games/GameTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package oz222am_hangman.Models.Games;

import org.junit.jupiter.api.Test;
import oz222am_hangman.Models.Words.Word;

import static org.junit.jupiter.api.Assertions.*;


public class GameTest {


@Test
public void shouldReturnTrue() throws Exception {
String input = "abc";
var word = new Word();
word.setValue(input);

var game = new Game(word);
assertTrue(game.verify('c'));
}

@Test
public void shouldDisplayCharacter() throws Exception {
String input = "abc";
var word = new Word();
word.setValue(input);

var game = new Game(word);
game.verify('c');

assertEquals(game.display(), "_ _ c ");
}


@Test
public void sholudNotSolved() throws Exception {
String input = "abc";
var word = new Word();
word.setValue(input);

var game = new Game(word);
game.verify('c');
assertFalse(game.isSolved());
}

@Test
public void sholudReturnZero() throws Exception {
String input = "abc";
var word = new Word();
word.setValue(input);

var game = new Game(word);
game.verify('c');
assertEquals(game.getFailedTries(), 0);
}

@Test
public void sholudReturnTotalOne() throws Exception {
String input = "abc";
var word = new Word();
word.setValue(input);

var game = new Game(word);
game.verify('c');
assertEquals(game.getTotalTires(), 1);
}

}
48 changes: 48 additions & 0 deletions src/oz222am_hangman/Models/Players/PlayerTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package oz222am_hangman.Models.Players;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;


public class PlayerTest {
private Player sut = new Player();

@Test
public void shouldSetValue() throws Exception {
String input = "otherName";

sut.setName(input);
assertEquals(sut.getName(), input);
}


@Test
public void shouldThrowException() {
String input = "";

assertThrows(Exception.class,
()-> sut.setName(input));
}


@Test
public void shouldReturnValue() throws Exception {
String input = "otherName";
String expected = input;
sut.setName(input); //setup sut

assertEquals(sut.getName(), expected);
}

@Test
public void shouldReturnString() throws Exception {
String input = "otherName";
String expected = "[0] Player: " + input;
sut.setName(input); //setup sut


assertEquals(sut.toString(), expected);
}
}
9 changes: 9 additions & 0 deletions src/oz222am_hangman/Models/Words/Word.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ public Word() {
}

private boolean validateValue(String word) {
if (word.isEmpty()) {
return false;
}
for (int i = 0; i < word.length(); ++i) {
if (!Character.isLetter(word.charAt(i))
) {
return false;
}
}
return true;
}

Expand Down
48 changes: 48 additions & 0 deletions src/oz222am_hangman/Models/Words/WordTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package oz222am_hangman.Models.Words;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;


public class WordTest {
private Word sut = new Word();

@Test
public void shouldSetValue() throws Exception {
String input = "otherName";

sut.setValue(input);
assertEquals(sut.getValue(), input);
}


@Test
public void shouldThrowException() {
String input = "";

assertThrows(Exception.class,
()-> sut.setValue(input));
}


@Test
public void shouldReturnValue() throws Exception {
String input = "otherName";
String expected = input;
sut.setValue(input); //setup sut

assertEquals(sut.getValue(), expected);
}

@Test
public void shouldReturnString() throws Exception {
String input = "otherName";
String expected = "[0] Word: " + input;
sut.setValue(input); //setup sut


assertEquals(sut.toString(), expected);
}
}
1 change: 1 addition & 0 deletions src/oz222am_hangman/resources/words.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ jaja
kaka
software
university
jkjkjkl]

0 comments on commit db82012

Please sign in to comment.