use of org.neo4j.collection.primitive.PrimitiveCollection in project neo4j by neo4j.
the class PrimitiveCollectionEqualityTest method hashCodeMustFollowValues.
@Theory
public void hashCodeMustFollowValues(ValueProducer values, Factory<PrimitiveCollection> factory) {
assumeTrue(values.isApplicable(factory));
try (PrimitiveCollection a = factory.newInstance()) {
Value x = values.randomValue();
Value y = values.randomValue();
Value z = values.randomValue();
int i = a.hashCode();
x.add(a);
int j = a.hashCode();
y.add(a);
int k = a.hashCode();
z.add(a);
int l = a.hashCode();
z.remove(a);
int m = a.hashCode();
y.remove(a);
int n = a.hashCode();
x.remove(a);
int o = a.hashCode();
assertThat("0 elm hashcode equal", o, is(i));
assertThat("1 elm hashcode equal", n, is(j));
assertThat("2 elm hashcode equal", m, is(k));
assertThat("3 elm hashcode distinct", l, not(isOneOf(i, j, k, m, n, o)));
assertThat("2 elm hashcode distinct", k, not(isOneOf(i, j, l, n, o)));
assertThat("1 elm hashcode distinct", n, not(isOneOf(i, k, l, m, o)));
assertThat("0 elm hashcode distinct", i, not(isOneOf(j, k, l, m, n)));
}
}
Aggregations