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

WordCountTest.java 3.1KB

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