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
|
2017-03-02 09:54:23 -05:00
|
|
|
public void consWithNilValues() {
|
2016-12-25 13:29:06 -05:00
|
|
|
String input = "(cons () nil)";
|
|
|
|
|
2017-01-27 10:51:25 -05:00
|
|
|
assertSExpressionsMatch(parseString("(())"), evaluateString(input));
|
2016-12-25 13:29:06 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2017-03-02 09:54:23 -05:00
|
|
|
public void consWithTwoSymbols() {
|
2016-12-25 13:29:06 -05:00
|
|
|
String input = "(cons 'a 'b)";
|
|
|
|
|
2017-01-27 10:51:25 -05:00
|
|
|
assertSExpressionsMatch(new Cons(new Symbol("A"), new Symbol("B")), evaluateString(input));
|
2016-12-25 13:29:06 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2017-03-02 09:54:23 -05:00
|
|
|
public void consWithListAsRest() {
|
2016-12-25 13:29:06 -05:00
|
|
|
String input = "(cons 1 '(2 3))";
|
|
|
|
|
2017-01-27 10:51:25 -05:00
|
|
|
assertSExpressionsMatch(parseString("(1 2 3)"), evaluateString(input));
|
2016-12-25 13:29:06 -05:00
|
|
|
}
|
2017-02-06 13:43:27 -05:00
|
|
|
|
2016-12-25 13:29:06 -05:00
|
|
|
@Test
|
2017-03-02 09:54:23 -05:00
|
|
|
public void consWithTwoLists() {
|
2016-12-25 13:29:06 -05:00
|
|
|
String input = "(cons '(1 2) '(3 4))";
|
|
|
|
|
2017-01-27 10:51:25 -05:00
|
|
|
assertSExpressionsMatch(parseString("((1 2) 3 4)"), evaluateString(input));
|
2016-12-25 13:29:06 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2017-03-02 09:54:23 -05:00
|
|
|
public void consWithList() {
|
2016-12-25 13:29:06 -05:00
|
|
|
String input = "(cons nil '(2 3))";
|
|
|
|
|
2017-01-27 10:51:25 -05:00
|
|
|
assertSExpressionsMatch(parseString("(nil 2 3)"), evaluateString(input));
|
2016-12-25 13:29:06 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test(expected = TooManyArgumentsException.class)
|
2017-03-02 09:54:23 -05:00
|
|
|
public void consWithTooManyArguments() {
|
2016-12-25 13:29:06 -05:00
|
|
|
String input = "(cons 1 2 3)";
|
|
|
|
|
|
|
|
evaluateString(input);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test(expected = TooFewArgumentsException.class)
|
2017-03-02 09:54:23 -05:00
|
|
|
public void consWithTooFewArguments() {
|
2016-12-25 13:29:06 -05:00
|
|
|
String input = "(cons 1)";
|
|
|
|
|
|
|
|
evaluateString(input);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|