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

53 lines
1.4 KiB
Java

package function.builtin.cons;
import static testutil.TestUtilities.assertSExpressionsMatch;
import static testutil.TestUtilities.evaluateString;
import static testutil.TestUtilities.parseString;
import org.junit.Test;
import function.ArgumentValidator.BadArgumentTypeException;
import function.ArgumentValidator.TooFewArgumentsException;
import function.ArgumentValidator.TooManyArgumentsException;
import testutil.SymbolAndFunctionCleaner;
public class LENGTHTest extends SymbolAndFunctionCleaner {
@Test
public void lengthOfNil() {
String input = "(length '())";
assertSExpressionsMatch(parseString("0"), evaluateString(input));
}
@Test
public void lengthOfListOfOneElement() {
String input = "(length '(1))";
assertSExpressionsMatch(parseString("1"), evaluateString(input));
}
@Test
public void lengthOfListOfManyElements() {
String input = "(length '(1 2 3 4 5))";
assertSExpressionsMatch(parseString("5"), evaluateString(input));
}
@Test(expected = BadArgumentTypeException.class)
public void lengthWithNonList() {
evaluateString("(length 'x)");
}
@Test(expected = TooManyArgumentsException.class)
public void lengthWithTooManyArguments() {
evaluateString("(length '(1 2) '(1 2))");
}
@Test(expected = TooFewArgumentsException.class)
public void lengthWithTooFewArguments() {
evaluateString("(length)");
}
}