PageRenderTime 50ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

/test/spelling/corrector/SpellingCorrectorHelperTest.java

https://github.com/juliengrenier/java-spelling-corrector
Java | 71 lines | 63 code | 8 blank | 0 comment | 4 complexity | 9a3a35766d8ddaabadc94c2a7e6f4b40 MD5 | raw file
  1. package spelling.corrector;
  2. import java.util.ArrayList;
  3. import java.util.List;
  4. import junit.framework.TestCase;
  5. public abstract class SpellingCorrectorHelperTest extends
  6. TestCase {
  7. public final void testGetDeletions() {
  8. try {
  9. List<String> expected = new ArrayList<String>();
  10. expected.add("ase");
  11. expected.add("cse");
  12. expected.add("cae");
  13. expected.add("cas");
  14. List<String> result = getHelper().getDeletion("case");
  15. assertEquals(expected, result);
  16. } catch (Exception e) {
  17. fail(e.getMessage());
  18. }
  19. }
  20. public final void testGetTranspositions() {
  21. try {
  22. List<String> expected = new ArrayList<String>();
  23. expected.add("acse");
  24. expected.add("csae");
  25. expected.add("caes");
  26. List<String> result = getHelper().getTransposition("case");
  27. assertEquals(expected, result);
  28. } catch (Exception e) {
  29. fail(e.getMessage());
  30. }
  31. }
  32. public final void testGetAlterations() {
  33. try {
  34. List<String> expected = new ArrayList<String>();
  35. String word = "case";
  36. for (int i = 0; i < word.length(); i++) {
  37. for (char c = 'a'; c <= 'z'; c++) {
  38. expected.add(word.replace(word.charAt(i), c));
  39. }
  40. }
  41. List<String> result = getHelper().getAlterations("case");
  42. assertEquals(expected, result);
  43. } catch (Exception e) {
  44. fail(e.getMessage());
  45. }
  46. }
  47. public final void testGetInsertions() {
  48. try {
  49. List<String> expected = new ArrayList<String>();
  50. String word = "case";
  51. for (int i = 0; i < word.length() + 1; i++) {
  52. for (char c = 'a'; c <= 'z'; c++) {
  53. expected.add(word.substring(0, i) + c + word.substring(i));
  54. }
  55. }
  56. List<String> result = getHelper().getInsertions("case");
  57. assertEquals(expected, result);
  58. } catch (Exception e) {
  59. fail(e.getMessage());
  60. }
  61. }
  62. abstract protected SpellingCorrectorHelper getHelper();
  63. }