From 5fd22b310f6d3172331b30a225059068b4f99754 Mon Sep 17 00:00:00 2001 From: Mike Cifelli Date: Fri, 27 Jan 2017 11:37:11 -0500 Subject: [PATCH] Simplified some predicate unit tests --- test/function/builtin/predicate/ATOMTester.java | 13 +++++-------- test/function/builtin/predicate/EQTester.java | 16 +++++++++------- .../builtin/predicate/EQUALSPTester.java | 13 +++++++------ .../function/builtin/predicate/EQUALTester.java | 17 +++++++++-------- .../builtin/predicate/GREATERPTester.java | 13 +++++++------ .../function/builtin/predicate/LESSPTester.java | 13 +++++++------ .../function/builtin/predicate/LISTPTester.java | 11 ++++------- test/function/builtin/predicate/NULLTester.java | 15 ++++++--------- test/parser/LispParserTester.java | 2 +- ...nTypeAssertions.java => TypeAssertions.java} | 6 +++++- 10 files changed, 60 insertions(+), 59 deletions(-) rename test/testutil/{SExpressionTypeAssertions.java => TypeAssertions.java} (93%) diff --git a/test/function/builtin/predicate/ATOMTester.java b/test/function/builtin/predicate/ATOMTester.java index 30fc55d..f866805 100644 --- a/test/function/builtin/predicate/ATOMTester.java +++ b/test/function/builtin/predicate/ATOMTester.java @@ -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) diff --git a/test/function/builtin/predicate/EQTester.java b/test/function/builtin/predicate/EQTester.java index 02e5853..d8f9440 100644 --- a/test/function/builtin/predicate/EQTester.java +++ b/test/function/builtin/predicate/EQTester.java @@ -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) diff --git a/test/function/builtin/predicate/EQUALSPTester.java b/test/function/builtin/predicate/EQUALSPTester.java index 8941c35..2294282 100644 --- a/test/function/builtin/predicate/EQUALSPTester.java +++ b/test/function/builtin/predicate/EQUALSPTester.java @@ -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) diff --git a/test/function/builtin/predicate/EQUALTester.java b/test/function/builtin/predicate/EQUALTester.java index a7276ee..e25e2ac 100644 --- a/test/function/builtin/predicate/EQUALTester.java +++ b/test/function/builtin/predicate/EQUALTester.java @@ -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) diff --git a/test/function/builtin/predicate/GREATERPTester.java b/test/function/builtin/predicate/GREATERPTester.java index 26ab718..6890b5c 100644 --- a/test/function/builtin/predicate/GREATERPTester.java +++ b/test/function/builtin/predicate/GREATERPTester.java @@ -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) diff --git a/test/function/builtin/predicate/LESSPTester.java b/test/function/builtin/predicate/LESSPTester.java index 3dcc6aa..924df1e 100644 --- a/test/function/builtin/predicate/LESSPTester.java +++ b/test/function/builtin/predicate/LESSPTester.java @@ -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) diff --git a/test/function/builtin/predicate/LISTPTester.java b/test/function/builtin/predicate/LISTPTester.java index 6f78838..c8e755a 100644 --- a/test/function/builtin/predicate/LISTPTester.java +++ b/test/function/builtin/predicate/LISTPTester.java @@ -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) diff --git a/test/function/builtin/predicate/NULLTester.java b/test/function/builtin/predicate/NULLTester.java index 585525b..460f073 100644 --- a/test/function/builtin/predicate/NULLTester.java +++ b/test/function/builtin/predicate/NULLTester.java @@ -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) diff --git a/test/parser/LispParserTester.java b/test/parser/LispParserTester.java index 7df9350..2eefd1f 100644 --- a/test/parser/LispParserTester.java +++ b/test/parser/LispParserTester.java @@ -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; diff --git a/test/testutil/SExpressionTypeAssertions.java b/test/testutil/TypeAssertions.java similarity index 93% rename from test/testutil/SExpressionTypeAssertions.java rename to test/testutil/TypeAssertions.java index 0d67b10..278aede 100644 --- a/test/testutil/SExpressionTypeAssertions.java +++ b/test/testutil/TypeAssertions.java @@ -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); + } + }