diff --git a/core/src/main/java/io/parsingdata/metal/data/ParseGraph.java b/core/src/main/java/io/parsingdata/metal/data/ParseGraph.java index 76bbb85a..30b7c8d4 100644 --- a/core/src/main/java/io/parsingdata/metal/data/ParseGraph.java +++ b/core/src/main/java/io/parsingdata/metal/data/ParseGraph.java @@ -150,8 +150,9 @@ public boolean equals(final Object obj) { && Objects.equals(head, ((ParseGraph)obj).head) && Objects.equals(tail, ((ParseGraph)obj).tail) && Objects.equals(branched, ((ParseGraph)obj).branched) + && Objects.equals(scopeDepth, ((ParseGraph)obj).scopeDepth) && Objects.equals(definition, ((ParseGraph)obj).definition); - // The size and scopeDepth fields are excluded from equals() and hashCode() because it is cached data. + // The size field is excluded from equals() and hashCode() because it is cached data. } @Override diff --git a/core/src/test/java/io/parsingdata/metal/AutoEqualityTest.java b/core/src/test/java/io/parsingdata/metal/AutoEqualityTest.java index 5341afcb..28762dd3 100644 --- a/core/src/test/java/io/parsingdata/metal/AutoEqualityTest.java +++ b/core/src/test/java/io/parsingdata/metal/AutoEqualityTest.java @@ -169,7 +169,7 @@ public class AutoEqualityTest { io.parsingdata.metal.expression.logical.Not.class, // Data structures CoreValue.class, ParseValue.class, ParseReference.class, ParseState.class, - NotAValue.class, ImmutableList.class, + NotAValue.class, ParseGraph.class, ImmutableList.class, ParseValueCache.class, // Inputs Slice.class, @@ -184,7 +184,7 @@ public class AutoEqualityTest { // Utility classes. Selection.class, ConstantFactory.class, // Multiple constructors - Environment.class, ParseGraph.class + Environment.class ); public static final Object OTHER_TYPE = new Object() {}; @@ -436,10 +436,10 @@ public void basicNoHashCollisions(final Object object, final Object same, final } } - public static void assertEquals(final Object o, final Object object) { + private static void assertEquals(final Object o, final Object object) { Assertions.assertEquals(o, object, String.format("Objects should be equal:\n%s\n%s\n", o, object)); } - public static void assertNotEquals(final Object o, final Object object) { + private static void assertNotEquals(final Object o, final Object object) { Assertions.assertNotEquals(o, object, String.format("Objects should not be equal:\n%s\n%s\n", o, object)); } diff --git a/core/src/test/java/io/parsingdata/metal/data/ParseGraphTest.java b/core/src/test/java/io/parsingdata/metal/data/ParseGraphTest.java index e0aa650f..07726ddc 100644 --- a/core/src/test/java/io/parsingdata/metal/data/ParseGraphTest.java +++ b/core/src/test/java/io/parsingdata/metal/data/ParseGraphTest.java @@ -61,7 +61,6 @@ public class ParseGraphTest { private static ParseGraph pg; private static ParseGraph pgc; private static ParseGraph pgl; - private static List pgs; private static Token aDef; private static ParseValue a; private static ParseValue b; @@ -97,7 +96,6 @@ public static void setup() { pg = makeSimpleGraph(); pgc = makeCycleGraph(); pgl = makeLongGraph(); - pgs = makeGraphList(); } private static ParseGraph makeSimpleGraph() { @@ -252,79 +250,6 @@ public void testCurrent() { assertFalse(EMPTY.addBranch(NONE).current().isPresent()); } - private static List makeGraphList() { - return List.of( - EMPTY, - EMPTY.add(a), - EMPTY.add(b), - EMPTY.add(a).add(b), - EMPTY.add(b).add(a), - - EMPTY.addBranch(t), - EMPTY.addBranch(s), - EMPTY.add(a).addBranch(s), - EMPTY.add(a).addBranch(t), - EMPTY.add(b).addBranch(s), - EMPTY.add(b).addBranch(t), - EMPTY.add(a).addBranch(t).addBranch(s), - EMPTY.add(a).addBranch(s).addBranch(t), - EMPTY.add(b).addBranch(s).addBranch(t), - EMPTY.add(b).addBranch(t).addBranch(s), - - EMPTY.add(a).addBranch(t).add(a), - EMPTY.add(a).addBranch(t).add(b), - EMPTY.add(b).addBranch(s).add(a), - EMPTY.add(b).addBranch(t).add(b), - EMPTY.add(a).addBranch(t).add(a).addBranch(s), - EMPTY.add(a).addBranch(s).add(b).addBranch(t), - EMPTY.add(b).addBranch(s).add(a).addBranch(t), - EMPTY.add(b).addBranch(t).add(b).addBranch(s), - - EMPTY.add(a).addBranch(t).add(a).addBranch(s).add(a), - EMPTY.add(a).addBranch(t).add(a).addBranch(s).add(b), - EMPTY.add(a).addBranch(s).add(b).addBranch(t).add(a), - EMPTY.add(a).addBranch(s).add(b).addBranch(t).add(b), - EMPTY.add(b).addBranch(s).add(a).addBranch(t).add(a), - EMPTY.add(b).addBranch(s).add(a).addBranch(t).add(b), - EMPTY.add(b).addBranch(t).add(b).addBranch(s).add(a), - EMPTY.add(b).addBranch(t).add(b).addBranch(s).add(b) - ); - } - - public static Stream nonEqualityTest() { - final List args = new ArrayList<>(); - for (int i = 0; i < pgs.size(); i++) { - for (int j = 0; j < pgs.size(); j++) { - if (i != j) { - args.add(arguments(i + "," + j, pgs.get(i), pgs.get(j))); - } - } - } - return args.stream(); - } - - @ParameterizedTest - @MethodSource - public void nonEqualityTest(final String testnr, final ParseGraph first, final ParseGraph second) { - AutoEqualityTest.assertNotEquals(first, second); - AutoEqualityTest.assertNotEquals(first.hashCode(), second.hashCode()); - } - - public static Stream equalityTest() { - final List args = new ArrayList<>(); - for (int i = 0; i < pgs.size(); i++) { - args.add(arguments(i, pgs.get(i), pgs.get(i))); - } - return args.stream(); - } - - @ParameterizedTest - @MethodSource - public void equalityTest(final int testnr, final ParseGraph first, final ParseGraph second) { - AutoEqualityTest.assertEquals(first, second); - AutoEqualityTest.assertEquals(first.hashCode(), second.hashCode()); - } - public static Stream scopeDepthTest() { return Stream.of( // Add branches with and without scope delimited tokens.