package com.insightfullogic.java8.answers.chapter2;

import org.junit.Test;

import javax.swing.*;

import java.text.DateFormat;
import java.util.Date;
import java.util.function.Function;
import java.util.function.Predicate;

//see : https://github.com/junit-team/junit4/wiki/Assertions
import static org.junit.Assert.assertEquals;

public class LambdaExercises {

	@Test
	public void chapter2_1b() {
		Function<Double, Double> negate = (x) -> -1 * x;
		Function<Double, Double> square = (x) -> x * x;
		Function<Double, Double> percent = (x) -> 100 * x;
		assertEquals(negate.apply(1.0), -1.0, 1e-10);
		assertEquals(square.apply(11.0), 121, 1e-10);
		assertEquals(percent.apply(1.0), 100, 1e-10);
	}

	@Test
	public void chapter2_1c() {
		Function<Integer, Integer> one = x -> x + 1;
		// 2 isn't
		Function<Integer, Boolean> three = x -> x == 1;
		assertEquals(one.apply(1), Integer.valueOf(1)); //עƥ,assertEquals
		assertEquals(three.apply(1), true);
	}
}

@@ -922,15 +922,16 @@
 eOf(
-1
+2
 )); //
+ 
 %D7%A2%C6%A5,a
@@ -985,12 +985,279 @@
 e);%0D%0A%09%7D%0D
+%0A%0D%0A%09@Test%0D%0A%09public void chapter2_2b() %7B%0D%0A%09%09ThreadLocal%3CDateFormat%3E threadSafeFormatter = ThreadLocal.withInitial(() -%3E DateFormat.getDateInstance());%0D%0A%09%09DateFormat formatter = threadSafeFormatter.get();%0D%0A%09%09assertEquals(%221970-1-1%22, formatter.format(new Date(0)));%0D%0A%09%7D%0D
 %0A%7D%0D%0A

add answer 2b in chapter2