@Test public void testExercise7filter() { System.out.println("----------- testExercise7 filter ----------------"); ComposableList<Integer> slr = ComposableListExercises.of(1, 2, 3).filter(i -> i <= 2); slr.forEach(System.out::println); assertEquals(Arrays.asList(1, 2), slr); }
@Test public void testExercise4map() { System.out.println("----------- testExercise4 map ----------------"); ComposableList<Integer> slr = ComposableListExercises.of(1, 2, 3).map(i -> i + 1); slr.forEach(System.out::println); assertEquals(Arrays.asList(2, 3, 4), slr); }
@Test public void testExercise15reduce() { System.out.println("----------- testExercise15 reduce ----------------"); ComposableList<Integer> slr = ComposableListExercises.of(1, 2, 3).reduce(1, (s, i) -> s + i); slr.forEach(System.out::println); assertEquals(Arrays.asList(7), slr); }
@Test public void testExercise10() { System.out.println("----------- testExercise10 ----------------"); ComposableList<Integer> slr = ComposableListExercises.of(1, 2, 3) .concatMap((t) -> ComposableListExercises.of(t + 1, t + 2, t + 3)); slr.forEach(System.out::println); assertEquals(Arrays.asList(2, 3, 4, 3, 4, 5, 4, 5, 6), slr); }
private void assertMatch(ComposableList<? extends Object> e, ComposableList<? extends Object> s) { if (e.size() != s.size()) { throw new RuntimeException("Count Doesn't Match"); } for (int i = 0; i < e.size(); i++) { if (!e.get(i).equals(s.get(i))) { throw new RuntimeException("Item does not match at index: " + i); } } }
@Test public void testExercise21zip() { System.out.println("----------- testExercise21 zip ----------------"); ComposableList<Integer> slr = ComposableListExercises.zip( ComposableListExercises.of(1, 2, 3), ComposableListExercises.of(4, 5, 6), (l, r) -> l + r); slr.forEach(System.out::println); assertEquals(Arrays.asList(5, 7, 9), slr); }