Convert cons tests to kotlin
This commit is contained in:
parent
84f164397b
commit
698df036ff
|
@ -1,78 +0,0 @@
|
|||
package function.builtin.cons;
|
||||
|
||||
import function.ArgumentValidator.BadArgumentTypeException;
|
||||
import function.ArgumentValidator.DottedArgumentListException;
|
||||
import function.ArgumentValidator.TooFewArgumentsException;
|
||||
import function.ArgumentValidator.TooManyArgumentsException;
|
||||
import org.junit.Test;
|
||||
import testutil.SymbolAndFunctionCleaner;
|
||||
|
||||
import static testutil.TestUtilities.assertSExpressionsMatch;
|
||||
import static testutil.TestUtilities.evaluateString;
|
||||
import static testutil.TestUtilities.parseString;
|
||||
|
||||
public class AppendTest extends SymbolAndFunctionCleaner {
|
||||
|
||||
@Test
|
||||
public void appendNil() {
|
||||
String input = "(append () ())";
|
||||
|
||||
assertSExpressionsMatch(parseString("nil"), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void appendNilToList() {
|
||||
String input = "(append () '(1 2 3))";
|
||||
|
||||
assertSExpressionsMatch(parseString("(1 2 3)"), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void appendListToNil() {
|
||||
String input = "(append '(1 2 3) ())";
|
||||
|
||||
assertSExpressionsMatch(parseString("(1 2 3)"), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void appendTwoLists() {
|
||||
String input = "(append '(1 2 3) '(4 5 6))";
|
||||
|
||||
assertSExpressionsMatch(parseString("(1 2 3 4 5 6)"), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void appendMakesCopyOfFirstList() {
|
||||
evaluateString("(setq x '(1 2 3))");
|
||||
evaluateString("(setq y '(4 5 6))");
|
||||
evaluateString("(append x y)");
|
||||
|
||||
assertSExpressionsMatch(parseString("(1 2 3)"), evaluateString("x"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void appendAllowsDottedSecondList() {
|
||||
String input = "(append '() (cons 3 4))";
|
||||
assertSExpressionsMatch(evaluateString("(cons 3 4)"), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test(expected = DottedArgumentListException.class)
|
||||
public void appendWithDottedFirstList() {
|
||||
evaluateString("(append (cons 1 2) '(3 4))");
|
||||
}
|
||||
|
||||
@Test(expected = TooManyArgumentsException.class)
|
||||
public void appendWithTooManyArguments() {
|
||||
evaluateString("(append () () ())");
|
||||
}
|
||||
|
||||
@Test(expected = TooFewArgumentsException.class)
|
||||
public void appendWithTooFewArguments() {
|
||||
evaluateString("(append ())");
|
||||
}
|
||||
|
||||
@Test(expected = BadArgumentTypeException.class)
|
||||
public void appendWithBadArgumentType() {
|
||||
evaluateString("(append 1 '(2))");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,88 @@
|
|||
package function.builtin.cons
|
||||
|
||||
import function.ArgumentValidator.BadArgumentTypeException
|
||||
import function.ArgumentValidator.DottedArgumentListException
|
||||
import function.ArgumentValidator.TooFewArgumentsException
|
||||
import function.ArgumentValidator.TooManyArgumentsException
|
||||
import org.junit.jupiter.api.Assertions.assertThrows
|
||||
import org.junit.jupiter.api.Test
|
||||
import testutil.LispTestInstance
|
||||
import testutil.SymbolAndFunctionCleaner
|
||||
import testutil.TestUtilities.assertSExpressionsMatch
|
||||
import testutil.TestUtilities.evaluateString
|
||||
import testutil.TestUtilities.parseString
|
||||
|
||||
@LispTestInstance
|
||||
class AppendTest : SymbolAndFunctionCleaner() {
|
||||
|
||||
@Test
|
||||
fun appendNil() {
|
||||
val input = "(append () ())"
|
||||
|
||||
assertSExpressionsMatch(parseString("nil"), evaluateString(input))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun appendNilToList() {
|
||||
val input = "(append () '(1 2 3))"
|
||||
|
||||
assertSExpressionsMatch(parseString("(1 2 3)"), evaluateString(input))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun appendListToNil() {
|
||||
val input = "(append '(1 2 3) ())"
|
||||
|
||||
assertSExpressionsMatch(parseString("(1 2 3)"), evaluateString(input))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun appendTwoLists() {
|
||||
val input = "(append '(1 2 3) '(4 5 6))"
|
||||
|
||||
assertSExpressionsMatch(parseString("(1 2 3 4 5 6)"), evaluateString(input))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun appendMakesCopyOfFirstList() {
|
||||
evaluateString("(setq x '(1 2 3))")
|
||||
evaluateString("(setq y '(4 5 6))")
|
||||
evaluateString("(append x y)")
|
||||
|
||||
assertSExpressionsMatch(parseString("(1 2 3)"), evaluateString("x"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun appendAllowsDottedSecondList() {
|
||||
val input = "(append '() (cons 3 4))"
|
||||
assertSExpressionsMatch(evaluateString("(cons 3 4)"), evaluateString(input))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun appendWithDottedFirstList() {
|
||||
assertThrows(DottedArgumentListException::class.java) {
|
||||
evaluateString("(append (cons 1 2) '(3 4))")
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun appendWithTooManyArguments() {
|
||||
assertThrows(TooManyArgumentsException::class.java) {
|
||||
evaluateString("(append () () ())")
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun appendWithTooFewArguments() {
|
||||
assertThrows(TooFewArgumentsException::class.java) {
|
||||
evaluateString("(append ())")
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun appendWithBadArgumentType() {
|
||||
assertThrows(BadArgumentTypeException::class.java) {
|
||||
evaluateString("(append 1 '(2))")
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,60 +0,0 @@
|
|||
package function.builtin.cons;
|
||||
|
||||
import function.ArgumentValidator.TooFewArgumentsException;
|
||||
import function.ArgumentValidator.TooManyArgumentsException;
|
||||
import org.junit.Test;
|
||||
import sexpression.Cons;
|
||||
import sexpression.Symbol;
|
||||
import testutil.SymbolAndFunctionCleaner;
|
||||
|
||||
import static testutil.TestUtilities.assertSExpressionsMatch;
|
||||
import static testutil.TestUtilities.evaluateString;
|
||||
import static testutil.TestUtilities.parseString;
|
||||
|
||||
public class ConstructTest extends SymbolAndFunctionCleaner {
|
||||
|
||||
@Test
|
||||
public void consWithNilValues() {
|
||||
String input = "(cons () nil)";
|
||||
|
||||
assertSExpressionsMatch(parseString("(())"), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void consWithTwoSymbols() {
|
||||
String input = "(cons 'a 'b)";
|
||||
|
||||
assertSExpressionsMatch(new Cons(new Symbol("A"), new Symbol("B")), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void consWithListAsRest() {
|
||||
String input = "(cons 1 '(2 3))";
|
||||
|
||||
assertSExpressionsMatch(parseString("(1 2 3)"), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void consWithTwoLists() {
|
||||
String input = "(cons '(1 2) '(3 4))";
|
||||
|
||||
assertSExpressionsMatch(parseString("((1 2) 3 4)"), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void consWithList() {
|
||||
String input = "(cons nil '(2 3))";
|
||||
|
||||
assertSExpressionsMatch(parseString("(nil 2 3)"), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test(expected = TooManyArgumentsException.class)
|
||||
public void consWithTooManyArguments() {
|
||||
evaluateString("(cons 1 2 3)");
|
||||
}
|
||||
|
||||
@Test(expected = TooFewArgumentsException.class)
|
||||
public void consWithTooFewArguments() {
|
||||
evaluateString("(cons 1)");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
package function.builtin.cons
|
||||
|
||||
import function.ArgumentValidator.TooFewArgumentsException
|
||||
import function.ArgumentValidator.TooManyArgumentsException
|
||||
import org.junit.jupiter.api.Assertions.assertThrows
|
||||
import org.junit.jupiter.api.Test
|
||||
import sexpression.Cons
|
||||
import sexpression.Symbol
|
||||
import testutil.LispTestInstance
|
||||
import testutil.SymbolAndFunctionCleaner
|
||||
import testutil.TestUtilities.assertSExpressionsMatch
|
||||
import testutil.TestUtilities.evaluateString
|
||||
import testutil.TestUtilities.parseString
|
||||
|
||||
@LispTestInstance
|
||||
class ConstructTest : SymbolAndFunctionCleaner() {
|
||||
|
||||
@Test
|
||||
fun consWithNilValues() {
|
||||
val input = "(cons () nil)"
|
||||
|
||||
assertSExpressionsMatch(parseString("(())"), evaluateString(input))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun consWithTwoSymbols() {
|
||||
val input = "(cons 'a 'b)"
|
||||
|
||||
assertSExpressionsMatch(Cons(Symbol("A"), Symbol("B")), evaluateString(input))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun consWithListAsRest() {
|
||||
val input = "(cons 1 '(2 3))"
|
||||
|
||||
assertSExpressionsMatch(parseString("(1 2 3)"), evaluateString(input))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun consWithTwoLists() {
|
||||
val input = "(cons '(1 2) '(3 4))"
|
||||
|
||||
assertSExpressionsMatch(parseString("((1 2) 3 4)"), evaluateString(input))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun consWithList() {
|
||||
val input = "(cons nil '(2 3))"
|
||||
|
||||
assertSExpressionsMatch(parseString("(nil 2 3)"), evaluateString(input))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun consWithTooManyArguments() {
|
||||
assertThrows(TooManyArgumentsException::class.java) {
|
||||
evaluateString("(cons 1 2 3)")
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun consWithTooFewArguments() {
|
||||
assertThrows(TooFewArgumentsException::class.java) {
|
||||
evaluateString("(cons 1)")
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,57 +0,0 @@
|
|||
package function.builtin.cons;
|
||||
|
||||
import function.ArgumentValidator.BadArgumentTypeException;
|
||||
import function.ArgumentValidator.TooFewArgumentsException;
|
||||
import function.ArgumentValidator.TooManyArgumentsException;
|
||||
import org.junit.Test;
|
||||
import testutil.SymbolAndFunctionCleaner;
|
||||
|
||||
import static testutil.TestUtilities.assertSExpressionsMatch;
|
||||
import static testutil.TestUtilities.evaluateString;
|
||||
import static testutil.TestUtilities.parseString;
|
||||
|
||||
public class FirstTest extends SymbolAndFunctionCleaner {
|
||||
|
||||
@Test
|
||||
public void firstOfNil() {
|
||||
String input = "(first nil)";
|
||||
|
||||
assertSExpressionsMatch(parseString("()"), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void firstOfList() {
|
||||
String input = "(first '(1 2 3))";
|
||||
|
||||
assertSExpressionsMatch(parseString("1"), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void carOfList() {
|
||||
String input = "(car '(1 2 3))";
|
||||
|
||||
assertSExpressionsMatch(parseString("1"), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nestedFirstOfList() {
|
||||
String input = "(first (first '((1 2) 3)))";
|
||||
|
||||
assertSExpressionsMatch(parseString("1"), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test(expected = BadArgumentTypeException.class)
|
||||
public void firstOfSymbol() {
|
||||
evaluateString("(first 'x)");
|
||||
}
|
||||
|
||||
@Test(expected = TooManyArgumentsException.class)
|
||||
public void firstWithTooManyArguments() {
|
||||
evaluateString("(first '(1 2) '(1 2) \"oh\")");
|
||||
}
|
||||
|
||||
@Test(expected = TooFewArgumentsException.class)
|
||||
public void firstWithTooFewArguments() {
|
||||
evaluateString("(first)");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
package function.builtin.cons
|
||||
|
||||
import function.ArgumentValidator.BadArgumentTypeException
|
||||
import function.ArgumentValidator.TooFewArgumentsException
|
||||
import function.ArgumentValidator.TooManyArgumentsException
|
||||
import org.junit.jupiter.api.Assertions.assertThrows
|
||||
import org.junit.jupiter.api.Test
|
||||
import testutil.LispTestInstance
|
||||
import testutil.SymbolAndFunctionCleaner
|
||||
import testutil.TestUtilities.assertSExpressionsMatch
|
||||
import testutil.TestUtilities.evaluateString
|
||||
import testutil.TestUtilities.parseString
|
||||
|
||||
@LispTestInstance
|
||||
class FirstTest : SymbolAndFunctionCleaner() {
|
||||
|
||||
@Test
|
||||
fun firstOfNil() {
|
||||
val input = "(first nil)"
|
||||
|
||||
assertSExpressionsMatch(parseString("()"), evaluateString(input))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun firstOfList() {
|
||||
val input = "(first '(1 2 3))"
|
||||
|
||||
assertSExpressionsMatch(parseString("1"), evaluateString(input))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun carOfList() {
|
||||
val input = "(car '(1 2 3))"
|
||||
|
||||
assertSExpressionsMatch(parseString("1"), evaluateString(input))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun nestedFirstOfList() {
|
||||
val input = "(first (first '((1 2) 3)))"
|
||||
|
||||
assertSExpressionsMatch(parseString("1"), evaluateString(input))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun firstOfSymbol() {
|
||||
assertThrows(BadArgumentTypeException::class.java) {
|
||||
evaluateString("(first 'x)")
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun firstWithTooManyArguments() {
|
||||
assertThrows(TooManyArgumentsException::class.java) {
|
||||
evaluateString("(first '(1 2) '(1 2) \"oh\")")
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun firstWithTooFewArguments() {
|
||||
assertThrows(TooFewArgumentsException::class.java) {
|
||||
evaluateString("(first)")
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,56 +0,0 @@
|
|||
package function.builtin.cons;
|
||||
|
||||
import function.ArgumentValidator.BadArgumentTypeException;
|
||||
import function.ArgumentValidator.DottedArgumentListException;
|
||||
import function.ArgumentValidator.TooFewArgumentsException;
|
||||
import function.ArgumentValidator.TooManyArgumentsException;
|
||||
import org.junit.Test;
|
||||
import testutil.SymbolAndFunctionCleaner;
|
||||
|
||||
import static testutil.TestUtilities.assertSExpressionsMatch;
|
||||
import static testutil.TestUtilities.evaluateString;
|
||||
import static testutil.TestUtilities.parseString;
|
||||
|
||||
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)");
|
||||
}
|
||||
|
||||
@Test(expected = DottedArgumentListException.class)
|
||||
public void lengthWithDottedList() {
|
||||
evaluateString("(length (cons 1 2))");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
package function.builtin.cons
|
||||
|
||||
import function.ArgumentValidator.BadArgumentTypeException
|
||||
import function.ArgumentValidator.DottedArgumentListException
|
||||
import function.ArgumentValidator.TooFewArgumentsException
|
||||
import function.ArgumentValidator.TooManyArgumentsException
|
||||
import org.junit.jupiter.api.Assertions.assertThrows
|
||||
import org.junit.jupiter.api.Test
|
||||
import testutil.LispTestInstance
|
||||
import testutil.SymbolAndFunctionCleaner
|
||||
import testutil.TestUtilities.assertSExpressionsMatch
|
||||
import testutil.TestUtilities.evaluateString
|
||||
import testutil.TestUtilities.parseString
|
||||
|
||||
@LispTestInstance
|
||||
class LengthTest : SymbolAndFunctionCleaner() {
|
||||
|
||||
@Test
|
||||
fun lengthOfNil() {
|
||||
val input = "(length '())"
|
||||
|
||||
assertSExpressionsMatch(parseString("0"), evaluateString(input))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun lengthOfListOfOneElement() {
|
||||
val input = "(length '(1))"
|
||||
|
||||
assertSExpressionsMatch(parseString("1"), evaluateString(input))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun lengthOfListOfManyElements() {
|
||||
val input = "(length '(1 2 3 4 5))"
|
||||
|
||||
assertSExpressionsMatch(parseString("5"), evaluateString(input))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun lengthWithNonList() {
|
||||
assertThrows(BadArgumentTypeException::class.java) {
|
||||
evaluateString("(length 'x)")
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun lengthWithTooManyArguments() {
|
||||
assertThrows(TooManyArgumentsException::class.java) {
|
||||
evaluateString("(length '(1 2) '(1 2))")
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun lengthWithTooFewArguments() {
|
||||
assertThrows(TooFewArgumentsException::class.java) {
|
||||
evaluateString("(length)")
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun lengthWithDottedList() {
|
||||
assertThrows(DottedArgumentListException::class.java) {
|
||||
evaluateString("(length (cons 1 2))")
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,59 +0,0 @@
|
|||
package function.builtin.cons;
|
||||
|
||||
import org.junit.Test;
|
||||
import testutil.SymbolAndFunctionCleaner;
|
||||
|
||||
import static function.builtin.cons.List.makeList;
|
||||
import static testutil.TestUtilities.assertSExpressionsMatch;
|
||||
import static testutil.TestUtilities.evaluateString;
|
||||
import static testutil.TestUtilities.parseString;
|
||||
|
||||
public class ListTest extends SymbolAndFunctionCleaner {
|
||||
|
||||
@Test
|
||||
public void listWithNoArguments() {
|
||||
String input = "(list)";
|
||||
|
||||
assertSExpressionsMatch(parseString("nil"), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void listWithOneArgument() {
|
||||
String input = "(list 1)";
|
||||
|
||||
assertSExpressionsMatch(parseString("(1)"), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void listWithTwoArguments() {
|
||||
String input = "(list 2 3)";
|
||||
|
||||
assertSExpressionsMatch(parseString("(2 3)"), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void listWithManyArguments() {
|
||||
String input = "(list 'm 'a 'n 'y 'a 'r 'g 's)";
|
||||
|
||||
assertSExpressionsMatch(parseString("(m a n y a r g s)"), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void listWithOneListArgument() {
|
||||
String input = "(list '(1))";
|
||||
|
||||
assertSExpressionsMatch(parseString("((1))"), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void listWithManyListArguments() {
|
||||
String input = "(list '(1) '(2 3) ())";
|
||||
|
||||
assertSExpressionsMatch(parseString("((1) (2 3) ())"), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void staticMakeList() {
|
||||
assertSExpressionsMatch(parseString("(22)"), makeList(parseString("22")));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
package function.builtin.cons
|
||||
|
||||
import function.builtin.cons.List.Companion.makeList
|
||||
import org.junit.jupiter.api.Test
|
||||
import testutil.LispTestInstance
|
||||
import testutil.SymbolAndFunctionCleaner
|
||||
import testutil.TestUtilities.assertSExpressionsMatch
|
||||
import testutil.TestUtilities.evaluateString
|
||||
import testutil.TestUtilities.parseString
|
||||
|
||||
@LispTestInstance
|
||||
class ListTest : SymbolAndFunctionCleaner() {
|
||||
|
||||
@Test
|
||||
fun listWithNoArguments() {
|
||||
val input = "(list)"
|
||||
|
||||
assertSExpressionsMatch(parseString("nil"), evaluateString(input))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun listWithOneArgument() {
|
||||
val input = "(list 1)"
|
||||
|
||||
assertSExpressionsMatch(parseString("(1)"), evaluateString(input))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun listWithTwoArguments() {
|
||||
val input = "(list 2 3)"
|
||||
|
||||
assertSExpressionsMatch(parseString("(2 3)"), evaluateString(input))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun listWithManyArguments() {
|
||||
val input = "(list 'm 'a 'n 'y 'a 'r 'g 's)"
|
||||
|
||||
assertSExpressionsMatch(parseString("(m a n y a r g s)"), evaluateString(input))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun listWithOneListArgument() {
|
||||
val input = "(list '(1))"
|
||||
|
||||
assertSExpressionsMatch(parseString("((1))"), evaluateString(input))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun listWithManyListArguments() {
|
||||
val input = "(list '(1) '(2 3) ())"
|
||||
|
||||
assertSExpressionsMatch(parseString("((1) (2 3) ())"), evaluateString(input))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun staticMakeList() {
|
||||
assertSExpressionsMatch(parseString("(22)"), makeList(parseString("22")))
|
||||
}
|
||||
}
|
|
@ -1,57 +0,0 @@
|
|||
package function.builtin.cons;
|
||||
|
||||
import function.ArgumentValidator.BadArgumentTypeException;
|
||||
import function.ArgumentValidator.TooFewArgumentsException;
|
||||
import function.ArgumentValidator.TooManyArgumentsException;
|
||||
import org.junit.Test;
|
||||
import testutil.SymbolAndFunctionCleaner;
|
||||
|
||||
import static testutil.TestUtilities.assertSExpressionsMatch;
|
||||
import static testutil.TestUtilities.evaluateString;
|
||||
import static testutil.TestUtilities.parseString;
|
||||
|
||||
public class RestTest extends SymbolAndFunctionCleaner {
|
||||
|
||||
@Test
|
||||
public void restOfNil() {
|
||||
String input = "(rest nil)";
|
||||
|
||||
assertSExpressionsMatch(parseString("()"), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void restOfList() {
|
||||
String input = "(rest '(1 2 3))";
|
||||
|
||||
assertSExpressionsMatch(parseString("(2 3)"), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cdrOfList() {
|
||||
String input = "(cdr '(1 2 3))";
|
||||
|
||||
assertSExpressionsMatch(parseString("(2 3)"), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nestedRestOfList() {
|
||||
String input = "(rest (rest '(1 2 3)))";
|
||||
|
||||
assertSExpressionsMatch(parseString("(3)"), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test(expected = BadArgumentTypeException.class)
|
||||
public void restOfSymbol() {
|
||||
evaluateString("(rest 'x)");
|
||||
}
|
||||
|
||||
@Test(expected = TooManyArgumentsException.class)
|
||||
public void restWithTooManyArguments() {
|
||||
evaluateString("(rest '(1 2) '(1 2) \"oh\")");
|
||||
}
|
||||
|
||||
@Test(expected = TooFewArgumentsException.class)
|
||||
public void restWithTooFewArguments() {
|
||||
evaluateString("(rest)");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
package function.builtin.cons
|
||||
|
||||
import function.ArgumentValidator.BadArgumentTypeException
|
||||
import function.ArgumentValidator.TooFewArgumentsException
|
||||
import function.ArgumentValidator.TooManyArgumentsException
|
||||
import org.junit.jupiter.api.Assertions.assertThrows
|
||||
import org.junit.jupiter.api.Test
|
||||
import testutil.LispTestInstance
|
||||
import testutil.SymbolAndFunctionCleaner
|
||||
import testutil.TestUtilities.assertSExpressionsMatch
|
||||
import testutil.TestUtilities.evaluateString
|
||||
import testutil.TestUtilities.parseString
|
||||
|
||||
@LispTestInstance
|
||||
class RestTest : SymbolAndFunctionCleaner() {
|
||||
|
||||
@Test
|
||||
fun restOfNil() {
|
||||
val input = "(rest nil)"
|
||||
|
||||
assertSExpressionsMatch(parseString("()"), evaluateString(input))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun restOfList() {
|
||||
val input = "(rest '(1 2 3))"
|
||||
|
||||
assertSExpressionsMatch(parseString("(2 3)"), evaluateString(input))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun cdrOfList() {
|
||||
val input = "(cdr '(1 2 3))"
|
||||
|
||||
assertSExpressionsMatch(parseString("(2 3)"), evaluateString(input))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun nestedRestOfList() {
|
||||
val input = "(rest (rest '(1 2 3)))"
|
||||
|
||||
assertSExpressionsMatch(parseString("(3)"), evaluateString(input))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun restOfSymbol() {
|
||||
assertThrows(BadArgumentTypeException::class.java) {
|
||||
evaluateString("(rest 'x)")
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun restWithTooManyArguments() {
|
||||
assertThrows(TooManyArgumentsException::class.java) {
|
||||
evaluateString("(rest '(1 2) '(1 2) \"oh\")")
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun restWithTooFewArguments() {
|
||||
assertThrows(TooFewArgumentsException::class.java) {
|
||||
evaluateString("(rest)")
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue