Convert more tests to kotlin
This commit is contained in:
parent
fc45019a9a
commit
cd158acdbf
|
@ -1,38 +0,0 @@
|
|||
package function.builtin.predicate;
|
||||
|
||||
import function.ArgumentValidator.TooFewArgumentsException;
|
||||
import function.ArgumentValidator.TooManyArgumentsException;
|
||||
import org.junit.Test;
|
||||
import testutil.SymbolAndFunctionCleaner;
|
||||
|
||||
import static testutil.TestUtilities.evaluateString;
|
||||
import static testutil.TypeAssertions.assertNil;
|
||||
import static testutil.TypeAssertions.assertT;
|
||||
|
||||
public class AtomTest extends SymbolAndFunctionCleaner {
|
||||
|
||||
@Test
|
||||
public void atomIsAtom() {
|
||||
assertT(evaluateString("(atom 'a)"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void atomIsAtomWithAlias() {
|
||||
assertT(evaluateString("(atom? 'a)"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void listIsNotAtom() {
|
||||
assertNil(evaluateString("(atom '(1 2 3))"));
|
||||
}
|
||||
|
||||
@Test(expected = TooManyArgumentsException.class)
|
||||
public void testApplyWithTooManyArguments() {
|
||||
evaluateString("(atom '1 '2)");
|
||||
}
|
||||
|
||||
@Test(expected = TooFewArgumentsException.class)
|
||||
public void testApplyWithTooFewArguments() {
|
||||
evaluateString("(atom)");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
package function.builtin.predicate
|
||||
|
||||
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.evaluateString
|
||||
import testutil.TypeAssertions.assertNil
|
||||
import testutil.TypeAssertions.assertT
|
||||
|
||||
@LispTestInstance
|
||||
class AtomTest : SymbolAndFunctionCleaner() {
|
||||
|
||||
@Test
|
||||
fun atomIsAtom() {
|
||||
assertT(evaluateString("(atom 'a)"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun atomIsAtomWithAlias() {
|
||||
assertT(evaluateString("(atom? 'a)"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun listIsNotAtom() {
|
||||
assertNil(evaluateString("(atom '(1 2 3))"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testApplyWithTooManyArguments() {
|
||||
assertThrows(TooManyArgumentsException::class.java) {
|
||||
evaluateString("(atom '1 '2)")
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testApplyWithTooFewArguments() {
|
||||
assertThrows(TooFewArgumentsException::class.java) {
|
||||
evaluateString("(atom)")
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,112 +0,0 @@
|
|||
package function.builtin.predicate;
|
||||
|
||||
import function.ArgumentValidator.TooFewArgumentsException;
|
||||
import function.ArgumentValidator.TooManyArgumentsException;
|
||||
import org.junit.Test;
|
||||
import testutil.SymbolAndFunctionCleaner;
|
||||
|
||||
import static testutil.TestUtilities.evaluateString;
|
||||
import static testutil.TypeAssertions.assertNil;
|
||||
import static testutil.TypeAssertions.assertT;
|
||||
|
||||
public class EqTest extends SymbolAndFunctionCleaner {
|
||||
|
||||
@Test
|
||||
public void eqWithEqualAtoms() {
|
||||
String input = "(eq 1 1)";
|
||||
|
||||
assertT(evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void eqWithEqualAtomsAndAlias() {
|
||||
String input = "(eq? 1 1)";
|
||||
|
||||
assertT(evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void eqWithUnequalAtoms() {
|
||||
String input = "(eq 1 2)";
|
||||
|
||||
assertNil(evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void eqWithTwoEqualNumbers() {
|
||||
String input = "(eq -4 -4)";
|
||||
|
||||
assertT(evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void eqWithTwoUnequalNumbers() {
|
||||
String input = "(eq +5 +7)";
|
||||
|
||||
assertNil(evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void eqWithTwoEqualStrings() {
|
||||
String input = "(eq \"potato\" \"potato\")";
|
||||
|
||||
assertT(evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void eqWithTwoUnequalStrings() {
|
||||
String input = "(eq \"tomato\" \"potato\")";
|
||||
|
||||
assertNil(evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void eqWithTwoDifferentCasedStrings() {
|
||||
String input = "(eq \"Potato\" \"potato\")";
|
||||
|
||||
assertNil(evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void eqWithAtomAndList() {
|
||||
String input = "(eq 1 '(2))";
|
||||
|
||||
assertNil(evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void eqWithSameList() {
|
||||
String initializeL1 = "(setq l1 '(1 2 3))";
|
||||
String initializeL2 = "(setq l2 l1)";
|
||||
String input = "(eq l1 l2)";
|
||||
|
||||
evaluateString(initializeL1);
|
||||
evaluateString(initializeL2);
|
||||
|
||||
assertT(evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void eqWithEqualLists() {
|
||||
String input = "(eq '(1 2) '(1 2))";
|
||||
|
||||
assertNil(evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void eqWithUnequalLists() {
|
||||
String input = "(eq '(1 2) '(3 4))";
|
||||
|
||||
assertNil(evaluateString(input));
|
||||
}
|
||||
|
||||
@Test(expected = TooManyArgumentsException.class)
|
||||
public void eqWithTooManyArguments() {
|
||||
evaluateString("(eq 'one 'two 'three)");
|
||||
}
|
||||
|
||||
@Test(expected = TooFewArgumentsException.class)
|
||||
public void eqWithTooFewArguments() {
|
||||
evaluateString("(eq 'one)");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,118 @@
|
|||
package function.builtin.predicate
|
||||
|
||||
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.evaluateString
|
||||
import testutil.TypeAssertions.assertNil
|
||||
import testutil.TypeAssertions.assertT
|
||||
|
||||
@LispTestInstance
|
||||
class EqTest : SymbolAndFunctionCleaner() {
|
||||
|
||||
@Test
|
||||
fun eqWithEqualAtoms() {
|
||||
val input = "(eq 1 1)"
|
||||
|
||||
assertT(evaluateString(input))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun eqWithEqualAtomsAndAlias() {
|
||||
val input = "(eq? 1 1)"
|
||||
|
||||
assertT(evaluateString(input))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun eqWithUnequalAtoms() {
|
||||
val input = "(eq 1 2)"
|
||||
|
||||
assertNil(evaluateString(input))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun eqWithTwoEqualNumbers() {
|
||||
val input = "(eq -4 -4)"
|
||||
|
||||
assertT(evaluateString(input))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun eqWithTwoUnequalNumbers() {
|
||||
val input = "(eq +5 +7)"
|
||||
|
||||
assertNil(evaluateString(input))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun eqWithTwoEqualStrings() {
|
||||
val input = "(eq \"potato\" \"potato\")"
|
||||
|
||||
assertT(evaluateString(input))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun eqWithTwoUnequalStrings() {
|
||||
val input = "(eq \"tomato\" \"potato\")"
|
||||
|
||||
assertNil(evaluateString(input))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun eqWithTwoDifferentCasedStrings() {
|
||||
val input = "(eq \"Potato\" \"potato\")"
|
||||
|
||||
assertNil(evaluateString(input))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun eqWithAtomAndList() {
|
||||
val input = "(eq 1 '(2))"
|
||||
|
||||
assertNil(evaluateString(input))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun eqWithSameList() {
|
||||
val initializeL1 = "(setq l1 '(1 2 3))"
|
||||
val initializeL2 = "(setq l2 l1)"
|
||||
val input = "(eq l1 l2)"
|
||||
|
||||
evaluateString(initializeL1)
|
||||
evaluateString(initializeL2)
|
||||
|
||||
assertT(evaluateString(input))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun eqWithEqualLists() {
|
||||
val input = "(eq '(1 2) '(1 2))"
|
||||
|
||||
assertNil(evaluateString(input))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun eqWithUnequalLists() {
|
||||
val input = "(eq '(1 2) '(3 4))"
|
||||
|
||||
assertNil(evaluateString(input))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun eqWithTooManyArguments() {
|
||||
assertThrows(TooManyArgumentsException::class.java) {
|
||||
evaluateString("(eq 'one 'two 'three)")
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun eqWithTooFewArguments() {
|
||||
assertThrows(TooFewArgumentsException::class.java) {
|
||||
evaluateString("(eq 'one)")
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,114 +0,0 @@
|
|||
package function.builtin.predicate;
|
||||
|
||||
import function.ArgumentValidator.TooFewArgumentsException;
|
||||
import function.ArgumentValidator.TooManyArgumentsException;
|
||||
import org.junit.Test;
|
||||
import testutil.SymbolAndFunctionCleaner;
|
||||
|
||||
import static testutil.TestUtilities.evaluateString;
|
||||
import static testutil.TypeAssertions.assertNil;
|
||||
import static testutil.TypeAssertions.assertT;
|
||||
|
||||
public class EqualTest extends SymbolAndFunctionCleaner {
|
||||
|
||||
@Test
|
||||
public void equalWithTwoEqualAtoms() {
|
||||
String input = "(equal 'a 'a)";
|
||||
|
||||
assertT(evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void equalWithTwoEqualAtomsAndAlias() {
|
||||
String input = "(equal? 'a 'a)";
|
||||
|
||||
assertT(evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void equalWithTwoUnequalAtoms() {
|
||||
String input = "(equal 'a 'b)";
|
||||
|
||||
assertNil(evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void equalWithTwoEqualNumbers() {
|
||||
String input = "(equal -4 -4)";
|
||||
|
||||
assertT(evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void equalWithTwoUnequalNumbers() {
|
||||
String input = "(equal +5 +7)";
|
||||
|
||||
assertNil(evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void equalWithTwoEqualStrings() {
|
||||
String input = "(equal \"potato\" \"potato\")";
|
||||
|
||||
assertT(evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void equalWithTwoUnequalStrings() {
|
||||
String input = "(equal \"tomato\" \"potato\")";
|
||||
|
||||
assertNil(evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void equalWithTwoDifferentCasedStrings() {
|
||||
String input = "(equal \"Potato\" \"potato\")";
|
||||
|
||||
assertNil(evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void equalWithAtomAndList() {
|
||||
String input = "(equal \"string\" '(m i k e))";
|
||||
|
||||
assertNil(evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void equalWithListAndAtom() {
|
||||
String input = "(equal '(m i k e) \"string\")";
|
||||
|
||||
assertNil(evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void equalWithTwoEqualLists() {
|
||||
String input = "(equal '(1 2 3) '(1 2 3))";
|
||||
|
||||
assertT(evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void equalWithTwoUnequalLists() {
|
||||
String input = "(equal '(1 2 3) '(1 3 3))";
|
||||
|
||||
assertNil(evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void equalWithTwoEqualNestedLists() {
|
||||
String input = "(equal '(1 ((2) 3)) '(1 ((2) 3)))";
|
||||
|
||||
assertT(evaluateString(input));
|
||||
}
|
||||
|
||||
@Test(expected = TooManyArgumentsException.class)
|
||||
public void equalWithTooManyArguments() {
|
||||
evaluateString("(equal 1 2 3)");
|
||||
}
|
||||
|
||||
@Test(expected = TooFewArgumentsException.class)
|
||||
public void equalWithTooFewArguments() {
|
||||
evaluateString("(equal 1)");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,120 @@
|
|||
package function.builtin.predicate
|
||||
|
||||
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.evaluateString
|
||||
import testutil.TypeAssertions.assertNil
|
||||
import testutil.TypeAssertions.assertT
|
||||
|
||||
@LispTestInstance
|
||||
class EqualTest : SymbolAndFunctionCleaner() {
|
||||
|
||||
@Test
|
||||
fun equalWithTwoEqualAtoms() {
|
||||
val input = "(equal 'a 'a)"
|
||||
|
||||
assertT(evaluateString(input))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun equalWithTwoEqualAtomsAndAlias() {
|
||||
val input = "(equal? 'a 'a)"
|
||||
|
||||
assertT(evaluateString(input))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun equalWithTwoUnequalAtoms() {
|
||||
val input = "(equal 'a 'b)"
|
||||
|
||||
assertNil(evaluateString(input))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun equalWithTwoEqualNumbers() {
|
||||
val input = "(equal -4 -4)"
|
||||
|
||||
assertT(evaluateString(input))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun equalWithTwoUnequalNumbers() {
|
||||
val input = "(equal +5 +7)"
|
||||
|
||||
assertNil(evaluateString(input))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun equalWithTwoEqualStrings() {
|
||||
val input = "(equal \"potato\" \"potato\")"
|
||||
|
||||
assertT(evaluateString(input))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun equalWithTwoUnequalStrings() {
|
||||
val input = "(equal \"tomato\" \"potato\")"
|
||||
|
||||
assertNil(evaluateString(input))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun equalWithTwoDifferentCasedStrings() {
|
||||
val input = "(equal \"Potato\" \"potato\")"
|
||||
|
||||
assertNil(evaluateString(input))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun equalWithAtomAndList() {
|
||||
val input = "(equal \"string\" '(m i k e))"
|
||||
|
||||
assertNil(evaluateString(input))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun equalWithListAndAtom() {
|
||||
val input = "(equal '(m i k e) \"string\")"
|
||||
|
||||
assertNil(evaluateString(input))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun equalWithTwoEqualLists() {
|
||||
val input = "(equal '(1 2 3) '(1 2 3))"
|
||||
|
||||
assertT(evaluateString(input))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun equalWithTwoUnequalLists() {
|
||||
val input = "(equal '(1 2 3) '(1 3 3))"
|
||||
|
||||
assertNil(evaluateString(input))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun equalWithTwoEqualNestedLists() {
|
||||
val input = "(equal '(1 ((2) 3)) '(1 ((2) 3)))"
|
||||
|
||||
assertT(evaluateString(input))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun equalWithTooManyArguments() {
|
||||
assertThrows(TooManyArgumentsException::class.java) {
|
||||
evaluateString("(equal 1 2 3)")
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun equalWithTooFewArguments() {
|
||||
assertThrows(TooFewArgumentsException::class.java) {
|
||||
evaluateString("(equal 1)")
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,38 +0,0 @@
|
|||
package function.builtin.predicate;
|
||||
|
||||
import function.ArgumentValidator.TooFewArgumentsException;
|
||||
import function.ArgumentValidator.TooManyArgumentsException;
|
||||
import org.junit.Test;
|
||||
import testutil.SymbolAndFunctionCleaner;
|
||||
|
||||
import static testutil.TestUtilities.evaluateString;
|
||||
import static testutil.TypeAssertions.assertNil;
|
||||
import static testutil.TypeAssertions.assertT;
|
||||
|
||||
public class ListpTest extends SymbolAndFunctionCleaner {
|
||||
|
||||
@Test
|
||||
public void listpWithList() {
|
||||
assertT(evaluateString("(listp '(1))"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void listpWithListAndAlias() {
|
||||
assertT(evaluateString("(list? '(1))"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void listpWithNonList() {
|
||||
assertNil(evaluateString("(listp 1)"));
|
||||
}
|
||||
|
||||
@Test(expected = TooFewArgumentsException.class)
|
||||
public void listpWithTooFewArguments() {
|
||||
evaluateString("(listp)");
|
||||
}
|
||||
|
||||
@Test(expected = TooManyArgumentsException.class)
|
||||
public void listpWithTooManyArguments() {
|
||||
evaluateString("(listp '() '())");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
package function.builtin.predicate
|
||||
|
||||
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.evaluateString
|
||||
import testutil.TypeAssertions.assertNil
|
||||
import testutil.TypeAssertions.assertT
|
||||
|
||||
@LispTestInstance
|
||||
class ListpTest : SymbolAndFunctionCleaner() {
|
||||
|
||||
@Test
|
||||
fun listpWithList() {
|
||||
assertT(evaluateString("(listp '(1))"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun listpWithListAndAlias() {
|
||||
assertT(evaluateString("(list? '(1))"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun listpWithNonList() {
|
||||
assertNil(evaluateString("(listp 1)"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun listpWithTooFewArguments() {
|
||||
assertThrows(TooFewArgumentsException::class.java) {
|
||||
evaluateString("(listp)")
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun listpWithTooManyArguments() {
|
||||
assertThrows(TooManyArgumentsException::class.java) {
|
||||
evaluateString("(listp '() '())")
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,38 +0,0 @@
|
|||
package function.builtin.predicate;
|
||||
|
||||
import function.ArgumentValidator.TooFewArgumentsException;
|
||||
import function.ArgumentValidator.TooManyArgumentsException;
|
||||
import org.junit.Test;
|
||||
import testutil.SymbolAndFunctionCleaner;
|
||||
|
||||
import static testutil.TestUtilities.evaluateString;
|
||||
import static testutil.TypeAssertions.assertNil;
|
||||
import static testutil.TypeAssertions.assertT;
|
||||
|
||||
public class NullTest extends SymbolAndFunctionCleaner {
|
||||
|
||||
@Test
|
||||
public void nilIsNull() {
|
||||
assertT(evaluateString("(null ())"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nilIsNullWithAlias() {
|
||||
assertT(evaluateString("(null? ())"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void listIsNotNull() {
|
||||
assertNil(evaluateString("(null '(1))"));
|
||||
}
|
||||
|
||||
@Test(expected = TooFewArgumentsException.class)
|
||||
public void testNullWithTooFewArguments() {
|
||||
evaluateString("(null)");
|
||||
}
|
||||
|
||||
@Test(expected = TooManyArgumentsException.class)
|
||||
public void testNullWithTooManyArguments() {
|
||||
evaluateString("(null 1 2)");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
package function.builtin.predicate
|
||||
|
||||
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.evaluateString
|
||||
import testutil.TypeAssertions.assertNil
|
||||
import testutil.TypeAssertions.assertT
|
||||
|
||||
@LispTestInstance
|
||||
class NullTest : SymbolAndFunctionCleaner() {
|
||||
|
||||
@Test
|
||||
fun nilIsNull() {
|
||||
assertT(evaluateString("(null ())"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun nilIsNullWithAlias() {
|
||||
assertT(evaluateString("(null? ())"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun listIsNotNull() {
|
||||
assertNil(evaluateString("(null '(1))"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testNullWithTooFewArguments() {
|
||||
assertThrows(TooFewArgumentsException::class.java) {
|
||||
evaluateString("(null)")
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testNullWithTooManyArguments() {
|
||||
assertThrows(TooManyArgumentsException::class.java) {
|
||||
evaluateString("(null 1 2)")
|
||||
}
|
||||
}
|
||||
}
|
|
@ -5,7 +5,6 @@ import function.ArgumentValidator.TooFewArgumentsException
|
|||
import org.junit.jupiter.api.Assertions.assertThrows
|
||||
import org.junit.jupiter.api.Test
|
||||
import testutil.LispTestInstance
|
||||
|
||||
import testutil.SymbolAndFunctionCleaner
|
||||
import testutil.TestUtilities.evaluateString
|
||||
import testutil.TypeAssertions.assertNil
|
||||
|
@ -41,11 +40,15 @@ class NumericEqualTest : SymbolAndFunctionCleaner() {
|
|||
|
||||
@Test
|
||||
fun `bad argument types`() {
|
||||
assertThrows(BadArgumentTypeException::class.java) { evaluateString("(= 'x 'x)") }
|
||||
assertThrows(BadArgumentTypeException::class.java) {
|
||||
evaluateString("(= 'x 'x)")
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `too few arguments`() {
|
||||
assertThrows(TooFewArgumentsException::class.java) { evaluateString("(=)") }
|
||||
assertThrows(TooFewArgumentsException::class.java) {
|
||||
evaluateString("(=)")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,58 +0,0 @@
|
|||
package function.builtin.predicate;
|
||||
|
||||
import function.ArgumentValidator.BadArgumentTypeException;
|
||||
import function.ArgumentValidator.TooFewArgumentsException;
|
||||
import org.junit.Test;
|
||||
import testutil.SymbolAndFunctionCleaner;
|
||||
|
||||
import static testutil.TestUtilities.evaluateString;
|
||||
import static testutil.TypeAssertions.assertNil;
|
||||
import static testutil.TypeAssertions.assertT;
|
||||
|
||||
public class NumericGreaterTest extends SymbolAndFunctionCleaner {
|
||||
|
||||
@Test
|
||||
public void greaterThanWithOneNumber_ReturnsT() {
|
||||
String input = "(> 1)";
|
||||
|
||||
assertT(evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void greaterThanWithTwoNumbers_ReturnsNil() {
|
||||
String input = "(> 1 2)";
|
||||
|
||||
assertNil(evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void greaterThanWithTwoNumbers_ReturnsT() {
|
||||
String input = "(> 3 2)";
|
||||
|
||||
assertT(evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void greaterThanWithManyNumbers_ReturnsNil() {
|
||||
String input = "(> 4 3 2 5 1)";
|
||||
|
||||
assertNil(evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void greaterThanWithManyNumbers() {
|
||||
String input = "(> 4 3 2 1 0)";
|
||||
|
||||
assertT(evaluateString(input));
|
||||
}
|
||||
|
||||
@Test(expected = BadArgumentTypeException.class)
|
||||
public void greaterThanWithNonNumbers() {
|
||||
evaluateString("(> 'x 'x)");
|
||||
}
|
||||
|
||||
@Test(expected = TooFewArgumentsException.class)
|
||||
public void greaterThanWithTooFewArguments() {
|
||||
evaluateString("(>)");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,64 @@
|
|||
package function.builtin.predicate
|
||||
|
||||
import function.ArgumentValidator.BadArgumentTypeException
|
||||
import function.ArgumentValidator.TooFewArgumentsException
|
||||
import org.junit.jupiter.api.Assertions.assertThrows
|
||||
import org.junit.jupiter.api.Test
|
||||
import testutil.LispTestInstance
|
||||
import testutil.SymbolAndFunctionCleaner
|
||||
import testutil.TestUtilities.evaluateString
|
||||
import testutil.TypeAssertions.assertNil
|
||||
import testutil.TypeAssertions.assertT
|
||||
|
||||
@LispTestInstance
|
||||
class NumericGreaterTest : SymbolAndFunctionCleaner() {
|
||||
|
||||
@Test
|
||||
fun greaterThanWithOneNumber_ReturnsT() {
|
||||
val input = "(> 1)"
|
||||
|
||||
assertT(evaluateString(input))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun greaterThanWithTwoNumbers_ReturnsNil() {
|
||||
val input = "(> 1 2)"
|
||||
|
||||
assertNil(evaluateString(input))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun greaterThanWithTwoNumbers_ReturnsT() {
|
||||
val input = "(> 3 2)"
|
||||
|
||||
assertT(evaluateString(input))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun greaterThanWithManyNumbers_ReturnsNil() {
|
||||
val input = "(> 4 3 2 5 1)"
|
||||
|
||||
assertNil(evaluateString(input))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun greaterThanWithManyNumbers() {
|
||||
val input = "(> 4 3 2 1 0)"
|
||||
|
||||
assertT(evaluateString(input))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun greaterThanWithNonNumbers() {
|
||||
assertThrows(BadArgumentTypeException::class.java) {
|
||||
evaluateString("(> 'x 'x)")
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun greaterThanWithTooFewArguments() {
|
||||
assertThrows(TooFewArgumentsException::class.java) {
|
||||
evaluateString("(>)")
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,58 +0,0 @@
|
|||
package function.builtin.predicate;
|
||||
|
||||
import function.ArgumentValidator.BadArgumentTypeException;
|
||||
import function.ArgumentValidator.TooFewArgumentsException;
|
||||
import org.junit.Test;
|
||||
import testutil.SymbolAndFunctionCleaner;
|
||||
|
||||
import static testutil.TestUtilities.evaluateString;
|
||||
import static testutil.TypeAssertions.assertNil;
|
||||
import static testutil.TypeAssertions.assertT;
|
||||
|
||||
public class NumericLessTest extends SymbolAndFunctionCleaner {
|
||||
|
||||
@Test
|
||||
public void lessThanWithOneNumber_ReturnsT() {
|
||||
String input = "(< 1)";
|
||||
|
||||
assertT(evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void lessThanWithTwoNumbers_ReturnsNil() {
|
||||
String input = "(< 2 1)";
|
||||
|
||||
assertNil(evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void lessThanWithTwoNumbers_ReturnsT() {
|
||||
String input = "(< 2 3)";
|
||||
|
||||
assertT(evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void lessThanWithManyNumbers_ReturnsNil() {
|
||||
String input = "(< 4 3 2 5 1)";
|
||||
|
||||
assertNil(evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void lessThanWithManyNumbers_ReturnsT() {
|
||||
String input = "(< 0 1 2 3 4)";
|
||||
|
||||
assertT(evaluateString(input));
|
||||
}
|
||||
|
||||
@Test(expected = BadArgumentTypeException.class)
|
||||
public void lessThanWithNonNumbers() {
|
||||
evaluateString("(< '(1) '(2))");
|
||||
}
|
||||
|
||||
@Test(expected = TooFewArgumentsException.class)
|
||||
public void lessThanWithTooFewArguments() {
|
||||
evaluateString("(<)");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,64 @@
|
|||
package function.builtin.predicate
|
||||
|
||||
import function.ArgumentValidator.BadArgumentTypeException
|
||||
import function.ArgumentValidator.TooFewArgumentsException
|
||||
import org.junit.jupiter.api.Assertions.assertThrows
|
||||
import org.junit.jupiter.api.Test
|
||||
import testutil.LispTestInstance
|
||||
import testutil.SymbolAndFunctionCleaner
|
||||
import testutil.TestUtilities.evaluateString
|
||||
import testutil.TypeAssertions.assertNil
|
||||
import testutil.TypeAssertions.assertT
|
||||
|
||||
@LispTestInstance
|
||||
class NumericLessTest : SymbolAndFunctionCleaner() {
|
||||
|
||||
@Test
|
||||
fun lessThanWithOneNumber_ReturnsT() {
|
||||
val input = "(< 1)"
|
||||
|
||||
assertT(evaluateString(input))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun lessThanWithTwoNumbers_ReturnsNil() {
|
||||
val input = "(< 2 1)"
|
||||
|
||||
assertNil(evaluateString(input))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun lessThanWithTwoNumbers_ReturnsT() {
|
||||
val input = "(< 2 3)"
|
||||
|
||||
assertT(evaluateString(input))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun lessThanWithManyNumbers_ReturnsNil() {
|
||||
val input = "(< 4 3 2 5 1)"
|
||||
|
||||
assertNil(evaluateString(input))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun lessThanWithManyNumbers_ReturnsT() {
|
||||
val input = "(< 0 1 2 3 4)"
|
||||
|
||||
assertT(evaluateString(input))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun lessThanWithNonNumbers() {
|
||||
assertThrows(BadArgumentTypeException::class.java) {
|
||||
evaluateString("(< '(1) '(2))")
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun lessThanWithTooFewArguments() {
|
||||
assertThrows(TooFewArgumentsException::class.java) {
|
||||
evaluateString("(<)")
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,159 +0,0 @@
|
|||
package function.builtin.special;
|
||||
|
||||
import function.ArgumentValidator.BadArgumentTypeException;
|
||||
import function.ArgumentValidator.DottedArgumentListException;
|
||||
import function.ArgumentValidator.TooFewArgumentsException;
|
||||
import function.ArgumentValidator.TooManyArgumentsException;
|
||||
import function.builtin.Eval.UndefinedSymbolException;
|
||||
import org.junit.Test;
|
||||
import sexpression.Cons;
|
||||
import sexpression.LispNumber;
|
||||
import sexpression.Nil;
|
||||
import testutil.SymbolAndFunctionCleaner;
|
||||
|
||||
import static testutil.TestUtilities.assertSExpressionsMatch;
|
||||
import static testutil.TestUtilities.evaluateString;
|
||||
|
||||
public class LetStarTest extends SymbolAndFunctionCleaner {
|
||||
|
||||
@Test
|
||||
public void simpleLet() {
|
||||
String input = "(let* ((x 1)) x)";
|
||||
|
||||
assertSExpressionsMatch(new LispNumber("1"), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void emptyLet_ReturnsNil() {
|
||||
String input = "(let* ())";
|
||||
|
||||
assertSExpressionsMatch(Nil.INSTANCE, evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void letStarWithSymbolsOnly_SetsValuesToNil() {
|
||||
String input = "(let* ((x) (y)) (list x y))";
|
||||
|
||||
assertSExpressionsMatch(new Cons(Nil.INSTANCE, new Cons(Nil.INSTANCE, Nil.INSTANCE)), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void letStarWithSetq_DoesNotAlterGlobalVariable() {
|
||||
String before = "(setq x 22)";
|
||||
String input = "(let* ((x 1)) x)";
|
||||
String after = "x";
|
||||
|
||||
assertSExpressionsMatch(new LispNumber("22"), evaluateString(before));
|
||||
assertSExpressionsMatch(new LispNumber("1"), evaluateString(input));
|
||||
assertSExpressionsMatch(new LispNumber("22"), evaluateString(after));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void letStarWithNestedSetq_DoesNotAlterGlobalVariable() {
|
||||
String before = "(setq x 22)";
|
||||
String input = "(let* ((x 33)) (setq x 44) x)";
|
||||
String after = "x";
|
||||
|
||||
assertSExpressionsMatch(new LispNumber("22"), evaluateString(before));
|
||||
assertSExpressionsMatch(new LispNumber("44"), evaluateString(input));
|
||||
assertSExpressionsMatch(new LispNumber("22"), evaluateString(after));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nestedLet() {
|
||||
String input = "(let* ((x 1)) (let* ((y (+ 1 x))) y))";
|
||||
|
||||
assertSExpressionsMatch(new LispNumber("2"), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nestedLetWithGlobals() {
|
||||
String before = "(setq x 92)";
|
||||
String input = "(let* ((x 1)) (let* ((y (+ 1 x))) y))";
|
||||
String after = "x";
|
||||
|
||||
assertSExpressionsMatch(new LispNumber("92"), evaluateString(before));
|
||||
assertSExpressionsMatch(new LispNumber("2"), evaluateString(input));
|
||||
assertSExpressionsMatch(new LispNumber("92"), evaluateString(after));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void alterGlobalVariableFromLet() {
|
||||
String before = "(setq x 1)";
|
||||
String input = "(let* ((y 1)) (setq x 2))";
|
||||
String after = "x";
|
||||
|
||||
assertSExpressionsMatch(new LispNumber("1"), evaluateString(before));
|
||||
assertSExpressionsMatch(new LispNumber("2"), evaluateString(input));
|
||||
assertSExpressionsMatch(new LispNumber("2"), evaluateString(after));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void accessGlobalVariableFromLet() {
|
||||
String before = "(setq x 1)";
|
||||
String input = "(let* () x)";
|
||||
|
||||
assertSExpressionsMatch(new LispNumber("1"), evaluateString(before));
|
||||
assertSExpressionsMatch(new LispNumber("1"), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test(expected = UndefinedSymbolException.class)
|
||||
public void letStarDoesNotSetGlobalVariable() {
|
||||
String input = "(let* ((x 1)) nil)";
|
||||
|
||||
evaluateString(input);
|
||||
evaluateString("x");
|
||||
}
|
||||
|
||||
@Test(expected = BadArgumentTypeException.class)
|
||||
public void letStarWithNonList() {
|
||||
evaluateString("(let* a)");
|
||||
}
|
||||
|
||||
@Test(expected = BadArgumentTypeException.class)
|
||||
public void letStarWithNoPairs() {
|
||||
evaluateString("(let* (a))");
|
||||
}
|
||||
|
||||
@Test(expected = TooFewArgumentsException.class)
|
||||
public void letStarWithTooFewItemsInPair() {
|
||||
evaluateString("(let* (()))");
|
||||
}
|
||||
|
||||
@Test(expected = TooManyArgumentsException.class)
|
||||
public void letStarWithTooManyItemsInPair() {
|
||||
evaluateString("(let* ((a b c)))");
|
||||
}
|
||||
|
||||
@Test(expected = BadArgumentTypeException.class)
|
||||
public void letStarWithNonSymbolInPair() {
|
||||
evaluateString("(let* ((1 b)))");
|
||||
}
|
||||
|
||||
@Test(expected = TooFewArgumentsException.class)
|
||||
public void letStarWithTooFewArguments() {
|
||||
evaluateString("(let*)");
|
||||
}
|
||||
|
||||
@Test(expected = DottedArgumentListException.class)
|
||||
public void letStarWithDottedArgumentList() {
|
||||
evaluateString("(apply 'let* (cons 'a 'b))");
|
||||
}
|
||||
|
||||
@Test(expected = DottedArgumentListException.class)
|
||||
public void letStarWithDottedPairList() {
|
||||
evaluateString("(apply 'let* (cons (cons 'a 'b) nil))");
|
||||
}
|
||||
|
||||
@Test(expected = DottedArgumentListException.class)
|
||||
public void letStarWithDottedPair() {
|
||||
evaluateString("(apply 'let* (cons (cons (cons 'a 'b) nil) nil))");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void letStarEvaluatesSymbolsInSequence() {
|
||||
String input = "(let* ((x 1) (y (+ x 1))) (+ x y))";
|
||||
|
||||
assertSExpressionsMatch(new LispNumber("3"), evaluateString(input));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,182 @@
|
|||
package function.builtin.special
|
||||
|
||||
import function.ArgumentValidator.BadArgumentTypeException
|
||||
import function.ArgumentValidator.DottedArgumentListException
|
||||
import function.ArgumentValidator.TooFewArgumentsException
|
||||
import function.ArgumentValidator.TooManyArgumentsException
|
||||
import function.builtin.Eval.UndefinedSymbolException
|
||||
import org.junit.jupiter.api.Assertions.assertThrows
|
||||
import org.junit.jupiter.api.Test
|
||||
import sexpression.Cons
|
||||
import sexpression.LispNumber
|
||||
import sexpression.Nil
|
||||
import testutil.LispTestInstance
|
||||
import testutil.SymbolAndFunctionCleaner
|
||||
import testutil.TestUtilities.assertSExpressionsMatch
|
||||
import testutil.TestUtilities.evaluateString
|
||||
|
||||
@LispTestInstance
|
||||
class LetStarTest : SymbolAndFunctionCleaner() {
|
||||
|
||||
@Test
|
||||
fun simpleLet() {
|
||||
val input = "(let* ((x 1)) x)"
|
||||
|
||||
assertSExpressionsMatch(LispNumber("1"), evaluateString(input))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun emptyLet_ReturnsNil() {
|
||||
val input = "(let* ())"
|
||||
|
||||
assertSExpressionsMatch(Nil, evaluateString(input))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun letStarWithSymbolsOnly_SetsValuesToNil() {
|
||||
val input = "(let* ((x) (y)) (list x y))"
|
||||
|
||||
assertSExpressionsMatch(Cons(Nil, Cons(Nil, Nil)), evaluateString(input))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun letStarWithSetq_DoesNotAlterGlobalVariable() {
|
||||
val before = "(setq x 22)"
|
||||
val input = "(let* ((x 1)) x)"
|
||||
val after = "x"
|
||||
|
||||
assertSExpressionsMatch(LispNumber("22"), evaluateString(before))
|
||||
assertSExpressionsMatch(LispNumber("1"), evaluateString(input))
|
||||
assertSExpressionsMatch(LispNumber("22"), evaluateString(after))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun letStarWithNestedSetq_DoesNotAlterGlobalVariable() {
|
||||
val before = "(setq x 22)"
|
||||
val input = "(let* ((x 33)) (setq x 44) x)"
|
||||
val after = "x"
|
||||
|
||||
assertSExpressionsMatch(LispNumber("22"), evaluateString(before))
|
||||
assertSExpressionsMatch(LispNumber("44"), evaluateString(input))
|
||||
assertSExpressionsMatch(LispNumber("22"), evaluateString(after))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun nestedLet() {
|
||||
val input = "(let* ((x 1)) (let* ((y (+ 1 x))) y))"
|
||||
|
||||
assertSExpressionsMatch(LispNumber("2"), evaluateString(input))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun nestedLetWithGlobals() {
|
||||
val before = "(setq x 92)"
|
||||
val input = "(let* ((x 1)) (let* ((y (+ 1 x))) y))"
|
||||
val after = "x"
|
||||
|
||||
assertSExpressionsMatch(LispNumber("92"), evaluateString(before))
|
||||
assertSExpressionsMatch(LispNumber("2"), evaluateString(input))
|
||||
assertSExpressionsMatch(LispNumber("92"), evaluateString(after))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun alterGlobalVariableFromLet() {
|
||||
val before = "(setq x 1)"
|
||||
val input = "(let* ((y 1)) (setq x 2))"
|
||||
val after = "x"
|
||||
|
||||
assertSExpressionsMatch(LispNumber("1"), evaluateString(before))
|
||||
assertSExpressionsMatch(LispNumber("2"), evaluateString(input))
|
||||
assertSExpressionsMatch(LispNumber("2"), evaluateString(after))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun accessGlobalVariableFromLet() {
|
||||
val before = "(setq x 1)"
|
||||
val input = "(let* () x)"
|
||||
|
||||
assertSExpressionsMatch(LispNumber("1"), evaluateString(before))
|
||||
assertSExpressionsMatch(LispNumber("1"), evaluateString(input))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun letStarDoesNotSetGlobalVariable() {
|
||||
val input = "(let* ((x 1)) nil)"
|
||||
|
||||
evaluateString(input)
|
||||
|
||||
assertThrows(UndefinedSymbolException::class.java) {
|
||||
evaluateString("x")
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun letStarWithNonList() {
|
||||
assertThrows(BadArgumentTypeException::class.java) {
|
||||
evaluateString("(let* a)")
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun letStarWithNoPairs() {
|
||||
assertThrows(BadArgumentTypeException::class.java) {
|
||||
evaluateString("(let* (a))")
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun letStarWithTooFewItemsInPair() {
|
||||
assertThrows(TooFewArgumentsException::class.java) {
|
||||
evaluateString("(let* (()))")
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun letStarWithTooManyItemsInPair() {
|
||||
assertThrows(TooManyArgumentsException::class.java) {
|
||||
evaluateString("(let* ((a b c)))")
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun letStarWithNonSymbolInPair() {
|
||||
assertThrows(BadArgumentTypeException::class.java) {
|
||||
evaluateString("(let* ((1 b)))")
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun letStarWithTooFewArguments() {
|
||||
assertThrows(TooFewArgumentsException::class.java) {
|
||||
evaluateString("(let*)")
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun letStarWithDottedArgumentList() {
|
||||
assertThrows(DottedArgumentListException::class.java) {
|
||||
evaluateString("(apply 'let* (cons 'a 'b))")
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun letStarWithDottedPairList() {
|
||||
assertThrows(DottedArgumentListException::class.java) {
|
||||
evaluateString("(apply 'let* (cons (cons 'a 'b) nil))")
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun letStarWithDottedPair() {
|
||||
assertThrows(DottedArgumentListException::class.java) {
|
||||
evaluateString("(apply 'let* (cons (cons (cons 'a 'b) nil) nil))")
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun letStarEvaluatesSymbolsInSequence() {
|
||||
val input = "(let* ((x 1) (y (+ x 1))) (+ x y))"
|
||||
|
||||
assertSExpressionsMatch(LispNumber("3"), evaluateString(input))
|
||||
}
|
||||
}
|
|
@ -1,159 +0,0 @@
|
|||
package function.builtin.special;
|
||||
|
||||
import function.ArgumentValidator.BadArgumentTypeException;
|
||||
import function.ArgumentValidator.DottedArgumentListException;
|
||||
import function.ArgumentValidator.TooFewArgumentsException;
|
||||
import function.ArgumentValidator.TooManyArgumentsException;
|
||||
import function.builtin.Eval.UndefinedSymbolException;
|
||||
import org.junit.Test;
|
||||
import sexpression.Cons;
|
||||
import sexpression.LispNumber;
|
||||
import sexpression.Nil;
|
||||
import testutil.SymbolAndFunctionCleaner;
|
||||
|
||||
import static testutil.TestUtilities.assertSExpressionsMatch;
|
||||
import static testutil.TestUtilities.evaluateString;
|
||||
|
||||
public class LetTest extends SymbolAndFunctionCleaner {
|
||||
|
||||
@Test
|
||||
public void simpleLet() {
|
||||
String input = "(let ((x 1)) x)";
|
||||
|
||||
assertSExpressionsMatch(new LispNumber("1"), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void emptyLet_ReturnsNil() {
|
||||
String input = "(let ())";
|
||||
|
||||
assertSExpressionsMatch(Nil.INSTANCE, evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void letWithSymbolsOnly_SetsValuesToNil() {
|
||||
String input = "(let ((x) (y)) (list x y))";
|
||||
|
||||
assertSExpressionsMatch(new Cons(Nil.INSTANCE, new Cons(Nil.INSTANCE, Nil.INSTANCE)), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void letWithSetq_DoesNotAlterGlobalVariable() {
|
||||
String before = "(setq x 22)";
|
||||
String input = "(let ((x 1)) x)";
|
||||
String after = "x";
|
||||
|
||||
assertSExpressionsMatch(new LispNumber("22"), evaluateString(before));
|
||||
assertSExpressionsMatch(new LispNumber("1"), evaluateString(input));
|
||||
assertSExpressionsMatch(new LispNumber("22"), evaluateString(after));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void letWithNestedSetq_DoesNotAlterGlobalVariable() {
|
||||
String before = "(setq x 22)";
|
||||
String input = "(let ((x 33)) (setq x 44) x)";
|
||||
String after = "x";
|
||||
|
||||
assertSExpressionsMatch(new LispNumber("22"), evaluateString(before));
|
||||
assertSExpressionsMatch(new LispNumber("44"), evaluateString(input));
|
||||
assertSExpressionsMatch(new LispNumber("22"), evaluateString(after));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nestedLet() {
|
||||
String input = "(let ((x 1)) (let ((y (+ 1 x))) y))";
|
||||
|
||||
assertSExpressionsMatch(new LispNumber("2"), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nestedLetWithGlobals() {
|
||||
String before = "(setq x 92)";
|
||||
String input = "(let ((x 1)) (let ((y (+ 1 x))) y))";
|
||||
String after = "x";
|
||||
|
||||
assertSExpressionsMatch(new LispNumber("92"), evaluateString(before));
|
||||
assertSExpressionsMatch(new LispNumber("2"), evaluateString(input));
|
||||
assertSExpressionsMatch(new LispNumber("92"), evaluateString(after));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void alterGlobalVariableFromLet() {
|
||||
String before = "(setq x 1)";
|
||||
String input = "(let ((y 1)) (setq x 2))";
|
||||
String after = "x";
|
||||
|
||||
assertSExpressionsMatch(new LispNumber("1"), evaluateString(before));
|
||||
assertSExpressionsMatch(new LispNumber("2"), evaluateString(input));
|
||||
assertSExpressionsMatch(new LispNumber("2"), evaluateString(after));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void accessGlobalVariableFromLet() {
|
||||
String before = "(setq x 1)";
|
||||
String input = "(let () x)";
|
||||
|
||||
assertSExpressionsMatch(new LispNumber("1"), evaluateString(before));
|
||||
assertSExpressionsMatch(new LispNumber("1"), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test(expected = UndefinedSymbolException.class)
|
||||
public void letDoesNotSetGlobalVariable() {
|
||||
String input = "(let ((x 1)) nil)";
|
||||
|
||||
evaluateString(input);
|
||||
evaluateString("x");
|
||||
}
|
||||
|
||||
@Test(expected = BadArgumentTypeException.class)
|
||||
public void letWithNonList() {
|
||||
evaluateString("(let a)");
|
||||
}
|
||||
|
||||
@Test(expected = BadArgumentTypeException.class)
|
||||
public void letWithNoPairs() {
|
||||
evaluateString("(let (a))");
|
||||
}
|
||||
|
||||
@Test(expected = TooFewArgumentsException.class)
|
||||
public void letWithTooFewItemsInPair() {
|
||||
evaluateString("(let (()))");
|
||||
}
|
||||
|
||||
@Test(expected = TooManyArgumentsException.class)
|
||||
public void letWithTooManyItemsInPair() {
|
||||
evaluateString("(let ((a b c)))");
|
||||
}
|
||||
|
||||
@Test(expected = BadArgumentTypeException.class)
|
||||
public void letWithNonSymbolInPair() {
|
||||
evaluateString("(let ((1 b)))");
|
||||
}
|
||||
|
||||
@Test(expected = TooFewArgumentsException.class)
|
||||
public void letWithTooFewArguments() {
|
||||
evaluateString("(let)");
|
||||
}
|
||||
|
||||
@Test(expected = DottedArgumentListException.class)
|
||||
public void letWithDottedArgumentList() {
|
||||
evaluateString("(apply 'let (cons 'a 'b))");
|
||||
}
|
||||
|
||||
@Test(expected = DottedArgumentListException.class)
|
||||
public void letWithDottedPairList() {
|
||||
evaluateString("(apply 'let (cons (cons 'a 'b) nil))");
|
||||
}
|
||||
|
||||
@Test(expected = DottedArgumentListException.class)
|
||||
public void letWithDottedPair() {
|
||||
evaluateString("(apply 'let (cons (cons (cons 'a 'b) nil) nil))");
|
||||
}
|
||||
|
||||
@Test(expected = UndefinedSymbolException.class)
|
||||
public void letEvaluatesSymbolsInParallel() {
|
||||
String input = "(let ((x 1) (y (+ x 1))) (+ x y))";
|
||||
|
||||
assertSExpressionsMatch(new LispNumber("2"), evaluateString(input));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,184 @@
|
|||
package function.builtin.special
|
||||
|
||||
import function.ArgumentValidator.BadArgumentTypeException
|
||||
import function.ArgumentValidator.DottedArgumentListException
|
||||
import function.ArgumentValidator.TooFewArgumentsException
|
||||
import function.ArgumentValidator.TooManyArgumentsException
|
||||
import function.builtin.Eval.UndefinedSymbolException
|
||||
import org.junit.jupiter.api.Assertions.assertThrows
|
||||
import org.junit.jupiter.api.Test
|
||||
import sexpression.Cons
|
||||
import sexpression.LispNumber
|
||||
import sexpression.Nil
|
||||
import testutil.LispTestInstance
|
||||
import testutil.SymbolAndFunctionCleaner
|
||||
import testutil.TestUtilities.assertSExpressionsMatch
|
||||
import testutil.TestUtilities.evaluateString
|
||||
|
||||
@LispTestInstance
|
||||
class LetTest : SymbolAndFunctionCleaner() {
|
||||
|
||||
@Test
|
||||
fun simpleLet() {
|
||||
val input = "(let ((x 1)) x)"
|
||||
|
||||
assertSExpressionsMatch(LispNumber("1"), evaluateString(input))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun emptyLet_ReturnsNil() {
|
||||
val input = "(let ())"
|
||||
|
||||
assertSExpressionsMatch(Nil, evaluateString(input))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun letWithSymbolsOnly_SetsValuesToNil() {
|
||||
val input = "(let ((x) (y)) (list x y))"
|
||||
|
||||
assertSExpressionsMatch(Cons(Nil, Cons(Nil, Nil)), evaluateString(input))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun letWithSetq_DoesNotAlterGlobalVariable() {
|
||||
val before = "(setq x 22)"
|
||||
val input = "(let ((x 1)) x)"
|
||||
val after = "x"
|
||||
|
||||
assertSExpressionsMatch(LispNumber("22"), evaluateString(before))
|
||||
assertSExpressionsMatch(LispNumber("1"), evaluateString(input))
|
||||
assertSExpressionsMatch(LispNumber("22"), evaluateString(after))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun letWithNestedSetq_DoesNotAlterGlobalVariable() {
|
||||
val before = "(setq x 22)"
|
||||
val input = "(let ((x 33)) (setq x 44) x)"
|
||||
val after = "x"
|
||||
|
||||
assertSExpressionsMatch(LispNumber("22"), evaluateString(before))
|
||||
assertSExpressionsMatch(LispNumber("44"), evaluateString(input))
|
||||
assertSExpressionsMatch(LispNumber("22"), evaluateString(after))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun nestedLet() {
|
||||
val input = "(let ((x 1)) (let ((y (+ 1 x))) y))"
|
||||
|
||||
assertSExpressionsMatch(LispNumber("2"), evaluateString(input))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun nestedLetWithGlobals() {
|
||||
val before = "(setq x 92)"
|
||||
val input = "(let ((x 1)) (let ((y (+ 1 x))) y))"
|
||||
val after = "x"
|
||||
|
||||
assertSExpressionsMatch(LispNumber("92"), evaluateString(before))
|
||||
assertSExpressionsMatch(LispNumber("2"), evaluateString(input))
|
||||
assertSExpressionsMatch(LispNumber("92"), evaluateString(after))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun alterGlobalVariableFromLet() {
|
||||
val before = "(setq x 1)"
|
||||
val input = "(let ((y 1)) (setq x 2))"
|
||||
val after = "x"
|
||||
|
||||
assertSExpressionsMatch(LispNumber("1"), evaluateString(before))
|
||||
assertSExpressionsMatch(LispNumber("2"), evaluateString(input))
|
||||
assertSExpressionsMatch(LispNumber("2"), evaluateString(after))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun accessGlobalVariableFromLet() {
|
||||
val before = "(setq x 1)"
|
||||
val input = "(let () x)"
|
||||
|
||||
assertSExpressionsMatch(LispNumber("1"), evaluateString(before))
|
||||
assertSExpressionsMatch(LispNumber("1"), evaluateString(input))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun letDoesNotSetGlobalVariable() {
|
||||
val input = "(let ((x 1)) nil)"
|
||||
|
||||
evaluateString(input)
|
||||
|
||||
assertThrows(UndefinedSymbolException::class.java) {
|
||||
evaluateString("x")
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun letWithNonList() {
|
||||
assertThrows(BadArgumentTypeException::class.java) {
|
||||
evaluateString("(let a)")
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun letWithNoPairs() {
|
||||
assertThrows(BadArgumentTypeException::class.java) {
|
||||
evaluateString("(let (a))")
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun letWithTooFewItemsInPair() {
|
||||
assertThrows(TooFewArgumentsException::class.java) {
|
||||
evaluateString("(let (()))")
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun letWithTooManyItemsInPair() {
|
||||
assertThrows(TooManyArgumentsException::class.java) {
|
||||
evaluateString("(let ((a b c)))")
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun letWithNonSymbolInPair() {
|
||||
assertThrows(BadArgumentTypeException::class.java) {
|
||||
evaluateString("(let ((1 b)))")
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun letWithTooFewArguments() {
|
||||
assertThrows(TooFewArgumentsException::class.java) {
|
||||
evaluateString("(let)")
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun letWithDottedArgumentList() {
|
||||
assertThrows(DottedArgumentListException::class.java) {
|
||||
evaluateString("(apply 'let (cons 'a 'b))")
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun letWithDottedPairList() {
|
||||
assertThrows(DottedArgumentListException::class.java) {
|
||||
evaluateString("(apply 'let (cons (cons 'a 'b) nil))")
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun letWithDottedPair() {
|
||||
assertThrows(DottedArgumentListException::class.java) {
|
||||
evaluateString("(apply 'let (cons (cons (cons 'a 'b) nil) nil))")
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun letEvaluatesSymbolsInParallel() {
|
||||
val input = "(let ((x 1) (y (+ x 1))) (+ x y))"
|
||||
|
||||
assertThrows(UndefinedSymbolException::class.java) {
|
||||
assertSExpressionsMatch(LispNumber("2"), evaluateString(input))
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue