83 lines
2.2 KiB
Java
83 lines
2.2 KiB
Java
package function.builtin;
|
|
|
|
import static testutil.TestUtilities.*;
|
|
|
|
import org.junit.Test;
|
|
|
|
import function.ArgumentValidator.*;
|
|
|
|
public class CONDTester {
|
|
|
|
@Test
|
|
public void testCondWithNoArguments() {
|
|
String input = "(cond)";
|
|
|
|
assertSExpressionsMatch(evaluateString(input), parseString("nil"));
|
|
}
|
|
|
|
@Test
|
|
public void testCondWithTrue() {
|
|
String input = "(cond (T))";
|
|
|
|
assertSExpressionsMatch(evaluateString(input), parseString("T"));
|
|
}
|
|
|
|
@Test
|
|
public void testCondWithSingleExpression() {
|
|
String input = "(cond (T \"true\"))";
|
|
|
|
assertSExpressionsMatch(evaluateString(input), parseString("\"true\""));
|
|
}
|
|
|
|
@Test
|
|
public void testCondWithMultipleExpressions() {
|
|
String input = "(cond ((= 1 2) 2) ((= 1 2) 2) ((= 1 1) 3))";
|
|
|
|
assertSExpressionsMatch(evaluateString(input), parseString("3"));
|
|
}
|
|
|
|
@Test
|
|
public void testCondWithMultipleConditionsMatching_ReturnFirstOne() {
|
|
String input = "(cond ((= 1 1) 2) ((= 1 1) 3))";
|
|
|
|
assertSExpressionsMatch(evaluateString(input), parseString("2"));
|
|
}
|
|
|
|
@Test
|
|
public void testCondWithMultipleConditionsMatching_OnlyEvaluatesFirstOne() {
|
|
String input = "(cond ((= 1 1) 2) ((= 1 1) x))";
|
|
|
|
assertSExpressionsMatch(evaluateString(input), parseString("2"));
|
|
}
|
|
|
|
@Test
|
|
public void testCondWithMultipleResultValues_OnlyReturnsLast() {
|
|
String input = "(cond ((= 1 1) 2 3 4))";
|
|
|
|
assertSExpressionsMatch(evaluateString(input), parseString("4"));
|
|
}
|
|
|
|
@Test
|
|
public void testCondWithNoConditionMatching_ReturnsNil() {
|
|
String input = "(cond ((= 1 2) T) ((= 1 3) T))";
|
|
|
|
assertSExpressionsMatch(evaluateString(input), parseString("nil"));
|
|
}
|
|
|
|
@Test(expected = BadArgumentTypeException.class)
|
|
public void testCondWithNilArgument_ThrowsException() {
|
|
evaluateString("(cond ())");
|
|
}
|
|
|
|
@Test(expected = BadArgumentTypeException.class)
|
|
public void testCondWithNonListArgument_ThrowsException() {
|
|
evaluateString("(cond o)");
|
|
}
|
|
|
|
@Test(expected = DottedArgumentListException.class)
|
|
public void testCondWithDottedArgumentList_ThrowsException() {
|
|
evaluateString("(apply 'cond (cons '(nil T) 'b))");
|
|
}
|
|
|
|
}
|