package function.builtin.math;

import static testutil.TestUtilities.assertSExpressionsMatch;
import static testutil.TestUtilities.evaluateString;

import org.junit.Test;

import function.ArgumentValidator.BadArgumentTypeException;
import sexpression.LispNumber;
import testutil.SymbolAndFunctionCleaner;

public class PLUSTest extends SymbolAndFunctionCleaner {

    @Test
    public void plusWithNoArguments() {
        String input = "(+)";

        assertSExpressionsMatch(new LispNumber("0"), evaluateString(input));
    }

    @Test
    public void plusWithOneNumber() {
        String input = "(+ 27)";

        assertSExpressionsMatch(new LispNumber("27"), evaluateString(input));
    }

    @Test
    public void plusWithTwoNumbers() {
        String input = "(+ 5 3)";

        assertSExpressionsMatch(new LispNumber("8"), evaluateString(input));
    }

    @Test
    public void plusWithManyNumbers_PositiveResult() {
        String input = "(+ 200 100 10 5)";

        assertSExpressionsMatch(new LispNumber("315"), evaluateString(input));
    }

    @Test
    public void plusWithManyNumbers_NegativeResult() {
        String input = "(+ 100 (- 200) 20 5)";

        assertSExpressionsMatch(new LispNumber("-75"), evaluateString(input));
    }

    @Test(expected = BadArgumentTypeException.class)
    public void plusWithNonNumber() {
        evaluateString("(+ 'a 'b)");
    }

}
