Refactored tests to put the expected and actual values in the correct positions

This commit is contained in:
Mike Cifelli 2017-01-27 10:51:25 -05:00
parent 32db0b2520
commit fe880e1a02
25 changed files with 105 additions and 104 deletions

View File

@ -13,21 +13,21 @@ public class APPLYTester {
public void testApply() { public void testApply() {
String input = "(apply '+ '(1 2 3))"; String input = "(apply '+ '(1 2 3))";
assertSExpressionsMatch(evaluateString(input), parseString("6")); assertSExpressionsMatch(parseString("6"), evaluateString(input));
} }
@Test @Test
public void testApplyWithLambdaExpression() { public void testApplyWithLambdaExpression() {
String input = "(apply (lambda (x) (+ x 1)) '(25))"; String input = "(apply (lambda (x) (+ x 1)) '(25))";
assertSExpressionsMatch(evaluateString(input), parseString("26")); assertSExpressionsMatch(parseString("26"), evaluateString(input));
} }
@Test @Test
public void testApplyWithQuotedLambdaExpression() { public void testApplyWithQuotedLambdaExpression() {
String input = "(apply '(lambda (x) (+ x 1)) '(25))"; String input = "(apply '(lambda (x) (+ x 1)) '(25))";
assertSExpressionsMatch(evaluateString(input), parseString("26")); assertSExpressionsMatch(parseString("26"), evaluateString(input));
} }
@Test @Test
@ -35,7 +35,7 @@ public class APPLYTester {
String argumentList = "(+ (25 10))"; String argumentList = "(+ (25 10))";
Cons parsedArgumentList = (Cons) parseString(argumentList); Cons parsedArgumentList = (Cons) parseString(argumentList);
assertSExpressionsMatch(APPLY.apply(parsedArgumentList), parseString("35")); assertSExpressionsMatch(parseString("35"), APPLY.apply(parsedArgumentList));
} }
@Test(expected = RuntimeException.class) @Test(expected = RuntimeException.class)

View File

@ -15,26 +15,26 @@ public class EVALTester {
public void testEval() { public void testEval() {
String input = "(eval 9)"; String input = "(eval 9)";
assertSExpressionsMatch(evaluateString(input), parseString("9")); assertSExpressionsMatch(parseString("9"), evaluateString(input));
} }
@Test @Test
public void testEvalNil() { public void testEvalNil() {
String input = "(eval ())"; String input = "(eval ())";
assertSExpressionsMatch(evaluateString(input), parseString("()")); assertSExpressionsMatch(parseString("()"), evaluateString(input));
} }
@Test @Test
public void testLookupSymbol() { public void testLookupSymbol() {
String symbol = ":symbol"; String symbol = ":symbol";
assertSExpressionsMatch(EVAL.lookupSymbol(symbol), parseString(symbol)); assertSExpressionsMatch(parseString(symbol), EVAL.lookupSymbol(symbol));
} }
@Test @Test
public void testLookupT() { public void testLookupT() {
String symbol = "T"; String symbol = "T";
assertSExpressionsMatch(EVAL.lookupSymbol(symbol), parseString(symbol)); assertSExpressionsMatch(parseString(symbol), EVAL.lookupSymbol(symbol));
} }
@Test @Test

View File

@ -12,7 +12,7 @@ public class FUNCALLTester {
public void testFuncallWithNumbers() { public void testFuncallWithNumbers() {
String input = "(funcall '+ 1 2 3)"; String input = "(funcall '+ 1 2 3)";
assertSExpressionsMatch(evaluateString(input), parseString("6")); assertSExpressionsMatch(parseString("6"), evaluateString(input));
} }
@Test @Test
@ -21,7 +21,7 @@ public class FUNCALLTester {
String input = "(funcall 'x 2 30)"; String input = "(funcall 'x 2 30)";
evaluateString(defineUserFunction); evaluateString(defineUserFunction);
assertSExpressionsMatch(evaluateString(input), parseString("32")); assertSExpressionsMatch(parseString("32"), evaluateString(input));
} }
@Test(expected = TooFewArgumentsException.class) @Test(expected = TooFewArgumentsException.class)

View File

@ -9,6 +9,7 @@ import org.junit.*;
import environment.Environment; import environment.Environment;
import function.ArgumentValidator.*; import function.ArgumentValidator.*;
import sexpression.*;
public class LOADTester { public class LOADTester {
@ -32,7 +33,7 @@ public class LOADTester {
public void loadGoodFile_ReturnsTAndPrintsNothing() { public void loadGoodFile_ReturnsTAndPrintsNothing() {
String input = "(load \"test/function/builtin/test-files/load-good.lisp\")"; String input = "(load \"test/function/builtin/test-files/load-good.lisp\")";
assertSExpressionsMatch(parseString("T"), evaluateString(input)); assertSExpressionsMatch(Symbol.T, evaluateString(input));
assertNothingPrinted(); assertNothingPrinted();
} }
@ -40,7 +41,7 @@ public class LOADTester {
public void loadBadFile_ReturnsNilAndPrintsError() { public void loadBadFile_ReturnsNilAndPrintsError() {
String input = "(load \"test/function/builtin/test-files/load-bad.lisp\")"; String input = "(load \"test/function/builtin/test-files/load-bad.lisp\")";
assertSExpressionsMatch(parseString("nil"), evaluateString(input)); assertSExpressionsMatch(Nil.getInstance(), evaluateString(input));
assertPrinted("LOAD: expression begins with ')' - line 1, column 1\n"); assertPrinted("LOAD: expression begins with ')' - line 1, column 1\n");
} }
@ -48,7 +49,7 @@ public class LOADTester {
public void loadNonExistentFile_ReturnsNilAndPrintsError() { public void loadNonExistentFile_ReturnsNilAndPrintsError() {
String input = "(load \"doesNotExist.lisp\")"; String input = "(load \"doesNotExist.lisp\")";
assertSExpressionsMatch(parseString("nil"), evaluateString(input)); assertSExpressionsMatch(Nil.getInstance(), evaluateString(input));
assertPrinted("LOAD: could not open 'doesNotExist.lisp'\n"); assertPrinted("LOAD: could not open 'doesNotExist.lisp'\n");
} }

View File

@ -12,21 +12,21 @@ public class CARTester {
public void testCarWithNil() { public void testCarWithNil() {
String input = "(car nil)"; String input = "(car nil)";
assertSExpressionsMatch(evaluateString(input), parseString("()")); assertSExpressionsMatch(parseString("()"), evaluateString(input));
} }
@Test @Test
public void testCarWithList() { public void testCarWithList() {
String input = "(car '(1 2 3))"; String input = "(car '(1 2 3))";
assertSExpressionsMatch(evaluateString(input), parseString("1")); assertSExpressionsMatch(parseString("1"), evaluateString(input));
} }
@Test @Test
public void testNestedCarWithList() { public void testNestedCarWithList() {
String input = "(car (car '((1 2) 3)))"; String input = "(car (car '((1 2) 3)))";
assertSExpressionsMatch(evaluateString(input), parseString("1")); assertSExpressionsMatch(parseString("1"), evaluateString(input));
} }
@Test(expected = BadArgumentTypeException.class) @Test(expected = BadArgumentTypeException.class)

View File

@ -12,21 +12,21 @@ public class CDRTester {
public void testCdrWithNil() { public void testCdrWithNil() {
String input = "(cdr nil)"; String input = "(cdr nil)";
assertSExpressionsMatch(evaluateString(input), parseString("()")); assertSExpressionsMatch(parseString("()"), evaluateString(input));
} }
@Test @Test
public void testCdrWithList() { public void testCdrWithList() {
String input = "(cdr '(1 2 3))"; String input = "(cdr '(1 2 3))";
assertSExpressionsMatch(evaluateString(input), parseString("(2 3)")); assertSExpressionsMatch(parseString("(2 3)"), evaluateString(input));
} }
@Test @Test
public void testNestedCdrWithList() { public void testNestedCdrWithList() {
String input = "(cdr (cdr '(1 2 3)))"; String input = "(cdr (cdr '(1 2 3)))";
assertSExpressionsMatch(evaluateString(input), parseString("(3)")); assertSExpressionsMatch(parseString("(3)"), evaluateString(input));
} }
@Test(expected = BadArgumentTypeException.class) @Test(expected = BadArgumentTypeException.class)

View File

@ -13,27 +13,27 @@ public class CONSTester {
public void testConsWithNilValues() { public void testConsWithNilValues() {
String input = "(cons () nil)"; String input = "(cons () nil)";
assertSExpressionsMatch(evaluateString(input), parseString("(())")); assertSExpressionsMatch(parseString("(())"), evaluateString(input));
} }
@Test @Test
public void testConsWithTwoSymbols() { public void testConsWithTwoSymbols() {
String input = "(cons 'a 'b)"; String input = "(cons 'a 'b)";
assertSExpressionsMatch(evaluateString(input), new Cons(new Symbol("A"), new Symbol("B"))); assertSExpressionsMatch(new Cons(new Symbol("A"), new Symbol("B")), evaluateString(input));
} }
@Test @Test
public void testConsWithListAsCdr() { public void testConsWithListAsCdr() {
String input = "(cons 1 '(2 3))"; String input = "(cons 1 '(2 3))";
assertSExpressionsMatch(evaluateString(input), parseString("(1 2 3)")); assertSExpressionsMatch(parseString("(1 2 3)"), evaluateString(input));
} }
@Test @Test
public void testConsWithTwoLists() { public void testConsWithTwoLists() {
String input = "(cons '(1 2) '(3 4))"; String input = "(cons '(1 2) '(3 4))";
assertSExpressionsMatch(evaluateString(input), parseString("((1 2) 3 4)")); assertSExpressionsMatch(parseString("((1 2) 3 4)"), evaluateString(input));
} }
@ -41,7 +41,7 @@ public class CONSTester {
public void testConsWithList() { public void testConsWithList() {
String input = "(cons nil '(2 3))"; String input = "(cons nil '(2 3))";
assertSExpressionsMatch(evaluateString(input), parseString("(nil 2 3)")); assertSExpressionsMatch(parseString("(nil 2 3)"), evaluateString(input));
} }
@Test(expected = TooManyArgumentsException.class) @Test(expected = TooManyArgumentsException.class)

View File

@ -12,21 +12,21 @@ public class LENGTHTester {
public void testLengthOfNil() { public void testLengthOfNil() {
String input = "(length '())"; String input = "(length '())";
assertSExpressionsMatch(evaluateString(input), parseString("0")); assertSExpressionsMatch(parseString("0"), evaluateString(input));
} }
@Test @Test
public void testLengthOfListOfOneElement() { public void testLengthOfListOfOneElement() {
String input = "(length '(1))"; String input = "(length '(1))";
assertSExpressionsMatch(evaluateString(input), parseString("1")); assertSExpressionsMatch(parseString("1"), evaluateString(input));
} }
@Test @Test
public void testLengthOfListOfManyElements() { public void testLengthOfListOfManyElements() {
String input = "(length '(1 2 3 4 5))"; String input = "(length '(1 2 3 4 5))";
assertSExpressionsMatch(evaluateString(input), parseString("5")); assertSExpressionsMatch(parseString("5"), evaluateString(input));
} }
@Test(expected = BadArgumentTypeException.class) @Test(expected = BadArgumentTypeException.class)

View File

@ -10,47 +10,47 @@ public class LISTTester {
public void testListWithNoArguments() { public void testListWithNoArguments() {
String input = "(list)"; String input = "(list)";
assertSExpressionsMatch(evaluateString(input), parseString("nil")); assertSExpressionsMatch(parseString("nil"), evaluateString(input));
} }
@Test @Test
public void testListWithOneArgument() { public void testListWithOneArgument() {
String input = "(list 1)"; String input = "(list 1)";
assertSExpressionsMatch(evaluateString(input), parseString("(1)")); assertSExpressionsMatch(parseString("(1)"), evaluateString(input));
} }
@Test @Test
public void testListWithTwoArguments() { public void testListWithTwoArguments() {
String input = "(list 2 3)"; String input = "(list 2 3)";
assertSExpressionsMatch(evaluateString(input), parseString("(2 3)")); assertSExpressionsMatch(parseString("(2 3)"), evaluateString(input));
} }
@Test @Test
public void testListWithManyArguments() { public void testListWithManyArguments() {
String input = "(list 'm 'a 'n 'y 'a 'r 'g 's)"; String input = "(list 'm 'a 'n 'y 'a 'r 'g 's)";
assertSExpressionsMatch(evaluateString(input), parseString("(m a n y a r g s)")); assertSExpressionsMatch(parseString("(m a n y a r g s)"), evaluateString(input));
} }
@Test @Test
public void testListWithOneListArgument() { public void testListWithOneListArgument() {
String input = "(list '(1))"; String input = "(list '(1))";
assertSExpressionsMatch(evaluateString(input), parseString("((1))")); assertSExpressionsMatch(parseString("((1))"), evaluateString(input));
} }
@Test @Test
public void testListWithManyListArguments() { public void testListWithManyListArguments() {
String input = "(list '(1) '(2 3) ())"; String input = "(list '(1) '(2 3) ())";
assertSExpressionsMatch(evaluateString(input), parseString("((1) (2 3) ())")); assertSExpressionsMatch(parseString("((1) (2 3) ())"), evaluateString(input));
} }
@Test @Test
public void testMakeList() { public void testMakeList() {
assertSExpressionsMatch(LIST.makeList(parseString("22")), parseString("(22)")); assertSExpressionsMatch(parseString("(22)"), LIST.makeList(parseString("22")));
} }
} }

View File

@ -12,42 +12,42 @@ public class DIVIDETester {
public void testDivideWithOne() { public void testDivideWithOne() {
String input = "(/ 1)"; String input = "(/ 1)";
assertSExpressionsMatch(evaluateString(input), parseString("1")); assertSExpressionsMatch(parseString("1"), evaluateString(input));
} }
@Test @Test
public void testDivideWithTwo() { public void testDivideWithTwo() {
String input = "(/ 2)"; String input = "(/ 2)";
assertSExpressionsMatch(evaluateString(input), parseString("0")); assertSExpressionsMatch(parseString("0"), evaluateString(input));
} }
@Test @Test
public void testDivideTwoNumbers() { public void testDivideTwoNumbers() {
String input = "(/ 24 3)"; String input = "(/ 24 3)";
assertSExpressionsMatch(evaluateString(input), parseString("8")); assertSExpressionsMatch(parseString("8"), evaluateString(input));
} }
@Test @Test
public void testDivideSeveralNumbers() { public void testDivideSeveralNumbers() {
String input = "(/ 256 2 2 8)"; String input = "(/ 256 2 2 8)";
assertSExpressionsMatch(evaluateString(input), parseString("8")); assertSExpressionsMatch(parseString("8"), evaluateString(input));
} }
@Test @Test
public void testDivideTwoNumbersWithRemainder() { public void testDivideTwoNumbersWithRemainder() {
String input = "(/ 9 2)"; String input = "(/ 9 2)";
assertSExpressionsMatch(evaluateString(input), parseString("4")); assertSExpressionsMatch(parseString("4"), evaluateString(input));
} }
@Test @Test
public void testDivideSeveralNumbersWithRemainder() { public void testDivideSeveralNumbersWithRemainder() {
String input = "(/ 19 2 5)"; String input = "(/ 19 2 5)";
assertSExpressionsMatch(evaluateString(input), parseString("1")); assertSExpressionsMatch(parseString("1"), evaluateString(input));
} }
@Test(expected = BadArgumentTypeException.class) @Test(expected = BadArgumentTypeException.class)

View File

@ -13,28 +13,28 @@ public class MINUSTester {
public void testMinusWithOneNumber() { public void testMinusWithOneNumber() {
String input = "(- 27)"; String input = "(- 27)";
assertSExpressionsMatch(evaluateString(input), new LispNumber("-27")); assertSExpressionsMatch(new LispNumber("-27"), evaluateString(input));
} }
@Test @Test
public void testMinusWithTwoNumbers() { public void testMinusWithTwoNumbers() {
String input = "(- 5 3)"; String input = "(- 5 3)";
assertSExpressionsMatch(evaluateString(input), new LispNumber("2")); assertSExpressionsMatch(new LispNumber("2"), evaluateString(input));
} }
@Test @Test
public void testMinusWithManyNumbers_PositiveResult() { public void testMinusWithManyNumbers_PositiveResult() {
String input = "(- 200 100 10 5)"; String input = "(- 200 100 10 5)";
assertSExpressionsMatch(evaluateString(input), new LispNumber("85")); assertSExpressionsMatch(new LispNumber("85"), evaluateString(input));
} }
@Test @Test
public void testMinusWithManyNumbers_NegativeResult() { public void testMinusWithManyNumbers_NegativeResult() {
String input = "(- 100 200 20 5)"; String input = "(- 100 200 20 5)";
assertSExpressionsMatch(evaluateString(input), new LispNumber("-125")); assertSExpressionsMatch(new LispNumber("-125"), evaluateString(input));
} }
@Test(expected = BadArgumentTypeException.class) @Test(expected = BadArgumentTypeException.class)

View File

@ -13,35 +13,35 @@ public class MULTIPLYTester {
public void testMultiplyWithNoArguments() { public void testMultiplyWithNoArguments() {
String input = "(*)"; String input = "(*)";
assertSExpressionsMatch(evaluateString(input), new LispNumber("1")); assertSExpressionsMatch(new LispNumber("1"), evaluateString(input));
} }
@Test @Test
public void testMultiplyWithOneNumber() { public void testMultiplyWithOneNumber() {
String input = "(* 8)"; String input = "(* 8)";
assertSExpressionsMatch(evaluateString(input), new LispNumber("8")); assertSExpressionsMatch(new LispNumber("8"), evaluateString(input));
} }
@Test @Test
public void testMultiplyWithTwoNumbers() { public void testMultiplyWithTwoNumbers() {
String input = "(* 5 3)"; String input = "(* 5 3)";
assertSExpressionsMatch(evaluateString(input), new LispNumber("15")); assertSExpressionsMatch(new LispNumber("15"), evaluateString(input));
} }
@Test @Test
public void testMultiplyWithManyNumbers_PositiveResult() { public void testMultiplyWithManyNumbers_PositiveResult() {
String input = "(* 2 3 5 1)"; String input = "(* 2 3 5 1)";
assertSExpressionsMatch(evaluateString(input), new LispNumber("30")); assertSExpressionsMatch(new LispNumber("30"), evaluateString(input));
} }
@Test @Test
public void testMultiplyWithManyNumbers_NegativeResult() { public void testMultiplyWithManyNumbers_NegativeResult() {
String input = "(* 3 (- 2) 10 2)"; String input = "(* 3 (- 2) 10 2)";
assertSExpressionsMatch(evaluateString(input), new LispNumber("-120")); assertSExpressionsMatch(new LispNumber("-120"), evaluateString(input));
} }
@Test(expected = BadArgumentTypeException.class) @Test(expected = BadArgumentTypeException.class)

View File

@ -13,35 +13,35 @@ public class PLUSTester {
public void testPlusWithNoArguments() { public void testPlusWithNoArguments() {
String input = "(+)"; String input = "(+)";
assertSExpressionsMatch(evaluateString(input), new LispNumber("0")); assertSExpressionsMatch(new LispNumber("0"), evaluateString(input));
} }
@Test @Test
public void testPlusWithOneNumber() { public void testPlusWithOneNumber() {
String input = "(+ 27)"; String input = "(+ 27)";
assertSExpressionsMatch(evaluateString(input), new LispNumber("27")); assertSExpressionsMatch(new LispNumber("27"), evaluateString(input));
} }
@Test @Test
public void testPlusWithTwoNumbers() { public void testPlusWithTwoNumbers() {
String input = "(+ 5 3)"; String input = "(+ 5 3)";
assertSExpressionsMatch(evaluateString(input), new LispNumber("8")); assertSExpressionsMatch(new LispNumber("8"), evaluateString(input));
} }
@Test @Test
public void testPlusWithManyNumbers_PositiveResult() { public void testPlusWithManyNumbers_PositiveResult() {
String input = "(+ 200 100 10 5)"; String input = "(+ 200 100 10 5)";
assertSExpressionsMatch(evaluateString(input), new LispNumber("315")); assertSExpressionsMatch(new LispNumber("315"), evaluateString(input));
} }
@Test @Test
public void testPlusWithManyNumbers_NegativeResult() { public void testPlusWithManyNumbers_NegativeResult() {
String input = "(+ 100 (- 200) 20 5)"; String input = "(+ 100 (- 200) 20 5)";
assertSExpressionsMatch(evaluateString(input), new LispNumber("-75")); assertSExpressionsMatch(new LispNumber("-75"), evaluateString(input));
} }
@Test(expected = BadArgumentTypeException.class) @Test(expected = BadArgumentTypeException.class)

View File

@ -12,14 +12,14 @@ public class ATOMTester {
public void testAtom_ReturnsTrue() { public void testAtom_ReturnsTrue() {
String input = "(atom 'a)"; String input = "(atom 'a)";
assertSExpressionsMatch(evaluateString(input), parseString("T")); assertSExpressionsMatch(parseString("T"), evaluateString(input));
} }
@Test @Test
public void testAtom_ReturnsFalse() { public void testAtom_ReturnsFalse() {
String input = "(atom '(1 2 3))"; String input = "(atom '(1 2 3))";
assertSExpressionsMatch(evaluateString(input), parseString("()")); assertSExpressionsMatch(parseString("()"), evaluateString(input));
} }
@Test(expected = TooManyArgumentsException.class) @Test(expected = TooManyArgumentsException.class)

View File

@ -12,20 +12,20 @@ public class EQTester {
public void testEqWithEqualAtoms() { public void testEqWithEqualAtoms() {
String input = "(eq 1 1)"; String input = "(eq 1 1)";
assertSExpressionsMatch(evaluateString(input), parseString("t")); assertSExpressionsMatch(parseString("t"), evaluateString(input));
} }
@Test @Test
public void testEqWithUnequalAtoms() { public void testEqWithUnequalAtoms() {
String input = "(eq 1 2)"; String input = "(eq 1 2)";
assertSExpressionsMatch(evaluateString(input), parseString("nil")); assertSExpressionsMatch(parseString("nil"), evaluateString(input));
} }
@Test @Test
public void testEqWithAtomAndList() { public void testEqWithAtomAndList() {
String input = "(eq 1 '(2))"; String input = "(eq 1 '(2))";
assertSExpressionsMatch(evaluateString(input), parseString("nil")); assertSExpressionsMatch(parseString("nil"), evaluateString(input));
} }
@Test @Test
@ -37,21 +37,21 @@ public class EQTester {
evaluateString(initializeL1); evaluateString(initializeL1);
evaluateString(initializeL2); evaluateString(initializeL2);
assertSExpressionsMatch(evaluateString(input), parseString("t")); assertSExpressionsMatch(parseString("t"), evaluateString(input));
} }
@Test @Test
public void testEqWithEqualLists() { public void testEqWithEqualLists() {
String input = "(eq '(1 2) '(1 2))"; String input = "(eq '(1 2) '(1 2))";
assertSExpressionsMatch(evaluateString(input), parseString("nil")); assertSExpressionsMatch(parseString("nil"), evaluateString(input));
} }
@Test @Test
public void testEqWithUnequalLists() { public void testEqWithUnequalLists() {
String input = "(eq '(1 2) '(3 4))"; String input = "(eq '(1 2) '(3 4))";
assertSExpressionsMatch(evaluateString(input), parseString("nil")); assertSExpressionsMatch(parseString("nil"), evaluateString(input));
} }
@Test(expected = TooManyArgumentsException.class) @Test(expected = TooManyArgumentsException.class)

View File

@ -12,35 +12,35 @@ public class EQUALSPTester {
public void testEqualspWithOneNumber() { public void testEqualspWithOneNumber() {
String input = "(= 1)"; String input = "(= 1)";
assertSExpressionsMatch(evaluateString(input), parseString("t")); assertSExpressionsMatch(parseString("t"), evaluateString(input));
} }
@Test @Test
public void testEqualspWithEqualNumbers() { public void testEqualspWithEqualNumbers() {
String input = "(= 1 1)"; String input = "(= 1 1)";
assertSExpressionsMatch(evaluateString(input), parseString("t")); assertSExpressionsMatch(parseString("t"), evaluateString(input));
} }
@Test @Test
public void testEqualspWithNonEqualNumbers() { public void testEqualspWithNonEqualNumbers() {
String input = "(= 1 2)"; String input = "(= 1 2)";
assertSExpressionsMatch(evaluateString(input), parseString("nil")); assertSExpressionsMatch(parseString("nil"), evaluateString(input));
} }
@Test @Test
public void testEqualspWithManyEqualNumbers() { public void testEqualspWithManyEqualNumbers() {
String input = "(= 4 4 4 4 4 4 4 4 4 4)"; String input = "(= 4 4 4 4 4 4 4 4 4 4)";
assertSExpressionsMatch(evaluateString(input), parseString("t")); assertSExpressionsMatch(parseString("t"), evaluateString(input));
} }
@Test @Test
public void testEqualspWithManyNonEqualNumbers() { public void testEqualspWithManyNonEqualNumbers() {
String input = "(= 4 4 4 4 5 4 4 4 4 4)"; String input = "(= 4 4 4 4 5 4 4 4 4 4)";
assertSExpressionsMatch(evaluateString(input), parseString("nil")); assertSExpressionsMatch(parseString("nil"), evaluateString(input));
} }
@Test(expected = BadArgumentTypeException.class) @Test(expected = BadArgumentTypeException.class)

View File

@ -12,49 +12,49 @@ public class EQUALTester {
public void testEqualWithTwoEqualAtoms() { public void testEqualWithTwoEqualAtoms() {
String input = "(equal 'a 'a)"; String input = "(equal 'a 'a)";
assertSExpressionsMatch(evaluateString(input), parseString("t")); assertSExpressionsMatch(parseString("t"), evaluateString(input));
} }
@Test @Test
public void testEqualWithTwoUnequalAtoms() { public void testEqualWithTwoUnequalAtoms() {
String input = "(equal 'a 'b)"; String input = "(equal 'a 'b)";
assertSExpressionsMatch(evaluateString(input), parseString("nil")); assertSExpressionsMatch(parseString("nil"), evaluateString(input));
} }
@Test @Test
public void testEqualWithAtomAndList() { public void testEqualWithAtomAndList() {
String input = "(equal \"string\" '(m i k e))"; String input = "(equal \"string\" '(m i k e))";
assertSExpressionsMatch(evaluateString(input), parseString("nil")); assertSExpressionsMatch(parseString("nil"), evaluateString(input));
} }
@Test @Test
public void testEqualWithListAndAtom() { public void testEqualWithListAndAtom() {
String input = "(equal '(m i k e) \"string\")"; String input = "(equal '(m i k e) \"string\")";
assertSExpressionsMatch(evaluateString(input), parseString("nil")); assertSExpressionsMatch(parseString("nil"), evaluateString(input));
} }
@Test @Test
public void testEqualWithTwoEqualLists() { public void testEqualWithTwoEqualLists() {
String input = "(equal '(1 2 3) '(1 2 3))"; String input = "(equal '(1 2 3) '(1 2 3))";
assertSExpressionsMatch(evaluateString(input), parseString("t")); assertSExpressionsMatch(parseString("t"), evaluateString(input));
} }
@Test @Test
public void testEqualWithTwoUnequalLists() { public void testEqualWithTwoUnequalLists() {
String input = "(equal '(1 2 3) '(1 3 3))"; String input = "(equal '(1 2 3) '(1 3 3))";
assertSExpressionsMatch(evaluateString(input), parseString("nil")); assertSExpressionsMatch(parseString("nil"), evaluateString(input));
} }
@Test @Test
public void testEqualWithTwoEqualNestedLists() { public void testEqualWithTwoEqualNestedLists() {
String input = "(equal '(1 ((2) 3)) '(1 ((2) 3)))"; String input = "(equal '(1 ((2) 3)) '(1 ((2) 3)))";
assertSExpressionsMatch(evaluateString(input), parseString("t")); assertSExpressionsMatch(parseString("t"), evaluateString(input));
} }
@Test(expected = TooManyArgumentsException.class) @Test(expected = TooManyArgumentsException.class)

View File

@ -12,35 +12,35 @@ public class GREATERPTester {
public void testGreaterpWithOneNumber_ReturnsT() { public void testGreaterpWithOneNumber_ReturnsT() {
String input = "(> 1)"; String input = "(> 1)";
assertSExpressionsMatch(evaluateString(input), parseString("t")); assertSExpressionsMatch(parseString("t"), evaluateString(input));
} }
@Test @Test
public void testGreaterpWithTwoNumbers_ReturnsNil() { public void testGreaterpWithTwoNumbers_ReturnsNil() {
String input = "(> 1 2)"; String input = "(> 1 2)";
assertSExpressionsMatch(evaluateString(input), parseString("nil")); assertSExpressionsMatch(parseString("nil"), evaluateString(input));
} }
@Test @Test
public void testGreaterpWithTwoNumbers_ReturnsT() { public void testGreaterpWithTwoNumbers_ReturnsT() {
String input = "(> 3 2)"; String input = "(> 3 2)";
assertSExpressionsMatch(evaluateString(input), parseString("t")); assertSExpressionsMatch(parseString("t"), evaluateString(input));
} }
@Test @Test
public void testGreaterpWithManyNumbers_ReturnsNil() { public void testGreaterpWithManyNumbers_ReturnsNil() {
String input = "(> 4 3 2 5 1)"; String input = "(> 4 3 2 5 1)";
assertSExpressionsMatch(evaluateString(input), parseString("nil")); assertSExpressionsMatch(parseString("nil"), evaluateString(input));
} }
@Test @Test
public void testGreaterpWithManyNumbers_ReturnsT() { public void testGreaterpWithManyNumbers_ReturnsT() {
String input = "(> 4 3 2 1 0)"; String input = "(> 4 3 2 1 0)";
assertSExpressionsMatch(evaluateString(input), parseString("t")); assertSExpressionsMatch(parseString("t"), evaluateString(input));
} }
@Test(expected = BadArgumentTypeException.class) @Test(expected = BadArgumentTypeException.class)

View File

@ -12,35 +12,35 @@ public class LESSPTester {
public void testLesspWithOneNumber_ReturnsT() { public void testLesspWithOneNumber_ReturnsT() {
String input = "(< 1)"; String input = "(< 1)";
assertSExpressionsMatch(evaluateString(input), parseString("t")); assertSExpressionsMatch(parseString("t"), evaluateString(input));
} }
@Test @Test
public void testLesspWithTwoNumbers_ReturnsNil() { public void testLesspWithTwoNumbers_ReturnsNil() {
String input = "(< 2 1)"; String input = "(< 2 1)";
assertSExpressionsMatch(evaluateString(input), parseString("nil")); assertSExpressionsMatch(parseString("nil"), evaluateString(input));
} }
@Test @Test
public void testLesspWithTwoNumbers_ReturnsT() { public void testLesspWithTwoNumbers_ReturnsT() {
String input = "(< 2 3)"; String input = "(< 2 3)";
assertSExpressionsMatch(evaluateString(input), parseString("t")); assertSExpressionsMatch(parseString("t"), evaluateString(input));
} }
@Test @Test
public void testLesspWithManyNumbers_ReturnsNil() { public void testLesspWithManyNumbers_ReturnsNil() {
String input = "(< 4 3 2 5 1)"; String input = "(< 4 3 2 5 1)";
assertSExpressionsMatch(evaluateString(input), parseString("nil")); assertSExpressionsMatch(parseString("nil"), evaluateString(input));
} }
@Test @Test
public void testLesspWithManyNumbers_ReturnsT() { public void testLesspWithManyNumbers_ReturnsT() {
String input = "(< 0 1 2 3 4)"; String input = "(< 0 1 2 3 4)";
assertSExpressionsMatch(evaluateString(input), parseString("t")); assertSExpressionsMatch(parseString("t"), evaluateString(input));
} }
@Test(expected = BadArgumentTypeException.class) @Test(expected = BadArgumentTypeException.class)

View File

@ -12,14 +12,14 @@ public class LISTPTester {
public void testListpWithList_ReturnsT() { public void testListpWithList_ReturnsT() {
String input = "(listp '(1))"; String input = "(listp '(1))";
assertSExpressionsMatch(evaluateString(input), parseString("T")); assertSExpressionsMatch(parseString("T"), evaluateString(input));
} }
@Test @Test
public void testListWithNonList_ReturnsNil() { public void testListWithNonList_ReturnsNil() {
String input = "(listp 1)"; String input = "(listp 1)";
assertSExpressionsMatch(evaluateString(input), parseString("NIL")); assertSExpressionsMatch(parseString("NIL"), evaluateString(input));
} }
@Test(expected = TooFewArgumentsException.class) @Test(expected = TooFewArgumentsException.class)

View File

@ -12,14 +12,14 @@ public class NULLTester {
public void testNilIsNull() { public void testNilIsNull() {
String input = "(null ())"; String input = "(null ())";
assertSExpressionsMatch(evaluateString(input), parseString("T")); assertSExpressionsMatch(parseString("T"), evaluateString(input));
} }
@Test @Test
public void testListIsNotNull() { public void testListIsNotNull() {
String input = "(null '(1))"; String input = "(null '(1))";
assertSExpressionsMatch(evaluateString(input), parseString("NIL")); assertSExpressionsMatch(parseString("NIL"), evaluateString(input));
} }
@Test(expected = TooFewArgumentsException.class) @Test(expected = TooFewArgumentsException.class)

View File

@ -12,56 +12,56 @@ public class CONDTester {
public void testCondWithNoArguments() { public void testCondWithNoArguments() {
String input = "(cond)"; String input = "(cond)";
assertSExpressionsMatch(evaluateString(input), parseString("nil")); assertSExpressionsMatch(parseString("nil"), evaluateString(input));
} }
@Test @Test
public void testCondWithTrue() { public void testCondWithTrue() {
String input = "(cond (T))"; String input = "(cond (T))";
assertSExpressionsMatch(evaluateString(input), parseString("T")); assertSExpressionsMatch(parseString("T"), evaluateString(input));
} }
@Test @Test
public void testCondWithSingleExpression() { public void testCondWithSingleExpression() {
String input = "(cond (T \"true\"))"; String input = "(cond (T \"true\"))";
assertSExpressionsMatch(evaluateString(input), parseString("\"true\"")); assertSExpressionsMatch(parseString("\"true\""), evaluateString(input));
} }
@Test @Test
public void testCondWithMultipleExpressions() { public void testCondWithMultipleExpressions() {
String input = "(cond ((= 1 2) 2) ((= 1 2) 2) ((= 1 1) 3))"; String input = "(cond ((= 1 2) 2) ((= 1 2) 2) ((= 1 1) 3))";
assertSExpressionsMatch(evaluateString(input), parseString("3")); assertSExpressionsMatch(parseString("3"), evaluateString(input));
} }
@Test @Test
public void testCondWithMultipleConditionsMatching_ReturnFirstOne() { public void testCondWithMultipleConditionsMatching_ReturnFirstOne() {
String input = "(cond ((= 1 1) 2) ((= 1 1) 3))"; String input = "(cond ((= 1 1) 2) ((= 1 1) 3))";
assertSExpressionsMatch(evaluateString(input), parseString("2")); assertSExpressionsMatch(parseString("2"), evaluateString(input));
} }
@Test @Test
public void testCondWithMultipleConditionsMatching_OnlyEvaluatesFirstOne() { public void testCondWithMultipleConditionsMatching_OnlyEvaluatesFirstOne() {
String input = "(cond ((= 1 1) 2) ((= 1 1) x))"; String input = "(cond ((= 1 1) 2) ((= 1 1) x))";
assertSExpressionsMatch(evaluateString(input), parseString("2")); assertSExpressionsMatch(parseString("2"), evaluateString(input));
} }
@Test @Test
public void testCondWithMultipleResultValues_OnlyReturnsLast() { public void testCondWithMultipleResultValues_OnlyReturnsLast() {
String input = "(cond ((= 1 1) 2 3 4))"; String input = "(cond ((= 1 1) 2 3 4))";
assertSExpressionsMatch(evaluateString(input), parseString("4")); assertSExpressionsMatch(parseString("4"), evaluateString(input));
} }
@Test @Test
public void testCondWithNoConditionMatching_ReturnsNil() { public void testCondWithNoConditionMatching_ReturnsNil() {
String input = "(cond ((= 1 2) T) ((= 1 3) T))"; String input = "(cond ((= 1 2) T) ((= 1 3) T))";
assertSExpressionsMatch(evaluateString(input), parseString("nil")); assertSExpressionsMatch(parseString("nil"), evaluateString(input));
} }
@Test(expected = BadArgumentTypeException.class) @Test(expected = BadArgumentTypeException.class)

View File

@ -12,8 +12,8 @@ public class DEFUNTester {
public void testDefun() { public void testDefun() {
String input = "(defun f () nil)"; String input = "(defun f () nil)";
assertSExpressionsMatch(evaluateString(input), parseString("f")); assertSExpressionsMatch(parseString("f"), evaluateString(input));
assertSExpressionsMatch(evaluateString("(f)"), parseString("()")); assertSExpressionsMatch(parseString("()"), evaluateString("(f)"));
} }
@Test(expected = DottedArgumentListException.class) @Test(expected = DottedArgumentListException.class)

View File

@ -12,14 +12,14 @@ public class QUOTETester {
public void testQuoteSymbol() { public void testQuoteSymbol() {
String input = "'a"; String input = "'a";
assertSExpressionsMatch(evaluateString(input), parseString("a")); assertSExpressionsMatch(parseString("a"), evaluateString(input));
} }
@Test @Test
public void testQuoteList() { public void testQuoteList() {
String input = "'(l i s t)"; String input = "'(l i s t)";
assertSExpressionsMatch(evaluateString(input), parseString("(l i s t)")); assertSExpressionsMatch(parseString("(l i s t)"), evaluateString(input));
} }
@Test(expected = TooFewArgumentsException.class) @Test(expected = TooFewArgumentsException.class)

View File

@ -20,13 +20,13 @@ public class SETFTester {
@Test @Test
public void testSetf() { public void testSetf() {
evaluateString("(setf a 23)"); evaluateString("(setf a 23)");
assertSExpressionsMatch(evaluateString("23"), evaluateString("a")); assertSExpressionsMatch(new LispNumber("23"), evaluateString("a"));
} }
@Test @Test
public void lookupDefinedSymbol() { public void lookupDefinedSymbol() {
evaluateString("(setf a 23)"); evaluateString("(setf a 23)");
assertSExpressionsMatch(evaluateString("23"), SETF.lookupSymbolValue("A")); assertSExpressionsMatch(new LispNumber("23"), SETF.lookupSymbolValue("A"));
} }
@Test @Test
@ -42,7 +42,7 @@ public class SETFTester {
evaluateString("(setf a 94)"); evaluateString("(setf a 94)");
SETF.setSymbolTable(global); SETF.setSymbolTable(global);
assertSExpressionsMatch(evaluateString("94"), evaluateString("a")); assertSExpressionsMatch(new LispNumber("94"), evaluateString("a"));
} }
@Test(expected = UndefinedSymbolException.class) @Test(expected = UndefinedSymbolException.class)
@ -65,7 +65,7 @@ public class SETFTester {
evaluateString("(setf a 94)"); evaluateString("(setf a 94)");
SETF.setSymbolTable(global); SETF.setSymbolTable(global);
assertSExpressionsMatch(evaluateString("94"), evaluateString("a")); assertSExpressionsMatch(new LispNumber("94"), evaluateString("a"));
} }
@Test(expected = BadArgumentTypeException.class) @Test(expected = BadArgumentTypeException.class)