2017-01-15 14:23:46 -05:00
|
|
|
package function.builtin.cons;
|
|
|
|
|
2017-11-12 09:42:25 -05:00
|
|
|
import static testutil.TestUtilities.assertSExpressionsMatch;
|
|
|
|
import static testutil.TestUtilities.evaluateString;
|
|
|
|
import static testutil.TestUtilities.parseString;
|
2017-01-15 14:23:46 -05:00
|
|
|
|
|
|
|
import org.junit.Test;
|
|
|
|
|
2017-11-12 09:42:25 -05:00
|
|
|
import function.ArgumentValidator.BadArgumentTypeException;
|
2018-03-15 18:30:47 -04:00
|
|
|
import function.ArgumentValidator.DottedArgumentListException;
|
2017-11-12 09:42:25 -05:00
|
|
|
import function.ArgumentValidator.TooFewArgumentsException;
|
|
|
|
import function.ArgumentValidator.TooManyArgumentsException;
|
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)");
|
|
|
|
}
|
|
|
|
|
2018-03-15 18:30:47 -04:00
|
|
|
@Test(expected = DottedArgumentListException.class)
|
|
|
|
public void lengthWithDottedList() {
|
|
|
|
evaluateString("(length (cons 1 2))");
|
|
|
|
}
|
|
|
|
|
2017-01-15 14:23:46 -05:00
|
|
|
}
|