Search in sources :

Example 6 with PrimitiveCollection

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)));
    }
}
Also used : PrimitiveCollection(org.neo4j.collection.primitive.PrimitiveCollection) DataPoint(org.junit.experimental.theories.DataPoint) Theory(org.junit.experimental.theories.Theory)

Aggregations

Theory (org.junit.experimental.theories.Theory)6 PrimitiveCollection (org.neo4j.collection.primitive.PrimitiveCollection)6 DataPoint (org.junit.experimental.theories.DataPoint)2 ArrayList (java.util.ArrayList)1