Пример #1
0
  @Test
  public void testWordLen3() throws Exception {
    System.out.println("TEST: the score of a correct word of 3 letters");

    Container.getInstance().setWord("see");
    Container.getInstance().setPlayerScore(0);

    assertEquals(
        "The score for a correct word with length 3 should be 1!",
        1,
        OnePlayer.computeScore(Container.getInstance().getWord().length()));
  }
Пример #2
0
  @Test
  public void testSubmittignWord() throws Exception {
    System.out.println("TEST: submitting word");

    InputStream r = this.getClass().getClassLoader().getResourceAsStream("english-dictionary.txt");
    Dictionary dict = new Dictionary(r);

    HashMap dictionary = new HashMap();
    ArrayList<String> wordList = new ArrayList<>();

    try {
      BufferedReader bf =
          new BufferedReader(
              new InputStreamReader(
                  this.getClass()
                      .getClassLoader()
                      .getResourceAsStream(("english-dictionary.txt"))));
      String word;

      while ((word = bf.readLine()) != null) {
        dictionary.put(word, word);
      }

      Container.getInstance().setDictionary(dictionary);
      Container.getInstance().setWordList(wordList);

      OnePlayer.submitWord("I");
      OnePlayer.submitWord("three");
      OnePlayer.submitWord("tree");
      OnePlayer.submitWord("tree");
      System.out.println(wordList.toString());
    } catch (Exception e) {
      System.out.println("");
      System.out.println(e);
    }

    assertTrue(
        "The user can not submit the same word more than one time, the expected array size is 2",
        wordList.size() == 2);
  }
Пример #3
0
  @Test
  public void testWordLen012() throws Exception {
    System.out.println("TEST: the score of a correct word of 1 or 2 letters");

    int i = 0;
    Container.getInstance().setPlayerScore(0);
    Container.getInstance().setWord("I");
    i += OnePlayer.computeScore(Container.getInstance().getWord().length());
    Container.getInstance().setWord("hi");
    i += OnePlayer.computeScore(Container.getInstance().getWord().length());

    assertEquals(
        "The score for a correct word with length 1 or 2 should be 0!",
        0,
        Container.getInstance().getPlayerScore());
  }
Пример #4
0
  @Test
  public void testScore() throws Exception {
    System.out.println("TEST: the score increases as the user submit a new word");
    int i = 0;
    Container.getInstance().setPlayerScore(0);
    Container.getInstance().setWord("I");
    i += OnePlayer.computeScore(Container.getInstance().getWord().length());
    Container.getInstance().setWord("hi");
    i += OnePlayer.computeScore(Container.getInstance().getWord().length());
    Container.getInstance().setWord("see");
    i += OnePlayer.computeScore(Container.getInstance().getWord().length());
    Container.getInstance().setWord("tree");
    i += OnePlayer.computeScore(Container.getInstance().getWord().length());
    Container.getInstance().setWord("north");
    i += OnePlayer.computeScore(Container.getInstance().getWord().length());
    Container.getInstance().setWord("banana");
    i += OnePlayer.computeScore(Container.getInstance().getWord().length());
    Container.getInstance().setWord("messman");
    i += OnePlayer.computeScore(Container.getInstance().getWord().length());
    Container.getInstance().setWord("abashing");
    i += OnePlayer.computeScore(Container.getInstance().getWord().length());

    assertEquals("The total score should be 23!", 23, Container.getInstance().getPlayerScore());
  }
Пример #5
0
 @BeforeClass
 public static void readyFramework() {
   System.out.println("TEST STARTS...");
   Container.getInstance().setPlayerScore(0);
 }