package net.volune.functions;

import org.junit.Test;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.function.BinaryOperator;
import java.util.function.Function;
import java.util.function.Supplier;

import static org.junit.Assert.assertEquals;

public class FunctionsTest extends TestBase {
    @Test
    public void testBiFunctionBind1() throws Exception {
        Spy spy = new Spy();
        map(Functions.bind1(spy::transform, 0));
        spy.checkConsumed(0, 1, 0, 2, 0, 3);
    }

    @Test
    public void testBiFunctionBind2() throws Exception {
        Spy spy = new Spy();
        map(Functions.bind2(spy::transform, 0));
        spy.checkConsumed(1, 0, 2, 0, 3, 0);
    }

    @Test
    public void testBiFunctionBind12() throws Exception {
        Spy spy = new Spy();
        generate(Functions.bind12(spy::transform, 8, 9));
        spy.checkConsumed(8, 9, 8, 9, 8, 9);
    }

    @Test
    public void testBinaryOperatorBind12() throws Exception {
        Spy spy = new Spy();
        BinaryOperator<String> operator = spy::operate;
        generate(Functions.bind12(operator, "a", "b"));
        spy.checkConsumed("a", "b", "a", "b", "a", "b");
    }

    private void map(Function<Integer, String> function) {
        List<String> results = new ArrayList<>();
        for (int i = 1; i <= LENGTH; ++i) {
            results.add(function.apply(i));
        }
        assertEquals(Arrays.asList("-1", "-2", "-3"), results);
    }

    private void generate(Supplier<String> supplier) {
        List<String> results = new ArrayList<>();
        for (int i = 1; i <= LENGTH; ++i) {
            results.add(supplier.get());
        }
        assertEquals(Arrays.asList("-1", "-2", "-3"), results);
    }
}
@@ -80,33 +80,8 @@
 st;%0A
-import java.util.Arrays;%0A
 impo
@@ -214,16 +214,55 @@
 plier;%0A%0A
+import static java.util.Arrays.asList;%0A
 import s
@@ -1443,39 +1443,32 @@
    assertEquals(
-Arrays.
 asList(%22-1%22, %22-2
@@ -1715,23 +1715,16 @@
 tEquals(
-Arrays.
 asList(%22

clean code