package function.builtin;

import static testutil.TestUtilities.*;

import org.junit.*;

import function.ArgumentValidator.TooFewArgumentsException;
import table.FunctionTable;

public class FUNCALLTester {

    @Before
    public void setUp() {
        FunctionTable.reset();
    }

    @After
    public void tearDown() {
        FunctionTable.reset();
    }

    @Test
    public void testFuncallWithNumbers() {
        String input = "(funcall '+ 1 2 3)";

        assertSExpressionsMatch(parseString("6"), evaluateString(input));
    }

    @Test
    public void testFuncallWithUserDefinedFunction() {
        String defineUserFunction = "(defun x (n m) (+ n m))";
        String input = "(funcall 'x 2 30)";

        evaluateString(defineUserFunction);
        assertSExpressionsMatch(parseString("32"), evaluateString(input));
    }

    @Test(expected = TooFewArgumentsException.class)
    public void testFuncallWithTooFewArguments() {
        evaluateString("(funcall)");
    }

}
