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)";
|
|
|
|
|
2017-01-27 10:51:25 -05:00
|
|
|
assertSExpressionsMatch(parseString("()"), evaluateString(input));
|
2016-12-23 10:53:11 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testCarWithList() {
|
|
|
|
String input = "(car '(1 2 3))";
|
|
|
|
|
2017-01-27 10:51:25 -05:00
|
|
|
assertSExpressionsMatch(parseString("1"), evaluateString(input));
|
2016-12-23 10:53:11 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testNestedCarWithList() {
|
|
|
|
String input = "(car (car '((1 2) 3)))";
|
|
|
|
|
2017-01-27 10:51:25 -05:00
|
|
|
assertSExpressionsMatch(parseString("1"), evaluateString(input));
|
2016-12-23 10:53:11 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@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
|
|
|
}
|
|
|
|
|
|
|
|
}
|