2017-02-24 16:00:05 -05:00
|
|
|
package function.builtin.cons;
|
|
|
|
|
|
|
|
import static testutil.TestUtilities.*;
|
|
|
|
|
|
|
|
import org.junit.Test;
|
|
|
|
|
|
|
|
import function.ArgumentValidator.*;
|
2017-07-19 15:23:15 -04:00
|
|
|
import testutil.SymbolAndFunctionCleaner;
|
2017-02-24 16:00:05 -05:00
|
|
|
|
2017-07-19 15:23:15 -04:00
|
|
|
public class FIRSTTest extends SymbolAndFunctionCleaner {
|
2017-02-24 16:00:05 -05:00
|
|
|
|
|
|
|
@Test
|
|
|
|
public void firstOfNil() {
|
|
|
|
String input = "(first nil)";
|
|
|
|
|
|
|
|
assertSExpressionsMatch(parseString("()"), evaluateString(input));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void firstOfList() {
|
|
|
|
String input = "(first '(1 2 3))";
|
|
|
|
|
|
|
|
assertSExpressionsMatch(parseString("1"), evaluateString(input));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void carOfList() {
|
|
|
|
String input = "(car '(1 2 3))";
|
|
|
|
|
|
|
|
assertSExpressionsMatch(parseString("1"), evaluateString(input));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void nestedFirstOfList() {
|
|
|
|
String input = "(first (first '((1 2) 3)))";
|
|
|
|
|
|
|
|
assertSExpressionsMatch(parseString("1"), evaluateString(input));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test(expected = BadArgumentTypeException.class)
|
|
|
|
public void firstOfSymbol() {
|
|
|
|
evaluateString("(first 'x)");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test(expected = TooManyArgumentsException.class)
|
|
|
|
public void firstWithTooManyArguments() {
|
|
|
|
evaluateString("(first '(1 2) '(1 2) \"oh\")");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test(expected = TooFewArgumentsException.class)
|
|
|
|
public void firstWithTooFewArguments() {
|
|
|
|
evaluateString("(first)");
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|