lots of exercises in java... from https://github.com/exercism/java

WordCountTest.java 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. import org.junit.Test;
  2. import org.junit.Ignore;
  3. import java.lang.Integer;
  4. import java.lang.String;
  5. import java.util.HashMap;
  6. import java.util.Map;
  7. import static org.junit.Assert.*;
  8. public class WordCountTest {
  9. private final WordCount wordCount = new WordCount();
  10. @Test
  11. public void countOneWord() {
  12. Map<String, Integer> actualWordCount = new HashMap<String, Integer>();
  13. final Map<String, Integer> expectedWordCount = new HashMap<String, Integer>();
  14. expectedWordCount.put("word", 1);
  15. actualWordCount = wordCount.phrase("word");
  16. assertEquals(
  17. expectedWordCount, actualWordCount
  18. );
  19. }
  20. @Ignore
  21. @Test
  22. public void countOneOfEach() {
  23. Map<String, Integer> actualWordCount = new HashMap<String, Integer>();
  24. final Map<String, Integer> expectedWordCount = new HashMap<String, Integer>();
  25. expectedWordCount.put("one", 1);
  26. expectedWordCount.put("of", 1);
  27. expectedWordCount.put("each", 1);
  28. actualWordCount = wordCount.phrase("one of each");
  29. assertEquals(
  30. expectedWordCount, actualWordCount
  31. );
  32. }
  33. @Ignore
  34. @Test
  35. public void countMultipleOccurences() {
  36. Map<String, Integer> actualWordCount = new HashMap<String, Integer>();
  37. final Map<String, Integer> expectedWordCount = new HashMap<String, Integer>();
  38. expectedWordCount.put("one", 1);
  39. expectedWordCount.put("fish", 4);
  40. expectedWordCount.put("two", 1);
  41. expectedWordCount.put("red", 1);
  42. expectedWordCount.put("blue", 1);
  43. actualWordCount = wordCount.phrase("one fish two fish red fish blue fish");
  44. assertEquals(
  45. expectedWordCount, actualWordCount
  46. );
  47. }
  48. @Ignore
  49. @Test
  50. public void ignorePunctuation() {
  51. Map<String, Integer> actualWordCount = new HashMap<String, Integer>();
  52. final Map<String, Integer> expectedWordCount = new HashMap<String, Integer>();
  53. expectedWordCount.put("car", 1);
  54. expectedWordCount.put("carpet", 1);
  55. expectedWordCount.put("as", 1);
  56. expectedWordCount.put("java", 1);
  57. expectedWordCount.put("javascript", 1);
  58. actualWordCount = wordCount.phrase("car : carpet as java : javascript!!&@$%^&");
  59. assertEquals(
  60. expectedWordCount, actualWordCount
  61. );
  62. }
  63. @Ignore
  64. @Test
  65. public void includeNumbers() {
  66. Map<String, Integer> actualWordCount = new HashMap<String, Integer>();
  67. final Map<String, Integer> expectedWordCount = new HashMap<String, Integer>();
  68. expectedWordCount.put("testing", 2);
  69. expectedWordCount.put("1", 1);
  70. expectedWordCount.put("2", 1);
  71. actualWordCount = wordCount.phrase("testing, 1, 2 testing");
  72. assertEquals(
  73. expectedWordCount, actualWordCount
  74. );
  75. }
  76. @Ignore
  77. @Test
  78. public void normalizeCase() {
  79. Map<String, Integer> actualWordCount = new HashMap<String, Integer>();
  80. final Map<String, Integer> expectedWordCount = new HashMap<String, Integer>();
  81. expectedWordCount.put("go", 3);
  82. actualWordCount = wordCount.phrase("go Go GO");
  83. assertEquals(
  84. expectedWordCount, actualWordCount
  85. );
  86. }
  87. }