Skip to content

Commit

Permalink
working towards aligning the spec with the impl
Browse files Browse the repository at this point in the history
  • Loading branch information
jurgenvinju committed Oct 14, 2023
1 parent 4506b14 commit 970b1e7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/main/java/io/usethesource/vallang/INode.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public interface INode extends IValue, Iterable<IValue> {
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();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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());
}
}
Expand Down

0 comments on commit 970b1e7

Please sign in to comment.