package joshua.decoder.segment_file;

import org.testng.annotations.Test;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.AfterMethod;
import static org.testng.Assert.*;

public class SentenceTest {
  @BeforeMethod
  public void beforeMethod() {
  }

  @AfterMethod
  public void afterMethod() {
  }

  @Test
  public void testConstructor() {
    Sentence sent = new Sentence("", 0);
    assertNotNull(sent);
  }

  @Test
  public void testEmpty() {
    assertTrue(new Sentence("", 0).isEmpty());
  }

  @Test
  public void testNotEmpty() {
    assertFalse(new Sentence("hello , world", 0).isEmpty());
  }

  /**
   * Return a string consisting of repeatedToken concatenated MAX_SENTENCE_TOKENS times, joined by a
   * space.
   *
   * @param repeatedToken
   * @param repeatedTimes
   * @return
   */
  private String concatTokens(String repeatedToken, int repeatedTimes) {
    String result = "";
    for (int i = 0; i < repeatedTimes - 1; i++) {
      result += repeatedToken + " ";
    }
    result += repeatedToken;
    return result;
  }

  @Test
  public void testTooManyTokens() {
    // Concatenate MAX_SENTENCE_TOKENS, each longer than the average length, joined by a space.
    String input = concatTokens("1234567", Sentence.MAX_SENTENCE_TOKENS);
    assertTrue(new Sentence(input, 0).isEmpty());
  }

  @Test
  public void testAlmostButNotTooManyTokens() {
    // Concatenate MAX_SENTENCE_TOKENS, each shorter than the average length, joined by a space.
    String input = concatTokens("12345", Sentence.MAX_SENTENCE_TOKENS);
    assertFalse(new Sentence(input, 0).isEmpty());
  }

  @Test
  public void testClearlyNotTooManyTokens() {
    // Concatenate MAX_SENTENCE_TOKENS, each shorter than the average length, joined by a space.
    String input = "token";
    assertFalse(new Sentence(input, 0).isEmpty());
  }

}

@@ -1282,336 +1282,868 @@
 S);%0A
-    assertTrue(new Sentence(input, 0).isEmpty());%0A  %7D%0A%0A  @Test%0A  public void testAlmostButNotTooManyTokens() %7B%0A    // Concatenate MAX_SENTENCE_TOKENS, each shorter than the average length, joined by a space.%0A    String input = concatTokens(%2212345%22, Sentence.MAX_SENTENCE_TOKENS);%0A    assertFalse(new Sentence(input, 0).isEmpty()
+%0A    Sentence sentence;%0A    // Source only%0A    sentence = new Sentence(input, 0);%0A    assertTrue(sentence.isEmpty());%0A    assertNull(sentence.target);%0A%0A    // Source + target%0A    sentence = new Sentence(input + %22 %7C%7C%7C target side%22, 0);%0A    assertTrue(sentence.isEmpty());%0A    assertEquals(sentence.target, %22%22);%0A  %7D%0A%0A  @Test%0A  public void testAlmostButNotTooManyTokens() %7B%0A    // Concatenate MAX_SENTENCE_TOKENS, each shorter than the average length, joined by a space.%0A    String input = concatTokens(%2212345%22, Sentence.MAX_SENTENCE_TOKENS);%0A%0A    Sentence sentence;%0A    // Source only%0A    sentence = new Sentence(input, 0);%0A    assertFalse(sentence.isEmpty());%0A    assertNull(sentence.target);%0A%0A    // Source + target%0A    sentence = new Sentence(input + %22 %7C%7C%7C target side%22, 0);%0A    assertFalse(sentence.isEmpty());%0A    assertEquals(sentence.target, %22target side%22
 );%0A 

test target side result of too long input