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

EtlTest.java 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import com.google.common.collect.ImmutableMap;
  2. import org.junit.Test;
  3. import java.util.Arrays;
  4. import java.util.List;
  5. import java.util.Map;
  6. import static org.assertj.core.api.Assertions.assertThat;
  7. public class EtlTest {
  8. private final Etl etl = new Etl();
  9. @Test
  10. public void testTransformOneValue() {
  11. Map<Integer, List<String>> old = ImmutableMap.of(1, Arrays.asList("A"));
  12. Map<String, Integer> expected = ImmutableMap.of("a", 1);
  13. assertThat(etl.transform(old)).isEqualTo(expected);
  14. }
  15. @Test
  16. public void testTransformMoreValues() {
  17. Map<Integer, List<String>> old = ImmutableMap.of(
  18. 1, Arrays.asList("A", "E", "I", "O", "U")
  19. );
  20. Map<String, Integer> expected = ImmutableMap.of(
  21. "a", 1,
  22. "e", 1,
  23. "i", 1,
  24. "o", 1,
  25. "u", 1
  26. );
  27. assertThat(etl.transform(old)).isEqualTo(expected);
  28. }
  29. @Test
  30. public void testMoreKeys() {
  31. Map<Integer, List<String>> old = ImmutableMap.of(
  32. 1, Arrays.asList("A", "E"),
  33. 2, Arrays.asList("D", "G")
  34. );
  35. Map<String, Integer> expected = ImmutableMap.of(
  36. "a", 1,
  37. "e", 1,
  38. "d", 2,
  39. "g", 2
  40. );
  41. assertThat(etl.transform(old)).isEqualTo(expected);
  42. }
  43. @Test
  44. public void testFullDataset() {
  45. Map<Integer, List<String>> old = ImmutableMap.<Integer, List<String>>builder().
  46. put(1, Arrays.asList("A", "E", "I", "O", "U", "L", "N", "R", "S", "T")).
  47. put(2, Arrays.asList("D", "G")).
  48. put(3, Arrays.asList("B", "C", "M", "P")).
  49. put(4, Arrays.asList("F", "H", "V", "W", "Y")).
  50. put(5, Arrays.asList("K")).
  51. put(8, Arrays.asList("J", "X")).
  52. put(10, Arrays.asList("Q", "Z")).
  53. build();
  54. Map<String, Integer> expected = ImmutableMap.<String, Integer>builder().
  55. put("a", 1).put("b", 3).put("c", 3).put("d", 2).put("e", 1).
  56. put("f", 4).put("g", 2).put("h", 4).put("i", 1).put("j", 8).
  57. put("k", 5).put("l", 1).put("m", 3).put("n", 1).put("o", 1).
  58. put("p", 3).put("q", 10).put("r", 1).put("s", 1).put("t", 1).
  59. put("u", 1).put("v", 4).put("w", 4).put("x", 8).put("y", 4).
  60. put("z", 10).build();
  61. assertThat(etl.transform(old)).isEqualTo(expected);
  62. }
  63. }