2017-01-15 14:23:46 -05:00
|
|
|
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 '())";
|
|
|
|
|
2017-01-27 10:51:25 -05:00
|
|
|
assertSExpressionsMatch(parseString("0"), evaluateString(input));
|
2017-01-15 14:23:46 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testLengthOfListOfOneElement() {
|
|
|
|
String input = "(length '(1))";
|
|
|
|
|
2017-01-27 10:51:25 -05:00
|
|
|
assertSExpressionsMatch(parseString("1"), evaluateString(input));
|
2017-01-15 14:23:46 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testLengthOfListOfManyElements() {
|
|
|
|
String input = "(length '(1 2 3 4 5))";
|
|
|
|
|
2017-01-27 10:51:25 -05:00
|
|
|
assertSExpressionsMatch(parseString("5"), evaluateString(input));
|
2017-01-15 14:23:46 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@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)");
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|