package com.insightfullogic.java8.test.chapter3;

import static org.junit.Assert.*;
import static java.util.Arrays.asList;

import java.util.Collections;
import java.util.List;
import java.util.function.Function;

import org.junit.Test;

import com.insightfullogic.java8.answers.chapter3.*;

public class MapUsingReduceTest {

	@Test
	public void emptyList() {
		assertMapped(Function.<Object> identity(), Collections.<Object> emptyList(), Collections.<Object> emptyList());
	}

	@Test
	public void identityMapsToItself() {
		assertMapped((Integer x) -> x, asList(1, 2, 3), asList(1, 2, 3));
	}

	@Test
	public void incrementingNumbers() {
		assertMapped((Integer x) -> x + 2, asList(1, 2, 3), asList(3, 4, 5));
	}

	private <I, O> void assertMapped(Function<I, O> mapper, List<I> input, List<O> expectedOutput) {
		List<O> output = MapUsingReduce.map(input.stream(), mapper);
		assertEquals(expectedOutput, output);

		List<O> paralleOutPut = MapUsingReduce.map(input.parallelStream(), mapper);
		assertEquals(expectedOutput, paralleOutPut);
	}

}

@@ -739,16 +739,216 @@
 %0D%0A%09%7D%0D%0A%0D%0A
+%09@Test%0D%0A%09public void convertIntegerToBooleanTest() %7B%0D%0A%09%09assertMapped((Integer x) -%3E %7B%0D%0A%09%09%09return x %3E= 0 ? true : false;%0D%0A%09%09%7D, asList(1, -2, 3, 0, -11), asList(true, false, true, true, false));%0D%0A%09%7D%0D%0A%0D%0A
 %09private

add test method for MapUsingReduce in chapter3