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

View File

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

View File

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

View File

@ -1,6 +1,7 @@
package function.builtin.predicate; package function.builtin.predicate;
import static testutil.TestUtilities.*; import static testutil.TestUtilities.evaluateString;
import static testutil.TypeAssertions.*;
import org.junit.Test; import org.junit.Test;
@ -12,49 +13,49 @@ public class EQUALTester {
public void testEqualWithTwoEqualAtoms() { public void testEqualWithTwoEqualAtoms() {
String input = "(equal 'a 'a)"; String input = "(equal 'a 'a)";
assertSExpressionsMatch(parseString("t"), evaluateString(input)); assertT(evaluateString(input));
} }
@Test @Test
public void testEqualWithTwoUnequalAtoms() { public void testEqualWithTwoUnequalAtoms() {
String input = "(equal 'a 'b)"; String input = "(equal 'a 'b)";
assertSExpressionsMatch(parseString("nil"), evaluateString(input)); assertNil(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(parseString("nil"), evaluateString(input)); assertNil(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(parseString("nil"), evaluateString(input)); assertNil(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(parseString("t"), evaluateString(input)); assertT(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(parseString("nil"), evaluateString(input)); assertNil(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(parseString("t"), evaluateString(input)); assertT(evaluateString(input));
} }
@Test(expected = TooManyArgumentsException.class) @Test(expected = TooManyArgumentsException.class)

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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