2017-01-14 18:01:14 -05:00
|
|
|
package function.builtin.cons;
|
2016-12-25 13:29:06 -05:00
|
|
|
|
|
|
|
import static testutil.TestUtilities.*;
|
|
|
|
|
|
|
|
import org.junit.Test;
|
|
|
|
|
|
|
|
import function.ArgumentValidator.*;
|
|
|
|
import sexpression.*;
|
|
|
|
|
|
|
|
public class CONSTester {
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testConsWithNilValues() {
|
|
|
|
String input = "(cons () nil)";
|
|
|
|
|
|
|
|
assertSExpressionsMatch(evaluateString(input), parseString("(())"));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testConsWithTwoSymbols() {
|
|
|
|
String input = "(cons 'a 'b)";
|
|
|
|
|
|
|
|
assertSExpressionsMatch(evaluateString(input), new Cons(new Symbol("A"), new Symbol("B")));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testConsWithListAsCdr() {
|
|
|
|
String input = "(cons 1 '(2 3))";
|
|
|
|
|
|
|
|
assertSExpressionsMatch(evaluateString(input), parseString("(1 2 3)"));
|
|
|
|
}
|
|
|
|
@Test
|
|
|
|
public void testConsWithTwoLists() {
|
|
|
|
String input = "(cons '(1 2) '(3 4))";
|
|
|
|
|
|
|
|
assertSExpressionsMatch(evaluateString(input), parseString("((1 2) 3 4)"));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testConsWithList() {
|
|
|
|
String input = "(cons nil '(2 3))";
|
|
|
|
|
|
|
|
assertSExpressionsMatch(evaluateString(input), parseString("(nil 2 3)"));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test(expected = TooManyArgumentsException.class)
|
|
|
|
public void testConsWithTooManyArguments() {
|
|
|
|
String input = "(cons 1 2 3)";
|
|
|
|
|
|
|
|
evaluateString(input);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test(expected = TooFewArgumentsException.class)
|
|
|
|
public void testConsWithTooFewArguments() {
|
|
|
|
String input = "(cons 1)";
|
|
|
|
|
|
|
|
evaluateString(input);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|