-
Notifications
You must be signed in to change notification settings - Fork 48
Expand file tree
/
Copy pathYourPlayerTest.java
More file actions
60 lines (48 loc) · 2.05 KB
/
YourPlayerTest.java
File metadata and controls
60 lines (48 loc) · 2.05 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
package com.hangman.players;
import org.junit.Test;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import static org.junit.Assert.*;
public class YourPlayerTest {
@Test
public void alwaysPickNextPopularChar() {
YourPlayer player = new YourPlayer();
player.setCharStrategy(Arrays.asList(null, null, null));
//note the two most popular characters
List<Character> expectedGuesses = new ArrayList<>();
expectedGuesses.add(player.getPopularChars().get(0));
expectedGuesses.add(player.getPopularChars().get(1));
//make two guesses
char guess1 = player.getGuess(Arrays.asList(null, null, null));
char guess2 = player.getGuess(Arrays.asList(null, null, null));
System.out.println(guess1);
System.out.println(guess2);
//verify those guesses match our popular characters
assertEquals(expectedGuesses, player.getAttemptedChars());
}
@Test
public void chooseStrategyByClueSize() {
YourPlayer player = new YourPlayer();
//make a clue of a given size and feed it to player
List<Character>wordLength3Chars = Arrays.asList(null, null, null);
player.setCharStrategy(wordLength3Chars);
player.getGuess(wordLength3Chars);
List<Character>expectedPopularChars = player.wordLength3Chars;
List<Character>actualPopularChars = player.getPopularChars();
//verify they are teh same
assertEquals(expectedPopularChars, actualPopularChars);
}
@Test
public void chooseLargestStrategyIfNoMatch() {
YourPlayer player = new YourPlayer();
//make a clue of an unsupported size and feed it to player
List<Character>wordLength11Chars = Arrays.asList(null, null, null, null, null, null, null, null, null, null, null);
player.setCharStrategy(wordLength11Chars);
player.getGuess(wordLength11Chars);
List<Character>expectedPopularChars = player.wordLength10Chars;
List<Character>actualPopularChars = player.getPopularChars();
//verify they are teh same
assertEquals(expectedPopularChars, actualPopularChars);
}
}