63 lines
1.5 KiB
Java
63 lines
1.5 KiB
Java
package function.builtin.cons;
|
|
|
|
import static testutil.TestUtilities.*;
|
|
|
|
import org.junit.Test;
|
|
|
|
import function.ArgumentValidator.*;
|
|
import sexpression.*;
|
|
import testutil.SymbolAndFunctionCleaner;
|
|
|
|
public class CONSTest extends SymbolAndFunctionCleaner {
|
|
|
|
@Test
|
|
public void consWithNilValues() {
|
|
String input = "(cons () nil)";
|
|
|
|
assertSExpressionsMatch(parseString("(())"), evaluateString(input));
|
|
}
|
|
|
|
@Test
|
|
public void consWithTwoSymbols() {
|
|
String input = "(cons 'a 'b)";
|
|
|
|
assertSExpressionsMatch(new Cons(new Symbol("A"), new Symbol("B")), evaluateString(input));
|
|
}
|
|
|
|
@Test
|
|
public void consWithListAsRest() {
|
|
String input = "(cons 1 '(2 3))";
|
|
|
|
assertSExpressionsMatch(parseString("(1 2 3)"), evaluateString(input));
|
|
}
|
|
|
|
@Test
|
|
public void consWithTwoLists() {
|
|
String input = "(cons '(1 2) '(3 4))";
|
|
|
|
assertSExpressionsMatch(parseString("((1 2) 3 4)"), evaluateString(input));
|
|
}
|
|
|
|
@Test
|
|
public void consWithList() {
|
|
String input = "(cons nil '(2 3))";
|
|
|
|
assertSExpressionsMatch(parseString("(nil 2 3)"), evaluateString(input));
|
|
}
|
|
|
|
@Test(expected = TooManyArgumentsException.class)
|
|
public void consWithTooManyArguments() {
|
|
String input = "(cons 1 2 3)";
|
|
|
|
evaluateString(input);
|
|
}
|
|
|
|
@Test(expected = TooFewArgumentsException.class)
|
|
public void consWithTooFewArguments() {
|
|
String input = "(cons 1)";
|
|
|
|
evaluateString(input);
|
|
}
|
|
|
|
}
|