2017-01-14 18:01:14 -05:00
|
|
|
package function.builtin.cons;
|
2016-12-23 10:53:11 -05:00
|
|
|
|
|
|
|
import static testutil.TestUtilities.*;
|
|
|
|
|
|
|
|
import org.junit.Test;
|
|
|
|
|
|
|
|
import function.ArgumentValidator.*;
|
|
|
|
|
|
|
|
public class CARTester {
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testCarWithNil() {
|
|
|
|
String input = "(car nil)";
|
|
|
|
|
|
|
|
assertSExpressionsMatch(evaluateString(input), parseString("()"));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testCarWithList() {
|
|
|
|
String input = "(car '(1 2 3))";
|
|
|
|
|
|
|
|
assertSExpressionsMatch(evaluateString(input), parseString("1"));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testNestedCarWithList() {
|
|
|
|
String input = "(car (car '((1 2) 3)))";
|
|
|
|
|
|
|
|
assertSExpressionsMatch(evaluateString(input), parseString("1"));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test(expected = BadArgumentTypeException.class)
|
|
|
|
public void testCarWithNonList() {
|
|
|
|
evaluateString("(car 'x)");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test(expected = TooManyArgumentsException.class)
|
|
|
|
public void testCarWithTooManyArguments() {
|
2016-12-25 13:29:06 -05:00
|
|
|
evaluateString("(car '(1 2) '(1 2) \"oh\")");
|
2016-12-23 10:53:11 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test(expected = TooFewArgumentsException.class)
|
|
|
|
public void testCarWithTooFewArguments() {
|
2016-12-25 13:29:06 -05:00
|
|
|
evaluateString("(car)");
|
2016-12-23 10:53:11 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|