From dfbf979a9d1788476ae39e8c50b28ec52829a0bb Mon Sep 17 00:00:00 2001 From: Hiroshi Miura Date: Sat, 18 May 2024 11:27:01 +0900 Subject: [PATCH] feat: improve test cases --- .../org/dts/spell/tests/InterlinguaTest.java | 59 +++++++++++++++++++ .../tests/OpenOfficeSpellDictonaryTest.java | 30 +++++++++- 2 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 src/test/java/org/dts/spell/tests/InterlinguaTest.java diff --git a/src/test/java/org/dts/spell/tests/InterlinguaTest.java b/src/test/java/org/dts/spell/tests/InterlinguaTest.java new file mode 100644 index 0000000..2b75343 --- /dev/null +++ b/src/test/java/org/dts/spell/tests/InterlinguaTest.java @@ -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(); + + } + } +} diff --git a/src/test/java/org/dts/spell/tests/OpenOfficeSpellDictonaryTest.java b/src/test/java/org/dts/spell/tests/OpenOfficeSpellDictonaryTest.java index 62d4466..2d89527 100644 --- a/src/test/java/org/dts/spell/tests/OpenOfficeSpellDictonaryTest.java +++ b/src/test/java/org/dts/spell/tests/OpenOfficeSpellDictonaryTest.java @@ -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 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)) { @@ -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); @@ -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)) {