package targetast;

import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import java.lang.reflect.Method;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class LessThanTest {
    static Class<?> classToTest;
    static Object instance;

    @BeforeAll
    public static void beforeClass() throws Exception {
        var classFiles = TestCodegen.generateClassFiles(TestCodegen.createClassLoader(), "LessThan.jav");
        classToTest = classFiles.get("LessThan");
        instance = classToTest.getDeclaredConstructor().newInstance();
    }

    @Test
    public void testLessThanInt() throws Exception {
        Method lessThan = classToTest.getDeclaredMethod("lessThan", Integer.class,Integer.class);
        Boolean result = (Boolean) lessThan.invoke(instance, 5, 7);
        assertTrue(result);
    }

    @Test
    public void testLessThanInt2() throws Exception {
        Method lessThan = classToTest.getDeclaredMethod("lessThan", Integer.class, Integer.class);
        Boolean result = (Boolean) lessThan.invoke(instance, 7, 5);
        assertFalse(result);
    }

    @Test
    public void testLessThanInt3() throws Exception {
        Method lessThan = classToTest.getDeclaredMethod("lessThan", Integer.class, Integer.class);
        Boolean result = (Boolean) lessThan.invoke(instance, 5, 5);
        assertFalse(result);
    }

    @Test
    public void testLessThanLong() throws Exception {
        Method lessThan = classToTest.getDeclaredMethod("lessThan", Long.class,Long.class);
        Boolean result = (Boolean) lessThan.invoke(instance, 5L, 7L);
        assertTrue(result);
    }

    @Test
    public void testLessThanLong2() throws Exception {
        Method lessThan = classToTest.getDeclaredMethod("lessThan", Long.class, Long.class);
        Boolean result = (Boolean) lessThan.invoke(instance, 7L, 5L);
        assertFalse(result);
    }

    @Test
    public void testLessThanLong3() throws Exception {
        Method lessThan = classToTest.getDeclaredMethod("lessThan", Long.class, Long.class);
        Boolean result = (Boolean) lessThan.invoke(instance, 5L, 5L);
        assertFalse(result);
    }

    @Test
    public void testLessThanFloat() throws Exception {
        Method lessThan = classToTest.getDeclaredMethod("lessThan", Float.class, Float.class);
        Boolean result = (Boolean) lessThan.invoke(instance, 7F, 5F);
        assertFalse(result);
    }

    @Test
    public void testLessThanDouble() throws Exception {
        Method lessThan = classToTest.getDeclaredMethod("lessThan", Double.class, Double.class);
        Boolean result = (Boolean) lessThan.invoke(instance, 7.0, 5.0);
        assertFalse(result);
    }

    @Test
    public void testLessThanLongInt() throws Exception {
        Method lessThan = classToTest.getDeclaredMethod("lessThan", Long.class, Integer.class);
        Boolean result = (Boolean) lessThan.invoke(instance, 7L, 5);
        assertFalse(result);
    }

    @Test
    public void testLessThanFloatInt() throws Exception {
        Method lessThan = classToTest.getDeclaredMethod("lessThan", Float.class, Integer.class);
        Boolean result = (Boolean) lessThan.invoke(instance, 7F, 5);
        assertFalse(result);
    }

    @Test
    public void testLessThanDoubleInt() throws Exception {
        Method lessThan = classToTest.getDeclaredMethod("lessThan", Double.class, Integer.class);
        Boolean result = (Boolean) lessThan.invoke(instance, 7.0, 5);
        assertFalse(result);
    }

    @Test
    public void testLessThanFloatLong() throws Exception {
        Method lessThan = classToTest.getDeclaredMethod("lessThan", Float.class, Long.class);
        Boolean result = (Boolean) lessThan.invoke(instance, 7F, 5L);
        assertFalse(result);
    }

    @Test
    public void testLessThanDoubleLong() throws Exception {
        Method lessThan = classToTest.getDeclaredMethod("lessThan", Double.class, Long.class);
        Boolean result = (Boolean) lessThan.invoke(instance, 7.0, 5L);
        assertFalse(result);
    }

    @Test
    public void testLessThanDoubleFloat() throws Exception {
        Method lessThan = classToTest.getDeclaredMethod("lessThan", Double.class, Float.class);
        Boolean result = (Boolean) lessThan.invoke(instance, 7.0, 5F);
        assertFalse(result);
    }
}
