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

EtlTest.java 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. import org.junit.Test;
  2. import java.util.*;
  3. import static org.junit.Assert.assertEquals;
  4. public class EtlTest {
  5. private final Etl etl = new Etl();
  6. @Test
  7. public void testTransformOneValue() {
  8. Map<Integer, List<String>> old = new HashMap<Integer, List<String>>() {
  9. {
  10. put(1, Arrays.asList("A"));
  11. }
  12. };
  13. old = Collections.unmodifiableMap(old);
  14. Map<String, Integer> expected = new HashMap<String, Integer>() {
  15. {
  16. put("a", 1);
  17. }
  18. };
  19. expected = Collections.unmodifiableMap(expected);
  20. assertEquals(expected, etl.transform(old));
  21. }
  22. @Test
  23. public void testTransformMoreValues() {
  24. Map<Integer, List<String>> old = new HashMap<Integer, List<String>>() {
  25. {
  26. put(1, Arrays.asList("A", "E", "I", "O", "U"));
  27. }
  28. };
  29. old = Collections.unmodifiableMap(old);
  30. Map<String, Integer> expected = new HashMap<String, Integer>() {
  31. {
  32. put("a", 1);
  33. put("e", 1);
  34. put("i", 1);
  35. put("o", 1);
  36. put("u", 1);
  37. }
  38. };
  39. expected = Collections.unmodifiableMap(expected);
  40. assertEquals(expected, etl.transform(old));
  41. }
  42. @Test
  43. public void testMoreKeys() {
  44. Map<Integer, List<String>> old = new HashMap<Integer, List<String>>() {
  45. {
  46. put(1, Arrays.asList("A", "E"));
  47. put(2, Arrays.asList("D", "G"));
  48. }
  49. };
  50. old = Collections.unmodifiableMap(old);
  51. Map<String, Integer> expected = new HashMap<String, Integer>() {
  52. {
  53. put("a", 1);
  54. put("e", 1);
  55. put("d", 2);
  56. put("g", 2);
  57. }
  58. };
  59. expected = Collections.unmodifiableMap(expected);
  60. assertEquals(expected, etl.transform(old));
  61. }
  62. @Test
  63. public void testFullDataset() {
  64. Map<Integer, List<String>> old = new HashMap<Integer, List<String>>() {
  65. {
  66. put(1, Arrays.asList("A", "E", "I", "O", "U", "L", "N", "R", "S", "T"));
  67. put(2, Arrays.asList("D", "G"));
  68. put(3, Arrays.asList("B", "C", "M", "P"));
  69. put(4, Arrays.asList("F", "H", "V", "W", "Y"));
  70. put(5, Arrays.asList("K"));
  71. put(8, Arrays.asList("J", "X"));
  72. put(10, Arrays.asList("Q", "Z"));
  73. }
  74. };
  75. old = Collections.unmodifiableMap(old);
  76. Map<String, Integer> expected = new HashMap<String, Integer>() {
  77. {
  78. put("a", 1);
  79. put("b", 3);
  80. put("c", 3);
  81. put("d", 2);
  82. put("e", 1);
  83. put("f", 4);
  84. put("g", 2);
  85. put("h", 4);
  86. put("i", 1);
  87. put("j", 8);
  88. put("k", 5);
  89. put("l", 1);
  90. put("m", 3);
  91. put("n", 1);
  92. put("o", 1);
  93. put("p", 3);
  94. put("q", 10);
  95. put("r", 1);
  96. put("s", 1);
  97. put("t", 1);
  98. put("u", 1);
  99. put("v", 4);
  100. put("w", 4);
  101. put("x", 8);
  102. put("y", 4);
  103. put("z", 10);
  104. }
  105. };
  106. expected = Collections.unmodifiableMap(expected);
  107. assertEquals(expected, etl.transform(old));
  108. }
  109. }