diff --git a/src/main/java/io/usethesource/vallang/INode.java b/src/main/java/io/usethesource/vallang/INode.java index 7b8b0993..b6698188 100644 --- a/src/main/java/io/usethesource/vallang/INode.java +++ b/src/main/java/io/usethesource/vallang/INode.java @@ -35,7 +35,7 @@ public interface INode extends IValue, Iterable { default int getMatchFingerprint() { int hash = getName().hashCode(); - return hash == 0 ? 3386882 /* node.hashCode() */ + arity() : hash << 2 + arity(); + return hash == 0 ? 13547528 /* "node".hashCode() << 2*/ + arity() : hash << 2 + arity(); } /** diff --git a/src/test/java/io/usethesource/vallang/specification/IValueTests.java b/src/test/java/io/usethesource/vallang/specification/IValueTests.java index ef01c947..3ef4fe98 100644 --- a/src/test/java/io/usethesource/vallang/specification/IValueTests.java +++ b/src/test/java/io/usethesource/vallang/specification/IValueTests.java @@ -73,11 +73,19 @@ public void testDefaultFingerprintContracts(IValue val1) { @ParameterizedTest @ArgumentsSource(ValueProvider.class) public void testFingerprintStabilityIntegersDoNotChangeTheTest(IValueFactory vf, IInteger integer) { assertEquals(integer.equals(vf.integer(0)) ? "int".hashCode() : integer.hashCode(), integer.getMatchFingerprint()); + + // this should stay or we have to make sure that the fingerprint works like that again + // if it changes + if (integer.less(vf.integer(Integer.MAX_VALUE)).getValue()) { + assertEquals(integer.intValue(), integer.hashCode()); + } } @ParameterizedTest @ArgumentsSource(ValueProvider.class) public void testFingerprintStabilityStringDoNotChangeTheTest(IString string) { assertEquals(string.length() == 0 ? "str".hashCode() : string.hashCode(), string.getMatchFingerprint()); + + } @ParameterizedTest @ArgumentsSource(ValueProvider.class) @@ -122,7 +130,7 @@ public void testFingerprintAllMapsTheSameDoNotChangeTheTest(IMap map1, IMap map2 @ParameterizedTest @ArgumentsSource(ValueProvider.class) public void testFingerprintStabilityTupleDoNotChangeTheTest(ITuple tuple) { - assertEquals("tuple".hashCode() << 2 + tuple.arity(), tuple.getMatchFingerprint()); + assertEquals(("tuple".hashCode() << 2) + tuple.arity(), tuple.getMatchFingerprint()); } @ParameterizedTest @ArgumentsSource(ValueProvider.class) @@ -139,12 +147,12 @@ public void testFingerprintStabilityNodeDoNotChangeTheTest(ISourceLocation node) @ParameterizedTest @ArgumentsSource(ValueProvider.class) public void testFingerprintStabilityNodeDoNotChangeTheTest(INode node) { - assertEquals(node.hashCode() == 0 ? "node".hashCode() << 2 + node.arity() : node.hashCode() << 2 + node.arity(), node.getMatchFingerprint()); + assertEquals(node.hashCode() == 0 ? ("node".hashCode() << 2) + node.arity() : (node.getName().hashCode() << 2) + node.arity(), node.getMatchFingerprint()); } @ParameterizedTest @ArgumentsSource(ValueProvider.class) public void testFingerprintEqualArityNodesTheSameDoNotChangeTheTest(INode node1, INode node2) { - if (node1.arity() == node2.arity()) { + if (node1.arity() == node2.arity() && node1.getName().equals(node2.getName())) { assertEquals(node1.getMatchFingerprint(), node2.getMatchFingerprint()); } }