/*
 * @author Ranides Atterwim <ranides@gmail.com>
 * @copyright Ranides Atterwim
 * @license WTFPL
 * @url http://ranides.net/projects/assira
 */
package net.ranides.assira.functional;

import java.util.function.Function;
import java.util.function.IntFunction;
import java.util.function.IntUnaryOperator;
import org.junit.Test;
import static org.junit.Assert.*;

/**
 *
 * @author Ranides Atterwim <ranides@gmail.com>
 */
public class IntCoFunctionTest {
    
    @Test
    public void testIdentity() {
        IntCoFunction a = IntCoFunction.identity();
        CoFunction<Integer, Integer> b = IntCoFunction.identity();
        
        assertEquals(8, a.invert(8));
        assertEquals(Integer.valueOf(8), b.invert(8));

    }
    
    @Test
    public void testInverted() {
        IntCoFunction a = v -> 10 * v;

        IntUnaryOperator b1 = IntCoFunction.inverted(a);
        IntFunction<Integer> b2 = IntCoFunction.inverted(a)::applyAsInt;
        
        IntCoFunction c1 = IntCoFunction.inverted(b1);
        IntCoFunction c2 = IntCoFunction.inverted((IntUnaryOperator)b2::apply);
        
        assertEquals(170, a.invert(17));
        assertEquals(170, b1.applyAsInt(17));
        assertEquals(Integer.valueOf(170), b2.apply(17));
        assertEquals(170, c1.invert(17));
        assertEquals(170, c2.invert(17));
    }
    
}
