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 LessEqualTest {
    static Class<?> classToTest;
    static Object instance;

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

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

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

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

    public void testFloats() throws Exception {
        Method lessEqual = classToTest.getDeclaredMethod("lessEqual", Float.class, Float.class);
        Boolean result = (Boolean) lessEqual.invoke(instance, 5F,7F);
        assertTrue(result);
    }

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

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

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

    @Test
    public void testDoubleInt() throws Exception {
        Method lessEqual = classToTest.getDeclaredMethod("lessEqual", Double.class, Integer.class);
        Boolean result = (Boolean) lessEqual.invoke(instance, 5.0,7);
        assertTrue(result);
    }

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

    @Test
    public void testDoubleLong() throws Exception {
        Method lessEqual = classToTest.getDeclaredMethod("lessEqual", Double.class, Long.class);
        Boolean result = (Boolean) lessEqual.invoke(instance, 5.0,7L);
        assertTrue(result);
    }

    @Test
    public void testEqDoubleFloat() throws Exception {
        Method lessEqual = classToTest.getDeclaredMethod("lessEqual", Double.class, Float.class);
        Boolean result = (Boolean) lessEqual.invoke(instance, 7.0,7F);
        assertTrue(result);
    }

    @Test
    public void testDoubleFloat() throws Exception {
        Method lessEqual = classToTest.getDeclaredMethod("lessEqual", Double.class, Float.class);
        Boolean result = (Boolean) lessEqual.invoke(instance, 5.0,7F);
        assertTrue(result);
    }

    @Test
    public void testDoubleFloat3() throws Exception {
        Method lessEqual = classToTest.getDeclaredMethod("lessEqual", Double.class, Float.class);
        Boolean result = (Boolean) lessEqual.invoke(instance, 9.0,7F);
        assertFalse(result);
    }
}
