Refactored tests to put the expected and actual values in the correct positions
This commit is contained in:
parent
32db0b2520
commit
fe880e1a02
|
@ -13,21 +13,21 @@ public class APPLYTester {
|
|||
public void testApply() {
|
||||
String input = "(apply '+ '(1 2 3))";
|
||||
|
||||
assertSExpressionsMatch(evaluateString(input), parseString("6"));
|
||||
assertSExpressionsMatch(parseString("6"), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testApplyWithLambdaExpression() {
|
||||
String input = "(apply (lambda (x) (+ x 1)) '(25))";
|
||||
|
||||
assertSExpressionsMatch(evaluateString(input), parseString("26"));
|
||||
assertSExpressionsMatch(parseString("26"), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testApplyWithQuotedLambdaExpression() {
|
||||
String input = "(apply '(lambda (x) (+ x 1)) '(25))";
|
||||
|
||||
assertSExpressionsMatch(evaluateString(input), parseString("26"));
|
||||
assertSExpressionsMatch(parseString("26"), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -35,7 +35,7 @@ public class APPLYTester {
|
|||
String argumentList = "(+ (25 10))";
|
||||
Cons parsedArgumentList = (Cons) parseString(argumentList);
|
||||
|
||||
assertSExpressionsMatch(APPLY.apply(parsedArgumentList), parseString("35"));
|
||||
assertSExpressionsMatch(parseString("35"), APPLY.apply(parsedArgumentList));
|
||||
}
|
||||
|
||||
@Test(expected = RuntimeException.class)
|
||||
|
|
|
@ -15,26 +15,26 @@ public class EVALTester {
|
|||
public void testEval() {
|
||||
String input = "(eval 9)";
|
||||
|
||||
assertSExpressionsMatch(evaluateString(input), parseString("9"));
|
||||
assertSExpressionsMatch(parseString("9"), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEvalNil() {
|
||||
String input = "(eval ())";
|
||||
|
||||
assertSExpressionsMatch(evaluateString(input), parseString("()"));
|
||||
assertSExpressionsMatch(parseString("()"), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLookupSymbol() {
|
||||
String symbol = ":symbol";
|
||||
assertSExpressionsMatch(EVAL.lookupSymbol(symbol), parseString(symbol));
|
||||
assertSExpressionsMatch(parseString(symbol), EVAL.lookupSymbol(symbol));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLookupT() {
|
||||
String symbol = "T";
|
||||
assertSExpressionsMatch(EVAL.lookupSymbol(symbol), parseString(symbol));
|
||||
assertSExpressionsMatch(parseString(symbol), EVAL.lookupSymbol(symbol));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -12,7 +12,7 @@ public class FUNCALLTester {
|
|||
public void testFuncallWithNumbers() {
|
||||
String input = "(funcall '+ 1 2 3)";
|
||||
|
||||
assertSExpressionsMatch(evaluateString(input), parseString("6"));
|
||||
assertSExpressionsMatch(parseString("6"), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -21,7 +21,7 @@ public class FUNCALLTester {
|
|||
String input = "(funcall 'x 2 30)";
|
||||
|
||||
evaluateString(defineUserFunction);
|
||||
assertSExpressionsMatch(evaluateString(input), parseString("32"));
|
||||
assertSExpressionsMatch(parseString("32"), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test(expected = TooFewArgumentsException.class)
|
||||
|
|
|
@ -9,6 +9,7 @@ import org.junit.*;
|
|||
|
||||
import environment.Environment;
|
||||
import function.ArgumentValidator.*;
|
||||
import sexpression.*;
|
||||
|
||||
public class LOADTester {
|
||||
|
||||
|
@ -32,7 +33,7 @@ public class LOADTester {
|
|||
public void loadGoodFile_ReturnsTAndPrintsNothing() {
|
||||
String input = "(load \"test/function/builtin/test-files/load-good.lisp\")";
|
||||
|
||||
assertSExpressionsMatch(parseString("T"), evaluateString(input));
|
||||
assertSExpressionsMatch(Symbol.T, evaluateString(input));
|
||||
assertNothingPrinted();
|
||||
}
|
||||
|
||||
|
@ -40,7 +41,7 @@ public class LOADTester {
|
|||
public void loadBadFile_ReturnsNilAndPrintsError() {
|
||||
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");
|
||||
}
|
||||
|
||||
|
@ -48,7 +49,7 @@ public class LOADTester {
|
|||
public void loadNonExistentFile_ReturnsNilAndPrintsError() {
|
||||
String input = "(load \"doesNotExist.lisp\")";
|
||||
|
||||
assertSExpressionsMatch(parseString("nil"), evaluateString(input));
|
||||
assertSExpressionsMatch(Nil.getInstance(), evaluateString(input));
|
||||
assertPrinted("LOAD: could not open 'doesNotExist.lisp'\n");
|
||||
}
|
||||
|
||||
|
|
|
@ -12,21 +12,21 @@ public class CARTester {
|
|||
public void testCarWithNil() {
|
||||
String input = "(car nil)";
|
||||
|
||||
assertSExpressionsMatch(evaluateString(input), parseString("()"));
|
||||
assertSExpressionsMatch(parseString("()"), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCarWithList() {
|
||||
String input = "(car '(1 2 3))";
|
||||
|
||||
assertSExpressionsMatch(evaluateString(input), parseString("1"));
|
||||
assertSExpressionsMatch(parseString("1"), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNestedCarWithList() {
|
||||
String input = "(car (car '((1 2) 3)))";
|
||||
|
||||
assertSExpressionsMatch(evaluateString(input), parseString("1"));
|
||||
assertSExpressionsMatch(parseString("1"), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test(expected = BadArgumentTypeException.class)
|
||||
|
|
|
@ -12,21 +12,21 @@ public class CDRTester {
|
|||
public void testCdrWithNil() {
|
||||
String input = "(cdr nil)";
|
||||
|
||||
assertSExpressionsMatch(evaluateString(input), parseString("()"));
|
||||
assertSExpressionsMatch(parseString("()"), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCdrWithList() {
|
||||
String input = "(cdr '(1 2 3))";
|
||||
|
||||
assertSExpressionsMatch(evaluateString(input), parseString("(2 3)"));
|
||||
assertSExpressionsMatch(parseString("(2 3)"), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNestedCdrWithList() {
|
||||
String input = "(cdr (cdr '(1 2 3)))";
|
||||
|
||||
assertSExpressionsMatch(evaluateString(input), parseString("(3)"));
|
||||
assertSExpressionsMatch(parseString("(3)"), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test(expected = BadArgumentTypeException.class)
|
||||
|
|
|
@ -13,27 +13,27 @@ public class CONSTester {
|
|||
public void testConsWithNilValues() {
|
||||
String input = "(cons () nil)";
|
||||
|
||||
assertSExpressionsMatch(evaluateString(input), parseString("(())"));
|
||||
assertSExpressionsMatch(parseString("(())"), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConsWithTwoSymbols() {
|
||||
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
|
||||
public void testConsWithListAsCdr() {
|
||||
String input = "(cons 1 '(2 3))";
|
||||
|
||||
assertSExpressionsMatch(evaluateString(input), parseString("(1 2 3)"));
|
||||
assertSExpressionsMatch(parseString("(1 2 3)"), evaluateString(input));
|
||||
}
|
||||
@Test
|
||||
public void testConsWithTwoLists() {
|
||||
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() {
|
||||
String input = "(cons nil '(2 3))";
|
||||
|
||||
assertSExpressionsMatch(evaluateString(input), parseString("(nil 2 3)"));
|
||||
assertSExpressionsMatch(parseString("(nil 2 3)"), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test(expected = TooManyArgumentsException.class)
|
||||
|
|
|
@ -12,21 +12,21 @@ public class LENGTHTester {
|
|||
public void testLengthOfNil() {
|
||||
String input = "(length '())";
|
||||
|
||||
assertSExpressionsMatch(evaluateString(input), parseString("0"));
|
||||
assertSExpressionsMatch(parseString("0"), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLengthOfListOfOneElement() {
|
||||
String input = "(length '(1))";
|
||||
|
||||
assertSExpressionsMatch(evaluateString(input), parseString("1"));
|
||||
assertSExpressionsMatch(parseString("1"), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLengthOfListOfManyElements() {
|
||||
String input = "(length '(1 2 3 4 5))";
|
||||
|
||||
assertSExpressionsMatch(evaluateString(input), parseString("5"));
|
||||
assertSExpressionsMatch(parseString("5"), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test(expected = BadArgumentTypeException.class)
|
||||
|
|
|
@ -10,47 +10,47 @@ public class LISTTester {
|
|||
public void testListWithNoArguments() {
|
||||
String input = "(list)";
|
||||
|
||||
assertSExpressionsMatch(evaluateString(input), parseString("nil"));
|
||||
assertSExpressionsMatch(parseString("nil"), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListWithOneArgument() {
|
||||
String input = "(list 1)";
|
||||
|
||||
assertSExpressionsMatch(evaluateString(input), parseString("(1)"));
|
||||
assertSExpressionsMatch(parseString("(1)"), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListWithTwoArguments() {
|
||||
String input = "(list 2 3)";
|
||||
|
||||
assertSExpressionsMatch(evaluateString(input), parseString("(2 3)"));
|
||||
assertSExpressionsMatch(parseString("(2 3)"), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListWithManyArguments() {
|
||||
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
|
||||
public void testListWithOneListArgument() {
|
||||
String input = "(list '(1))";
|
||||
|
||||
assertSExpressionsMatch(evaluateString(input), parseString("((1))"));
|
||||
assertSExpressionsMatch(parseString("((1))"), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListWithManyListArguments() {
|
||||
String input = "(list '(1) '(2 3) ())";
|
||||
|
||||
assertSExpressionsMatch(evaluateString(input), parseString("((1) (2 3) ())"));
|
||||
assertSExpressionsMatch(parseString("((1) (2 3) ())"), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMakeList() {
|
||||
assertSExpressionsMatch(LIST.makeList(parseString("22")), parseString("(22)"));
|
||||
assertSExpressionsMatch(parseString("(22)"), LIST.makeList(parseString("22")));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -12,42 +12,42 @@ public class DIVIDETester {
|
|||
public void testDivideWithOne() {
|
||||
String input = "(/ 1)";
|
||||
|
||||
assertSExpressionsMatch(evaluateString(input), parseString("1"));
|
||||
assertSExpressionsMatch(parseString("1"), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDivideWithTwo() {
|
||||
String input = "(/ 2)";
|
||||
|
||||
assertSExpressionsMatch(evaluateString(input), parseString("0"));
|
||||
assertSExpressionsMatch(parseString("0"), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDivideTwoNumbers() {
|
||||
String input = "(/ 24 3)";
|
||||
|
||||
assertSExpressionsMatch(evaluateString(input), parseString("8"));
|
||||
assertSExpressionsMatch(parseString("8"), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDivideSeveralNumbers() {
|
||||
String input = "(/ 256 2 2 8)";
|
||||
|
||||
assertSExpressionsMatch(evaluateString(input), parseString("8"));
|
||||
assertSExpressionsMatch(parseString("8"), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDivideTwoNumbersWithRemainder() {
|
||||
String input = "(/ 9 2)";
|
||||
|
||||
assertSExpressionsMatch(evaluateString(input), parseString("4"));
|
||||
assertSExpressionsMatch(parseString("4"), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDivideSeveralNumbersWithRemainder() {
|
||||
String input = "(/ 19 2 5)";
|
||||
|
||||
assertSExpressionsMatch(evaluateString(input), parseString("1"));
|
||||
assertSExpressionsMatch(parseString("1"), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test(expected = BadArgumentTypeException.class)
|
||||
|
|
|
@ -13,28 +13,28 @@ public class MINUSTester {
|
|||
public void testMinusWithOneNumber() {
|
||||
String input = "(- 27)";
|
||||
|
||||
assertSExpressionsMatch(evaluateString(input), new LispNumber("-27"));
|
||||
assertSExpressionsMatch(new LispNumber("-27"), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMinusWithTwoNumbers() {
|
||||
String input = "(- 5 3)";
|
||||
|
||||
assertSExpressionsMatch(evaluateString(input), new LispNumber("2"));
|
||||
assertSExpressionsMatch(new LispNumber("2"), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMinusWithManyNumbers_PositiveResult() {
|
||||
String input = "(- 200 100 10 5)";
|
||||
|
||||
assertSExpressionsMatch(evaluateString(input), new LispNumber("85"));
|
||||
assertSExpressionsMatch(new LispNumber("85"), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMinusWithManyNumbers_NegativeResult() {
|
||||
String input = "(- 100 200 20 5)";
|
||||
|
||||
assertSExpressionsMatch(evaluateString(input), new LispNumber("-125"));
|
||||
assertSExpressionsMatch(new LispNumber("-125"), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test(expected = BadArgumentTypeException.class)
|
||||
|
|
|
@ -13,35 +13,35 @@ public class MULTIPLYTester {
|
|||
public void testMultiplyWithNoArguments() {
|
||||
String input = "(*)";
|
||||
|
||||
assertSExpressionsMatch(evaluateString(input), new LispNumber("1"));
|
||||
assertSExpressionsMatch(new LispNumber("1"), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultiplyWithOneNumber() {
|
||||
String input = "(* 8)";
|
||||
|
||||
assertSExpressionsMatch(evaluateString(input), new LispNumber("8"));
|
||||
assertSExpressionsMatch(new LispNumber("8"), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultiplyWithTwoNumbers() {
|
||||
String input = "(* 5 3)";
|
||||
|
||||
assertSExpressionsMatch(evaluateString(input), new LispNumber("15"));
|
||||
assertSExpressionsMatch(new LispNumber("15"), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultiplyWithManyNumbers_PositiveResult() {
|
||||
String input = "(* 2 3 5 1)";
|
||||
|
||||
assertSExpressionsMatch(evaluateString(input), new LispNumber("30"));
|
||||
assertSExpressionsMatch(new LispNumber("30"), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultiplyWithManyNumbers_NegativeResult() {
|
||||
String input = "(* 3 (- 2) 10 2)";
|
||||
|
||||
assertSExpressionsMatch(evaluateString(input), new LispNumber("-120"));
|
||||
assertSExpressionsMatch(new LispNumber("-120"), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test(expected = BadArgumentTypeException.class)
|
||||
|
|
|
@ -13,35 +13,35 @@ public class PLUSTester {
|
|||
public void testPlusWithNoArguments() {
|
||||
String input = "(+)";
|
||||
|
||||
assertSExpressionsMatch(evaluateString(input), new LispNumber("0"));
|
||||
assertSExpressionsMatch(new LispNumber("0"), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPlusWithOneNumber() {
|
||||
String input = "(+ 27)";
|
||||
|
||||
assertSExpressionsMatch(evaluateString(input), new LispNumber("27"));
|
||||
assertSExpressionsMatch(new LispNumber("27"), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPlusWithTwoNumbers() {
|
||||
String input = "(+ 5 3)";
|
||||
|
||||
assertSExpressionsMatch(evaluateString(input), new LispNumber("8"));
|
||||
assertSExpressionsMatch(new LispNumber("8"), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPlusWithManyNumbers_PositiveResult() {
|
||||
String input = "(+ 200 100 10 5)";
|
||||
|
||||
assertSExpressionsMatch(evaluateString(input), new LispNumber("315"));
|
||||
assertSExpressionsMatch(new LispNumber("315"), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPlusWithManyNumbers_NegativeResult() {
|
||||
String input = "(+ 100 (- 200) 20 5)";
|
||||
|
||||
assertSExpressionsMatch(evaluateString(input), new LispNumber("-75"));
|
||||
assertSExpressionsMatch(new LispNumber("-75"), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test(expected = BadArgumentTypeException.class)
|
||||
|
|
|
@ -12,14 +12,14 @@ public class ATOMTester {
|
|||
public void testAtom_ReturnsTrue() {
|
||||
String input = "(atom 'a)";
|
||||
|
||||
assertSExpressionsMatch(evaluateString(input), parseString("T"));
|
||||
assertSExpressionsMatch(parseString("T"), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAtom_ReturnsFalse() {
|
||||
String input = "(atom '(1 2 3))";
|
||||
|
||||
assertSExpressionsMatch(evaluateString(input), parseString("()"));
|
||||
assertSExpressionsMatch(parseString("()"), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test(expected = TooManyArgumentsException.class)
|
||||
|
|
|
@ -12,20 +12,20 @@ public class EQTester {
|
|||
public void testEqWithEqualAtoms() {
|
||||
String input = "(eq 1 1)";
|
||||
|
||||
assertSExpressionsMatch(evaluateString(input), parseString("t"));
|
||||
assertSExpressionsMatch(parseString("t"), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEqWithUnequalAtoms() {
|
||||
String input = "(eq 1 2)";
|
||||
|
||||
assertSExpressionsMatch(evaluateString(input), parseString("nil"));
|
||||
assertSExpressionsMatch(parseString("nil"), evaluateString(input));
|
||||
}
|
||||
@Test
|
||||
public void testEqWithAtomAndList() {
|
||||
String input = "(eq 1 '(2))";
|
||||
|
||||
assertSExpressionsMatch(evaluateString(input), parseString("nil"));
|
||||
assertSExpressionsMatch(parseString("nil"), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -37,21 +37,21 @@ public class EQTester {
|
|||
evaluateString(initializeL1);
|
||||
evaluateString(initializeL2);
|
||||
|
||||
assertSExpressionsMatch(evaluateString(input), parseString("t"));
|
||||
assertSExpressionsMatch(parseString("t"), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEqWithEqualLists() {
|
||||
String input = "(eq '(1 2) '(1 2))";
|
||||
|
||||
assertSExpressionsMatch(evaluateString(input), parseString("nil"));
|
||||
assertSExpressionsMatch(parseString("nil"), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEqWithUnequalLists() {
|
||||
String input = "(eq '(1 2) '(3 4))";
|
||||
|
||||
assertSExpressionsMatch(evaluateString(input), parseString("nil"));
|
||||
assertSExpressionsMatch(parseString("nil"), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test(expected = TooManyArgumentsException.class)
|
||||
|
|
|
@ -12,35 +12,35 @@ public class EQUALSPTester {
|
|||
public void testEqualspWithOneNumber() {
|
||||
String input = "(= 1)";
|
||||
|
||||
assertSExpressionsMatch(evaluateString(input), parseString("t"));
|
||||
assertSExpressionsMatch(parseString("t"), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEqualspWithEqualNumbers() {
|
||||
String input = "(= 1 1)";
|
||||
|
||||
assertSExpressionsMatch(evaluateString(input), parseString("t"));
|
||||
assertSExpressionsMatch(parseString("t"), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEqualspWithNonEqualNumbers() {
|
||||
String input = "(= 1 2)";
|
||||
|
||||
assertSExpressionsMatch(evaluateString(input), parseString("nil"));
|
||||
assertSExpressionsMatch(parseString("nil"), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEqualspWithManyEqualNumbers() {
|
||||
String input = "(= 4 4 4 4 4 4 4 4 4 4)";
|
||||
|
||||
assertSExpressionsMatch(evaluateString(input), parseString("t"));
|
||||
assertSExpressionsMatch(parseString("t"), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEqualspWithManyNonEqualNumbers() {
|
||||
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)
|
||||
|
|
|
@ -12,49 +12,49 @@ public class EQUALTester {
|
|||
public void testEqualWithTwoEqualAtoms() {
|
||||
String input = "(equal 'a 'a)";
|
||||
|
||||
assertSExpressionsMatch(evaluateString(input), parseString("t"));
|
||||
assertSExpressionsMatch(parseString("t"), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEqualWithTwoUnequalAtoms() {
|
||||
String input = "(equal 'a 'b)";
|
||||
|
||||
assertSExpressionsMatch(evaluateString(input), parseString("nil"));
|
||||
assertSExpressionsMatch(parseString("nil"), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEqualWithAtomAndList() {
|
||||
String input = "(equal \"string\" '(m i k e))";
|
||||
|
||||
assertSExpressionsMatch(evaluateString(input), parseString("nil"));
|
||||
assertSExpressionsMatch(parseString("nil"), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEqualWithListAndAtom() {
|
||||
String input = "(equal '(m i k e) \"string\")";
|
||||
|
||||
assertSExpressionsMatch(evaluateString(input), parseString("nil"));
|
||||
assertSExpressionsMatch(parseString("nil"), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEqualWithTwoEqualLists() {
|
||||
String input = "(equal '(1 2 3) '(1 2 3))";
|
||||
|
||||
assertSExpressionsMatch(evaluateString(input), parseString("t"));
|
||||
assertSExpressionsMatch(parseString("t"), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEqualWithTwoUnequalLists() {
|
||||
String input = "(equal '(1 2 3) '(1 3 3))";
|
||||
|
||||
assertSExpressionsMatch(evaluateString(input), parseString("nil"));
|
||||
assertSExpressionsMatch(parseString("nil"), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEqualWithTwoEqualNestedLists() {
|
||||
String input = "(equal '(1 ((2) 3)) '(1 ((2) 3)))";
|
||||
|
||||
assertSExpressionsMatch(evaluateString(input), parseString("t"));
|
||||
assertSExpressionsMatch(parseString("t"), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test(expected = TooManyArgumentsException.class)
|
||||
|
|
|
@ -12,35 +12,35 @@ public class GREATERPTester {
|
|||
public void testGreaterpWithOneNumber_ReturnsT() {
|
||||
String input = "(> 1)";
|
||||
|
||||
assertSExpressionsMatch(evaluateString(input), parseString("t"));
|
||||
assertSExpressionsMatch(parseString("t"), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGreaterpWithTwoNumbers_ReturnsNil() {
|
||||
String input = "(> 1 2)";
|
||||
|
||||
assertSExpressionsMatch(evaluateString(input), parseString("nil"));
|
||||
assertSExpressionsMatch(parseString("nil"), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGreaterpWithTwoNumbers_ReturnsT() {
|
||||
String input = "(> 3 2)";
|
||||
|
||||
assertSExpressionsMatch(evaluateString(input), parseString("t"));
|
||||
assertSExpressionsMatch(parseString("t"), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGreaterpWithManyNumbers_ReturnsNil() {
|
||||
String input = "(> 4 3 2 5 1)";
|
||||
|
||||
assertSExpressionsMatch(evaluateString(input), parseString("nil"));
|
||||
assertSExpressionsMatch(parseString("nil"), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGreaterpWithManyNumbers_ReturnsT() {
|
||||
String input = "(> 4 3 2 1 0)";
|
||||
|
||||
assertSExpressionsMatch(evaluateString(input), parseString("t"));
|
||||
assertSExpressionsMatch(parseString("t"), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test(expected = BadArgumentTypeException.class)
|
||||
|
|
|
@ -12,35 +12,35 @@ public class LESSPTester {
|
|||
public void testLesspWithOneNumber_ReturnsT() {
|
||||
String input = "(< 1)";
|
||||
|
||||
assertSExpressionsMatch(evaluateString(input), parseString("t"));
|
||||
assertSExpressionsMatch(parseString("t"), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLesspWithTwoNumbers_ReturnsNil() {
|
||||
String input = "(< 2 1)";
|
||||
|
||||
assertSExpressionsMatch(evaluateString(input), parseString("nil"));
|
||||
assertSExpressionsMatch(parseString("nil"), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLesspWithTwoNumbers_ReturnsT() {
|
||||
String input = "(< 2 3)";
|
||||
|
||||
assertSExpressionsMatch(evaluateString(input), parseString("t"));
|
||||
assertSExpressionsMatch(parseString("t"), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLesspWithManyNumbers_ReturnsNil() {
|
||||
String input = "(< 4 3 2 5 1)";
|
||||
|
||||
assertSExpressionsMatch(evaluateString(input), parseString("nil"));
|
||||
assertSExpressionsMatch(parseString("nil"), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLesspWithManyNumbers_ReturnsT() {
|
||||
String input = "(< 0 1 2 3 4)";
|
||||
|
||||
assertSExpressionsMatch(evaluateString(input), parseString("t"));
|
||||
assertSExpressionsMatch(parseString("t"), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test(expected = BadArgumentTypeException.class)
|
||||
|
|
|
@ -12,14 +12,14 @@ public class LISTPTester {
|
|||
public void testListpWithList_ReturnsT() {
|
||||
String input = "(listp '(1))";
|
||||
|
||||
assertSExpressionsMatch(evaluateString(input), parseString("T"));
|
||||
assertSExpressionsMatch(parseString("T"), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListWithNonList_ReturnsNil() {
|
||||
String input = "(listp 1)";
|
||||
|
||||
assertSExpressionsMatch(evaluateString(input), parseString("NIL"));
|
||||
assertSExpressionsMatch(parseString("NIL"), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test(expected = TooFewArgumentsException.class)
|
||||
|
|
|
@ -12,14 +12,14 @@ public class NULLTester {
|
|||
public void testNilIsNull() {
|
||||
String input = "(null ())";
|
||||
|
||||
assertSExpressionsMatch(evaluateString(input), parseString("T"));
|
||||
assertSExpressionsMatch(parseString("T"), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListIsNotNull() {
|
||||
String input = "(null '(1))";
|
||||
|
||||
assertSExpressionsMatch(evaluateString(input), parseString("NIL"));
|
||||
assertSExpressionsMatch(parseString("NIL"), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test(expected = TooFewArgumentsException.class)
|
||||
|
|
|
@ -12,56 +12,56 @@ public class CONDTester {
|
|||
public void testCondWithNoArguments() {
|
||||
String input = "(cond)";
|
||||
|
||||
assertSExpressionsMatch(evaluateString(input), parseString("nil"));
|
||||
assertSExpressionsMatch(parseString("nil"), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCondWithTrue() {
|
||||
String input = "(cond (T))";
|
||||
|
||||
assertSExpressionsMatch(evaluateString(input), parseString("T"));
|
||||
assertSExpressionsMatch(parseString("T"), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCondWithSingleExpression() {
|
||||
String input = "(cond (T \"true\"))";
|
||||
|
||||
assertSExpressionsMatch(evaluateString(input), parseString("\"true\""));
|
||||
assertSExpressionsMatch(parseString("\"true\""), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCondWithMultipleExpressions() {
|
||||
String input = "(cond ((= 1 2) 2) ((= 1 2) 2) ((= 1 1) 3))";
|
||||
|
||||
assertSExpressionsMatch(evaluateString(input), parseString("3"));
|
||||
assertSExpressionsMatch(parseString("3"), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCondWithMultipleConditionsMatching_ReturnFirstOne() {
|
||||
String input = "(cond ((= 1 1) 2) ((= 1 1) 3))";
|
||||
|
||||
assertSExpressionsMatch(evaluateString(input), parseString("2"));
|
||||
assertSExpressionsMatch(parseString("2"), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCondWithMultipleConditionsMatching_OnlyEvaluatesFirstOne() {
|
||||
String input = "(cond ((= 1 1) 2) ((= 1 1) x))";
|
||||
|
||||
assertSExpressionsMatch(evaluateString(input), parseString("2"));
|
||||
assertSExpressionsMatch(parseString("2"), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCondWithMultipleResultValues_OnlyReturnsLast() {
|
||||
String input = "(cond ((= 1 1) 2 3 4))";
|
||||
|
||||
assertSExpressionsMatch(evaluateString(input), parseString("4"));
|
||||
assertSExpressionsMatch(parseString("4"), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCondWithNoConditionMatching_ReturnsNil() {
|
||||
String input = "(cond ((= 1 2) T) ((= 1 3) T))";
|
||||
|
||||
assertSExpressionsMatch(evaluateString(input), parseString("nil"));
|
||||
assertSExpressionsMatch(parseString("nil"), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test(expected = BadArgumentTypeException.class)
|
||||
|
|
|
@ -12,8 +12,8 @@ public class DEFUNTester {
|
|||
public void testDefun() {
|
||||
String input = "(defun f () nil)";
|
||||
|
||||
assertSExpressionsMatch(evaluateString(input), parseString("f"));
|
||||
assertSExpressionsMatch(evaluateString("(f)"), parseString("()"));
|
||||
assertSExpressionsMatch(parseString("f"), evaluateString(input));
|
||||
assertSExpressionsMatch(parseString("()"), evaluateString("(f)"));
|
||||
}
|
||||
|
||||
@Test(expected = DottedArgumentListException.class)
|
||||
|
|
|
@ -12,14 +12,14 @@ public class QUOTETester {
|
|||
public void testQuoteSymbol() {
|
||||
String input = "'a";
|
||||
|
||||
assertSExpressionsMatch(evaluateString(input), parseString("a"));
|
||||
assertSExpressionsMatch(parseString("a"), evaluateString(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testQuoteList() {
|
||||
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)
|
||||
|
|
|
@ -20,13 +20,13 @@ public class SETFTester {
|
|||
@Test
|
||||
public void testSetf() {
|
||||
evaluateString("(setf a 23)");
|
||||
assertSExpressionsMatch(evaluateString("23"), evaluateString("a"));
|
||||
assertSExpressionsMatch(new LispNumber("23"), evaluateString("a"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void lookupDefinedSymbol() {
|
||||
evaluateString("(setf a 23)");
|
||||
assertSExpressionsMatch(evaluateString("23"), SETF.lookupSymbolValue("A"));
|
||||
assertSExpressionsMatch(new LispNumber("23"), SETF.lookupSymbolValue("A"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -42,7 +42,7 @@ public class SETFTester {
|
|||
|
||||
evaluateString("(setf a 94)");
|
||||
SETF.setSymbolTable(global);
|
||||
assertSExpressionsMatch(evaluateString("94"), evaluateString("a"));
|
||||
assertSExpressionsMatch(new LispNumber("94"), evaluateString("a"));
|
||||
}
|
||||
|
||||
@Test(expected = UndefinedSymbolException.class)
|
||||
|
@ -65,7 +65,7 @@ public class SETFTester {
|
|||
|
||||
evaluateString("(setf a 94)");
|
||||
SETF.setSymbolTable(global);
|
||||
assertSExpressionsMatch(evaluateString("94"), evaluateString("a"));
|
||||
assertSExpressionsMatch(new LispNumber("94"), evaluateString("a"));
|
||||
}
|
||||
|
||||
@Test(expected = BadArgumentTypeException.class)
|
||||
|
|
Loading…
Reference in New Issue