Simplified some predicate unit tests

This commit is contained in:
Mike Cifelli 2017-01-27 11:37:11 -05:00
parent fe880e1a02
commit 5fd22b310f
10 changed files with 60 additions and 59 deletions

View File

@ -1,6 +1,7 @@
package function.builtin.predicate;
import static testutil.TestUtilities.*;
import static testutil.TypeAssertions.*;
import org.junit.Test;
@ -9,17 +10,13 @@ import function.ArgumentValidator.*;
public class ATOMTester {
@Test
public void testAtom_ReturnsTrue() {
String input = "(atom 'a)";
assertSExpressionsMatch(parseString("T"), evaluateString(input));
public void atomIsAtom() {
assertT(evaluateString("(atom 'a)"));
}
@Test
public void testAtom_ReturnsFalse() {
String input = "(atom '(1 2 3))";
assertSExpressionsMatch(parseString("()"), evaluateString(input));
public void listIsNotAtom() {
assertNil(evaluateString("(atom '(1 2 3))"));
}
@Test(expected = TooManyArgumentsException.class)

View File

@ -1,6 +1,7 @@
package function.builtin.predicate;
import static testutil.TestUtilities.*;
import static testutil.TestUtilities.evaluateString;
import static testutil.TypeAssertions.*;
import org.junit.Test;
@ -12,20 +13,21 @@ public class EQTester {
public void testEqWithEqualAtoms() {
String input = "(eq 1 1)";
assertSExpressionsMatch(parseString("t"), evaluateString(input));
assertT(evaluateString(input));
}
@Test
public void testEqWithUnequalAtoms() {
String input = "(eq 1 2)";
assertSExpressionsMatch(parseString("nil"), evaluateString(input));
assertNil(evaluateString(input));
}
@Test
public void testEqWithAtomAndList() {
String input = "(eq 1 '(2))";
assertSExpressionsMatch(parseString("nil"), evaluateString(input));
assertNil(evaluateString(input));
}
@Test
@ -37,21 +39,21 @@ public class EQTester {
evaluateString(initializeL1);
evaluateString(initializeL2);
assertSExpressionsMatch(parseString("t"), evaluateString(input));
assertT(evaluateString(input));
}
@Test
public void testEqWithEqualLists() {
String input = "(eq '(1 2) '(1 2))";
assertSExpressionsMatch(parseString("nil"), evaluateString(input));
assertNil(evaluateString(input));
}
@Test
public void testEqWithUnequalLists() {
String input = "(eq '(1 2) '(3 4))";
assertSExpressionsMatch(parseString("nil"), evaluateString(input));
assertNil(evaluateString(input));
}
@Test(expected = TooManyArgumentsException.class)

View File

@ -1,6 +1,7 @@
package function.builtin.predicate;
import static testutil.TestUtilities.*;
import static testutil.TestUtilities.evaluateString;
import static testutil.TypeAssertions.*;
import org.junit.Test;
@ -12,35 +13,35 @@ public class EQUALSPTester {
public void testEqualspWithOneNumber() {
String input = "(= 1)";
assertSExpressionsMatch(parseString("t"), evaluateString(input));
assertT(evaluateString(input));
}
@Test
public void testEqualspWithEqualNumbers() {
String input = "(= 1 1)";
assertSExpressionsMatch(parseString("t"), evaluateString(input));
assertT(evaluateString(input));
}
@Test
public void testEqualspWithNonEqualNumbers() {
String input = "(= 1 2)";
assertSExpressionsMatch(parseString("nil"), evaluateString(input));
assertNil(evaluateString(input));
}
@Test
public void testEqualspWithManyEqualNumbers() {
String input = "(= 4 4 4 4 4 4 4 4 4 4)";
assertSExpressionsMatch(parseString("t"), evaluateString(input));
assertT(evaluateString(input));
}
@Test
public void testEqualspWithManyNonEqualNumbers() {
String input = "(= 4 4 4 4 5 4 4 4 4 4)";
assertSExpressionsMatch(parseString("nil"), evaluateString(input));
assertNil(evaluateString(input));
}
@Test(expected = BadArgumentTypeException.class)

View File

@ -1,6 +1,7 @@
package function.builtin.predicate;
import static testutil.TestUtilities.*;
import static testutil.TestUtilities.evaluateString;
import static testutil.TypeAssertions.*;
import org.junit.Test;
@ -12,49 +13,49 @@ public class EQUALTester {
public void testEqualWithTwoEqualAtoms() {
String input = "(equal 'a 'a)";
assertSExpressionsMatch(parseString("t"), evaluateString(input));
assertT(evaluateString(input));
}
@Test
public void testEqualWithTwoUnequalAtoms() {
String input = "(equal 'a 'b)";
assertSExpressionsMatch(parseString("nil"), evaluateString(input));
assertNil(evaluateString(input));
}
@Test
public void testEqualWithAtomAndList() {
String input = "(equal \"string\" '(m i k e))";
assertSExpressionsMatch(parseString("nil"), evaluateString(input));
assertNil(evaluateString(input));
}
@Test
public void testEqualWithListAndAtom() {
String input = "(equal '(m i k e) \"string\")";
assertSExpressionsMatch(parseString("nil"), evaluateString(input));
assertNil(evaluateString(input));
}
@Test
public void testEqualWithTwoEqualLists() {
String input = "(equal '(1 2 3) '(1 2 3))";
assertSExpressionsMatch(parseString("t"), evaluateString(input));
assertT(evaluateString(input));
}
@Test
public void testEqualWithTwoUnequalLists() {
String input = "(equal '(1 2 3) '(1 3 3))";
assertSExpressionsMatch(parseString("nil"), evaluateString(input));
assertNil(evaluateString(input));
}
@Test
public void testEqualWithTwoEqualNestedLists() {
String input = "(equal '(1 ((2) 3)) '(1 ((2) 3)))";
assertSExpressionsMatch(parseString("t"), evaluateString(input));
assertT(evaluateString(input));
}
@Test(expected = TooManyArgumentsException.class)

View File

@ -1,6 +1,7 @@
package function.builtin.predicate;
import static testutil.TestUtilities.*;
import static testutil.TestUtilities.evaluateString;
import static testutil.TypeAssertions.*;
import org.junit.Test;
@ -12,35 +13,35 @@ public class GREATERPTester {
public void testGreaterpWithOneNumber_ReturnsT() {
String input = "(> 1)";
assertSExpressionsMatch(parseString("t"), evaluateString(input));
assertT(evaluateString(input));
}
@Test
public void testGreaterpWithTwoNumbers_ReturnsNil() {
String input = "(> 1 2)";
assertSExpressionsMatch(parseString("nil"), evaluateString(input));
assertNil(evaluateString(input));
}
@Test
public void testGreaterpWithTwoNumbers_ReturnsT() {
String input = "(> 3 2)";
assertSExpressionsMatch(parseString("t"), evaluateString(input));
assertT(evaluateString(input));
}
@Test
public void testGreaterpWithManyNumbers_ReturnsNil() {
String input = "(> 4 3 2 5 1)";
assertSExpressionsMatch(parseString("nil"), evaluateString(input));
assertNil(evaluateString(input));
}
@Test
public void testGreaterpWithManyNumbers_ReturnsT() {
String input = "(> 4 3 2 1 0)";
assertSExpressionsMatch(parseString("t"), evaluateString(input));
assertT(evaluateString(input));
}
@Test(expected = BadArgumentTypeException.class)

View File

@ -1,6 +1,7 @@
package function.builtin.predicate;
import static testutil.TestUtilities.*;
import static testutil.TestUtilities.evaluateString;
import static testutil.TypeAssertions.*;
import org.junit.Test;
@ -12,35 +13,35 @@ public class LESSPTester {
public void testLesspWithOneNumber_ReturnsT() {
String input = "(< 1)";
assertSExpressionsMatch(parseString("t"), evaluateString(input));
assertT(evaluateString(input));
}
@Test
public void testLesspWithTwoNumbers_ReturnsNil() {
String input = "(< 2 1)";
assertSExpressionsMatch(parseString("nil"), evaluateString(input));
assertNil(evaluateString(input));
}
@Test
public void testLesspWithTwoNumbers_ReturnsT() {
String input = "(< 2 3)";
assertSExpressionsMatch(parseString("t"), evaluateString(input));
assertT(evaluateString(input));
}
@Test
public void testLesspWithManyNumbers_ReturnsNil() {
String input = "(< 4 3 2 5 1)";
assertSExpressionsMatch(parseString("nil"), evaluateString(input));
assertNil(evaluateString(input));
}
@Test
public void testLesspWithManyNumbers_ReturnsT() {
String input = "(< 0 1 2 3 4)";
assertSExpressionsMatch(parseString("t"), evaluateString(input));
assertT(evaluateString(input));
}
@Test(expected = BadArgumentTypeException.class)

View File

@ -1,6 +1,7 @@
package function.builtin.predicate;
import static testutil.TestUtilities.*;
import static testutil.TestUtilities.evaluateString;
import static testutil.TypeAssertions.*;
import org.junit.Test;
@ -10,16 +11,12 @@ public class LISTPTester {
@Test
public void testListpWithList_ReturnsT() {
String input = "(listp '(1))";
assertSExpressionsMatch(parseString("T"), evaluateString(input));
assertT(evaluateString("(listp '(1))"));
}
@Test
public void testListWithNonList_ReturnsNil() {
String input = "(listp 1)";
assertSExpressionsMatch(parseString("NIL"), evaluateString(input));
assertNil(evaluateString("(listp 1)"));
}
@Test(expected = TooFewArgumentsException.class)

View File

@ -1,6 +1,7 @@
package function.builtin.predicate;
import static testutil.TestUtilities.*;
import static testutil.TestUtilities.evaluateString;
import static testutil.TypeAssertions.*;
import org.junit.Test;
@ -9,17 +10,13 @@ import function.ArgumentValidator.*;
public class NULLTester {
@Test
public void testNilIsNull() {
String input = "(null ())";
assertSExpressionsMatch(parseString("T"), evaluateString(input));
public void nilIsNull() {
assertT(evaluateString("(null ())"));
}
@Test
public void testListIsNotNull() {
String input = "(null '(1))";
assertSExpressionsMatch(parseString("NIL"), evaluateString(input));
public void listIsNotNull() {
assertNil(evaluateString("(null '(1))"));
}
@Test(expected = TooFewArgumentsException.class)

View File

@ -1,7 +1,7 @@
package parser;
import static org.junit.Assert.*;
import static testutil.SExpressionTypeAssertions.*;
import static testutil.TypeAssertions.*;
import static testutil.TestUtilities.createIOExceptionThrowingInputStream;
import static testutil.TestUtilities.createInputStreamFromString;

View File

@ -4,7 +4,7 @@ import static org.junit.Assert.*;
import sexpression.*;
public final class SExpressionTypeAssertions {
public final class TypeAssertions {
public static void assertList(SExpression sExpression) {
assertFalse(sExpression.atomp());
@ -64,4 +64,8 @@ public final class SExpressionTypeAssertions {
assertTrue(sExpression.symbolp());
}
public static void assertT(SExpression sExpression) {
assertEquals(Symbol.T, sExpression);
}
}