-
Notifications
You must be signed in to change notification settings - Fork 48
Expand file tree
/
Copy pathYourPlayerTest.java
More file actions
74 lines (61 loc) · 2.78 KB
/
YourPlayerTest.java
File metadata and controls
74 lines (61 loc) · 2.78 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package com.hangman.players;
import org.junit.Test;
import java.util.Arrays;
import java.util.List;
import static junit.framework.Assert.assertTrue;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
public class YourPlayerTest {
@Test
public void testCanGetWordsThatMatchLengthSpecified() throws Exception {
String[] words = {"aboard", "accident"};
List<String> matches = YourPlayer.getWordMatchingLength(words, 6);
assertTrue(matches.contains("aboard"));
assertFalse(matches.contains("accident"));
}
@Test
public void testCanExcludeWordsThatContainMissedChar() throws Exception {
String[] words = {"aboard", "actual", "active"};
List<String> matches = YourPlayer.getWordsWithoutChars(words, 'b');
assertTrue(matches.contains("actual"));
assertFalse(matches.contains("aboard"));
}
@Test
public void testGivenAPartialMatchedStringFilterOutWordsThatDoNotQualify() throws Exception {
String[] words = {"aboard", "actual", "active"};
List<String> matches = YourPlayer.getWordMatchingPattern(words, Arrays.asList('_', 'c', '_', '_', '_', '_'));
assertTrue(matches.contains("actual"));
assertFalse(matches.contains("aboard"));
}
@Test
public void testLastGuessedCharIsReturned() throws Exception {
YourPlayer player = new YourPlayer();
char first = player.GetGuess(Arrays.asList('e', 'b', 'c'));
assertEquals(first, player.getLastCharGuessed());
}
@Test
public void testCanGetCorrectLastGuessResult() throws Exception {
YourPlayer player = new YourPlayer();
char first = player.GetGuess(Arrays.asList('_', '_', '_'));
char second = player.GetGuess(Arrays.asList('_', 'e', '_'));
assertEquals(YourPlayer.RIGHT_GUESS, player.getLastAttemptResult());
char third = player.GetGuess(Arrays.asList('_', 'e', '_'));
assertEquals(YourPlayer.WRONG_GUESS, player.getLastAttemptResult());
}
@Test
public void testCanCheckIfWeHaveMadeAtLeastOneRightGuess() throws Exception {
YourPlayer player = new YourPlayer();
char first = player.GetGuess(Arrays.asList('_', '_', '_'));
assertFalse(player.hasOneRightGuess());
char second = player.GetGuess(Arrays.asList('_', '_', '_'));
assertFalse(player.hasOneRightGuess());
char third = player.GetGuess(Arrays.asList('_', 'e', '_'));
assertTrue(player.hasOneRightGuess());
}
@Test
public void testCanGetTheMostFrequentAppearingCharInWordList() throws Exception {
String[] words = {"aboard", "actual", "active"};
char mostFrequent = YourPlayer.getMostFrequentChar(words, Arrays.asList('f', 'u', 't'));
assertEquals('a', mostFrequent);
}
}