2017-02-21 12:35:47 -05:00
|
|
|
package function.builtin.special;
|
|
|
|
|
|
|
|
import static testutil.TestUtilities.evaluateString;
|
2017-11-12 09:42:25 -05:00
|
|
|
import static testutil.TypeAssertions.assertNil;
|
|
|
|
import static testutil.TypeAssertions.assertT;
|
2017-02-21 12:35:47 -05:00
|
|
|
|
2017-07-19 15:23:15 -04:00
|
|
|
import org.junit.Test;
|
2017-02-21 12:35:47 -05:00
|
|
|
|
2017-11-12 09:42:25 -05:00
|
|
|
import function.ArgumentValidator.TooFewArgumentsException;
|
|
|
|
import function.ArgumentValidator.TooManyArgumentsException;
|
2017-02-21 12:35:47 -05:00
|
|
|
import function.builtin.EVAL.UndefinedSymbolException;
|
2017-07-19 15:23:15 -04:00
|
|
|
import testutil.SymbolAndFunctionCleaner;
|
2017-02-21 12:35:47 -05:00
|
|
|
|
2017-07-19 15:23:15 -04:00
|
|
|
public class IFTest extends SymbolAndFunctionCleaner {
|
2017-02-21 12:35:47 -05:00
|
|
|
|
|
|
|
@Test
|
|
|
|
public void ifWithOneExpression_ReturnsExpression() {
|
|
|
|
String input = "(if t t)";
|
|
|
|
|
|
|
|
assertT(evaluateString(input));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void ifWithOneExpression_ReturnsNil() {
|
|
|
|
String input = "(if nil t)";
|
|
|
|
|
|
|
|
assertNil(evaluateString(input));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void ifWithTwoExpressions_ReturnsFirst() {
|
|
|
|
String input = "(if t t nil)";
|
|
|
|
|
|
|
|
assertT(evaluateString(input));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void ifWithTwoExpressions_ReturnsSecond() {
|
|
|
|
String input = "(if nil nil t)";
|
|
|
|
|
|
|
|
assertT(evaluateString(input));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void ifWithNumericConditional() {
|
|
|
|
String input = "(if 23 t nil)";
|
|
|
|
|
|
|
|
assertT(evaluateString(input));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test(expected = UndefinedSymbolException.class)
|
|
|
|
public void ifWithNilCondition_DoesNotEvaluateThenForm() {
|
2017-03-07 16:41:26 -05:00
|
|
|
String input = "(if nil (setq x 22))";
|
2017-02-21 12:35:47 -05:00
|
|
|
|
|
|
|
assertNil(evaluateString(input));
|
|
|
|
evaluateString("x");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test(expected = UndefinedSymbolException.class)
|
|
|
|
public void ifWithTrueCondition_DoesNotEvaluateElseForm() {
|
2017-03-07 16:41:26 -05:00
|
|
|
String input = "(if t nil (setq x 22))";
|
2017-02-21 12:35:47 -05:00
|
|
|
|
|
|
|
assertNil(evaluateString(input));
|
|
|
|
evaluateString("x");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test(expected = TooFewArgumentsException.class)
|
|
|
|
public void ifWithTooFewArguments() {
|
|
|
|
evaluateString("(if t)");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test(expected = TooManyArgumentsException.class)
|
|
|
|
public void ifWithTooManyArguments() {
|
|
|
|
evaluateString("(if t t t t)");
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|