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

EtlTest.java 3.6KB

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