2017-01-15 14:23:46 -05:00
|
|
|
package function.builtin.cons;
|
|
|
|
|
|
|
|
import static testutil.TestUtilities.*;
|
|
|
|
|
|
|
|
import org.junit.Test;
|
|
|
|
|
|
|
|
import function.ArgumentValidator.*;
|
2017-07-19 15:23:15 -04:00
|
|
|
import testutil.SymbolAndFunctionCleaner;
|
2017-01-15 14:23:46 -05:00
|
|
|
|
2017-07-19 15:23:15 -04:00
|
|
|
public class LENGTHTest extends SymbolAndFunctionCleaner {
|
2017-01-15 14:23:46 -05:00
|
|
|
|
|
|
|
@Test
|
2017-03-02 09:54:23 -05:00
|
|
|
public void lengthOfNil() {
|
2017-01-15 14:23:46 -05:00
|
|
|
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
|
2017-03-02 09:54:23 -05:00
|
|
|
public void lengthOfListOfOneElement() {
|
2017-01-15 14:23:46 -05:00
|
|
|
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
|
2017-03-02 09:54:23 -05:00
|
|
|
public void lengthOfListOfManyElements() {
|
2017-01-15 14:23:46 -05:00
|
|
|
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)
|
2017-03-02 09:54:23 -05:00
|
|
|
public void lengthWithNonList() {
|
2017-01-15 14:23:46 -05:00
|
|
|
evaluateString("(length 'x)");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test(expected = TooManyArgumentsException.class)
|
2017-03-02 09:54:23 -05:00
|
|
|
public void lengthWithTooManyArguments() {
|
2017-01-15 14:23:46 -05:00
|
|
|
evaluateString("(length '(1 2) '(1 2))");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test(expected = TooFewArgumentsException.class)
|
2017-03-02 09:54:23 -05:00
|
|
|
public void lengthWithTooFewArguments() {
|
2017-01-15 14:23:46 -05:00
|
|
|
evaluateString("(length)");
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|