transcendental-lisp/test/function/builtin/cons/LENGTHTester.java

48 lines
1.1 KiB
Java
Raw Normal View History

package function.builtin.cons;
import static testutil.TestUtilities.*;
import org.junit.Test;
import function.ArgumentValidator.*;
public class LENGTHTester {
@Test
public void testLengthOfNil() {
String input = "(length '())";
assertSExpressionsMatch(evaluateString(input), parseString("0"));
}
@Test
public void testLengthOfListOfOneElement() {
String input = "(length '(1))";
assertSExpressionsMatch(evaluateString(input), parseString("1"));
}
@Test
public void testLengthOfListOfManyElements() {
String input = "(length '(1 2 3 4 5))";
assertSExpressionsMatch(evaluateString(input), parseString("5"));
}
@Test(expected = BadArgumentTypeException.class)
public void testLengthWithNonList() {
evaluateString("(length 'x)");
}
@Test(expected = TooManyArgumentsException.class)
public void testLengthWithTooManyArguments() {
evaluateString("(length '(1 2) '(1 2))");
}
@Test(expected = TooFewArgumentsException.class)
public void testLengthWithTooFewArguments() {
evaluateString("(length)");
}
}