PageRenderTime 67ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/java/src/test/java/SpellingCorrectorTest.java

https://github.com/kbaribeau/Spelling-Corrector
Java | 57 lines | 41 code | 16 blank | 0 comment | 0 complexity | ac4dfe8da953a19d0dda86fbf94b1ead MD5 | raw file
  1. import java.util.HashSet;
  2. import java.util.Set;
  3. import org.junit.Test;
  4. import static org.junit.Assert.*;
  5. public class SpellingCorrectorTest {
  6. SpellingCorrector spellingCorrector = new SpellingCorrector();
  7. @Test
  8. public void shouldReturnDeletions() throws Exception {
  9. Set<String> words = new HashSet<String>();
  10. words.add("he");
  11. words.add("te");
  12. words.add("th");
  13. assertEquals(words, spellingCorrector.applySingleCharacterDeletions("the"));
  14. }
  15. @Test
  16. public void shouldReturnTranspositions() throws Exception {
  17. Set<String> words = new HashSet<String>();
  18. words.add("etst");
  19. words.add("tset");
  20. words.add("tets");
  21. assertEquals(words, spellingCorrector.applyTranspositions("test"));
  22. }
  23. @Test
  24. public void shouldReturnAlterations() throws Exception {
  25. assertEquals(101, spellingCorrector.applyOneLetterTypeos("test").size());
  26. }
  27. @Test
  28. public void shouldReturnInserts() throws Exception {
  29. assertEquals(126, spellingCorrector.applyInserts("test").size());
  30. }
  31. @Test
  32. public void shouldReturnTheCorrectWord() throws Exception {
  33. assertEquals("access", spellingCorrector.correct("acess"));
  34. assertEquals("access", spellingCorrector.correct("access"));
  35. assertEquals("causing", spellingCorrector.correct("acesing"));
  36. assertEquals("heard", spellingCorrector.correct("heare"));
  37. assertEquals("carry", spellingCorrector.correct("carr"));
  38. assertEquals("forbidden", spellingCorrector.correct("forbiden"));
  39. assertEquals("house", spellingCorrector.correct("hoyse"));
  40. }
  41. }