feat: implemented RandomWordGenerator

This commit is contained in:
Yannik Bretschneider 2021-06-05 23:10:56 +02:00
parent 11559d1f56
commit b0a37d63f8
2 changed files with 158 additions and 0 deletions

View File

@ -0,0 +1,141 @@
package uulm.teamname.marvelous.server.lobbymanager;
import java.util.Locale;
import java.util.Random;
public class RandomWordGenerator {
private static Random random = new Random();
public static String generateTwoWords() {
var firstWord = randomWords[random.nextInt(randomWords.length)];
var secondWord = randomWords[random.nextInt(randomWords.length)];
while (firstWord.equals(secondWord)) {
secondWord = randomWords[random.nextInt(randomWords.length)];
}
firstWord = firstWord.substring(0, 1).toUpperCase() + firstWord.substring(1).toLowerCase();
secondWord = secondWord.substring(0, 1).toUpperCase() + secondWord.substring(1).toLowerCase();
return firstWord + secondWord;
}
private static final String[] randomWords = new String[] {
"wait",
"release",
"river",
"important",
"mark",
"electric",
"defective",
"poke",
"blue",
"beef",
"spring",
"hurt",
"orange",
"happy",
"zealous",
"flowery",
"accurate",
"brake",
"title",
"x-ray",
"festive",
"wrathful",
"scissors",
"peaceful",
"finicky",
"shape",
"soothe",
"head",
"spotted",
"needless",
"time",
"abundant",
"humdrum",
"mouth",
"trot",
"bounce",
"thank",
"avoid",
"shocking",
"minor",
"secret",
"rabbit",
"protect",
"honey",
"business",
"worthless",
"suggest",
"splendid",
"drab",
"safe",
"gigantic",
"arrive",
"drum",
"hate",
"dinosaurs",
"bore",
"tired",
"regret",
"fit",
"potato",
"confuse",
"childlike",
"vein",
"sound",
"attack",
"exchange",
"back",
"check",
"damaged",
"grandmother",
"division",
"groovy",
"throat",
"office",
"pin",
"stare",
"meddle",
"shivering",
"interfere",
"occur",
"hole",
"sugar",
"test",
"blind",
"free",
"perform",
"cherries",
"flavor",
"stupendous",
"purpose",
"extend",
"risk",
"fanatical",
"grubby",
"beg",
"romantic",
"outrageous",
"swift",
"bath",
"room",
"pocket",
"front",
"flower",
"quicksand",
"mark",
"sturdy",
"resolute",
"letters",
"expert",
"hapless",
"bloody",
"blue-eyed",
"hope",
"chew",
};
}

View File

@ -0,0 +1,17 @@
package uulm.teamname.marvelous.server.lobbymanager;
import org.junit.jupiter.api.Test;
import static org.mockito.Mockito.*;
import static org.junit.jupiter.api.Assertions.*;
import static org.assertj.core.api.Assertions.*;
class RandomWordGeneratorTest {
@Test
void generatesAString() {
// System.out.println(RandomWordGenerator.generateTwoWords());
assertThat(RandomWordGenerator.generateTwoWords()).isInstanceOf(String.class);
}
}