Skip to content

Commit

Permalink
feat: improve test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
miurahr committed May 18, 2024
1 parent 7985005 commit dfbf979
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 1 deletion.
59 changes: 59 additions & 0 deletions src/test/java/org/dts/spell/tests/InterlinguaTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package org.dts.spell.tests;


import org.dts.spell.SpellChecker;
import org.dts.spell.dictionary.OpenOfficeSpellDictionary;
import org.dts.spell.dictionary.SpellDictionary;
import org.junit.Test;

import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;

import static org.assertj.core.api.Assertions.assertThat;

public class InterlinguaTest extends TestBase {

private static final String DICTIONARY_ZIP = "ia.zip";

@Override
protected String getDictionary() {
return DICTIONARY_ZIP;
}

@Test
public void testInterlinguaZipLoad() throws IOException {
try (InputStream is = getClass().getResourceAsStream(DICTIONARY_ZIP)) {
SpellDictionary dict = new OpenOfficeSpellDictionary(is, personalDictionary, false);
SpellChecker checker = new SpellChecker(dict);
checker.setCaseSensitive(false);
String word = "Die";
assertThat(checker.isCorrect(word)).isTrue();
}
}

@Test
public void testInterlinguaFileLoad() throws IOException {
try (InputStream affFile = Files.newInputStream(tempDir.resolve("ia/index.aff"));
InputStream dicFile = Files.newInputStream(tempDir.resolve("ia/index.dic"))) {
SpellDictionary dict = new OpenOfficeSpellDictionary(affFile, dicFile, personalDictionary, false);
SpellChecker checker = new SpellChecker(dict);
checker.setCaseSensitive(false);
String word = "Die";
assertThat(checker.isCorrect(word)).isTrue();
}
}

@Test
public void testInterlinguaFileLoadBackground() throws IOException {
try (InputStream affFile = Files.newInputStream(tempDir.resolve("ia/index.aff"));
InputStream dicFile = Files.newInputStream(tempDir.resolve("ia/index.dic"))) {
SpellDictionary dict = new OpenOfficeSpellDictionary(affFile, dicFile, personalDictionary, true);
SpellChecker checker = new SpellChecker(dict);
checker.setCaseSensitive(false);
String word = "Die";
assertThat(checker.isCorrect(word)).isTrue();

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,23 @@ public void testCheckOpenOfficeDictionary() throws IOException {
}
}

@Test
public void testCheckOpenOfficeDictionaryBackground() throws IOException {
try (InputStream affFile = Files.newInputStream(tempDir.resolve("en_US.aff"));
InputStream dicFile = Files.newInputStream(tempDir.resolve("en_US.dic"))) {
SpellDictionary dict = new OpenOfficeSpellDictionary(affFile, dicFile, personalDictionary, true);
SpellChecker checker = new SpellChecker(dict);
checker.setCaseSensitive(false);

String word = "Hello world!";
assertThat(checker.isCorrect(word)).isTrue();
List<String> suggestions = dict.getSuggestions(word);
assertThat(suggestions.size()).isEqualTo(10);
assertThat(suggestions).contains("Worldliness's", "Worldlinesses", "Worldliness", "Worldliest", "Afterworlds",
"Afterworld's", "Afterworld", "Worldwide", "Dreamworlds");
}
}

@Test
public void testOpenOfficeDictionaryZipDictionaryStream() throws IOException {
try (InputStream is = getClass().getResourceAsStream(DICTIONARY_ZIP)) {
Expand Down Expand Up @@ -80,7 +97,7 @@ public void testOpenOfficeDictionaryZipFile() throws IOException {
}

@Test
public void testOpenOfficeDictionaryStreamBackground() throws IOException {
public void testOpenOfficeDictionaryZipStreamBackground() throws IOException {
try (InputStream is = getClass().getResourceAsStream(DICTIONARY_ZIP)) {
SpellDictionary dict = new OpenOfficeSpellDictionary(is, personalDictionary, true);
SpellChecker checker = new SpellChecker(dict);
Expand All @@ -90,6 +107,17 @@ public void testOpenOfficeDictionaryStreamBackground() throws IOException {
}
}

@Test
public void testOpenOfficeDictionaryCompoundRule() throws IOException {
try (InputStream is = getClass().getResourceAsStream(DICTIONARY_ZIP)) {
SpellDictionary dict = new OpenOfficeSpellDictionary(is, personalDictionary, true);
SpellChecker checker = new SpellChecker(dict);
checker.setCaseSensitive(false);
String word = "1st, 2nd, 121st";
assertThat(checker.isCorrect(word)).isFalse();
}
}

@Test
public void testOpenOfficeDictionaryCharSequence() throws IOException {
try (InputStream is = getClass().getResourceAsStream(DICTIONARY_ZIP)) {
Expand Down

0 comments on commit dfbf979

Please sign in to comment.