forked from MetroCS/ConsoleGameHub
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWordGuessGameTest.java
More file actions
59 lines (45 loc) · 1.66 KB
/
WordGuessGameTest.java
File metadata and controls
59 lines (45 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import org.junit.jupiter.api.Test;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.Optional;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* Tests for WordGuessGame.
* @version 1
*/
public class WordGuessGameTest {
@Test
public void testCorrectGuessOnFirstTry() {
String simulatedInput = "APPLE\n";
InputStream originalIn = System.in;
System.setIn(new ByteArrayInputStream(simulatedInput.getBytes()));
WordGuessGame game = new WordGuessGame();
Optional<Integer> result = game.play();
assertTrue(result.isPresent());
assertEquals(6, result.get());
System.setIn(originalIn);
}
@Test
public void testIncorrectThenCorrectGuess() {
String simulatedInput = "MANGO\nAPPLE\n";
InputStream originalIn = System.in;
System.setIn(new ByteArrayInputStream(simulatedInput.getBytes()));
WordGuessGame game = new WordGuessGame();
Optional<Integer> result = game.play();
assertTrue(result.isPresent());
assertEquals(5, result.get());
System.setIn(originalIn);
}
@Test
public void testAllIncorrectGuesses() {
String simulatedInput = "MANGO\nGRAPE\nPLUMB\nBERRY\nPEACH\nLEMON\n";
InputStream originalIn = System.in;
System.setIn(new ByteArrayInputStream(simulatedInput.getBytes()));
WordGuessGame game = new WordGuessGame();
Optional<Integer> result = game.play();
assertTrue(result.isPresent());
assertEquals(0, result.get());
System.setIn(originalIn);
}
}