Search in sources :

Example 1 with PrimitiveCollection

use of org.neo4j.collection.primitive.PrimitiveCollection in project neo4j by neo4j.

the class PrimitiveCollectionEqualityTest method addingTheSameValuesMustProduceEqualCollections.

@Theory
public void addingTheSameValuesMustProduceEqualCollections(ValueProducer values, Factory<PrimitiveCollection> factoryA, Factory<PrimitiveCollection> factoryB) {
    assumeTrue(values.isApplicable(factoryA));
    assumeTrue(values.isApplicable(factoryB));
    try (PrimitiveCollection a = factoryA.newInstance();
        PrimitiveCollection b = factoryB.newInstance()) {
        Value value = values.randomValue();
        value.add(a);
        value.add(b);
        assertEquals(a, b);
    }
}
Also used : PrimitiveCollection(org.neo4j.collection.primitive.PrimitiveCollection) Theory(org.junit.experimental.theories.Theory)

Example 2 with PrimitiveCollection

use of org.neo4j.collection.primitive.PrimitiveCollection in project neo4j by neo4j.

the class PrimitiveCollectionEqualityTest method capacityDifferencesMustNotInfluenceEquality.

@Theory
public void capacityDifferencesMustNotInfluenceEquality(ValueProducer values, Factory<PrimitiveCollection> factoryA, Factory<PrimitiveCollection> factoryB) {
    assumeTrue(values.isApplicable(factoryA));
    assumeTrue(values.isApplicable(factoryB));
    try (PrimitiveCollection a = factoryA.newInstance();
        PrimitiveCollection b = factoryB.newInstance()) {
        List<Value> tmps = new ArrayList<>();
        for (int i = 0; i < 5000; i++) {
            Value value = values.randomValue();
            value.add(b);
            tmps.add(value);
        }
        Value specificValue = values.randomValue();
        specificValue.add(a);
        specificValue.add(b);
        for (int i = 0; i < 5000; i++) {
            Value value = values.randomValue();
            value.add(b);
            tmps.add(value);
        }
        Collections.shuffle(tmps);
        for (Value value : tmps) {
            value.remove(b);
        }
        assertEquals(a, b);
    }
}
Also used : ArrayList(java.util.ArrayList) PrimitiveCollection(org.neo4j.collection.primitive.PrimitiveCollection) DataPoint(org.junit.experimental.theories.DataPoint) Theory(org.junit.experimental.theories.Theory)

Example 3 with PrimitiveCollection

use of org.neo4j.collection.primitive.PrimitiveCollection in project neo4j by neo4j.

the class PrimitiveCollectionEqualityTest method emptyCollectionsAreEqual.

@Theory
public void emptyCollectionsAreEqual(ValueProducer values, Factory<PrimitiveCollection> factoryA, Factory<PrimitiveCollection> factoryB) {
    assumeTrue(values.isApplicable(factoryA));
    assumeTrue(values.isApplicable(factoryB));
    try (PrimitiveCollection a = factoryA.newInstance();
        PrimitiveCollection b = factoryB.newInstance()) {
        assertEquals(a, b);
    }
}
Also used : PrimitiveCollection(org.neo4j.collection.primitive.PrimitiveCollection) Theory(org.junit.experimental.theories.Theory)

Example 4 with PrimitiveCollection

use of org.neo4j.collection.primitive.PrimitiveCollection in project neo4j by neo4j.

the class PrimitiveCollectionEqualityTest method differentButEquivalentMutationsShouldProduceEqualCollections.

@Theory
public void differentButEquivalentMutationsShouldProduceEqualCollections(ValueProducer values, Factory<PrimitiveCollection> factoryA, Factory<PrimitiveCollection> factoryB) {
    // Note that this test, cute as it is, also verifies that the hashCode implementation is order-invariant :)
    assumeTrue(values.isApplicable(factoryA));
    assumeTrue(values.isApplicable(factoryB));
    try (PrimitiveCollection a = factoryA.newInstance();
        PrimitiveCollection b = factoryB.newInstance()) {
        Value x = values.randomValue();
        Value y = values.randomValue();
        Value z = values.randomValue();
        x.add(a);
        z.add(a);
        z.add(b);
        y.add(b);
        x.add(b);
        y.remove(b);
        assertEquals(a, b);
    }
}
Also used : PrimitiveCollection(org.neo4j.collection.primitive.PrimitiveCollection) Theory(org.junit.experimental.theories.Theory)

Example 5 with PrimitiveCollection

use of org.neo4j.collection.primitive.PrimitiveCollection in project neo4j by neo4j.

the class PrimitiveCollectionEqualityTest method addingDifferentValuesMustProduceUnequalCollections.

@Theory
public void addingDifferentValuesMustProduceUnequalCollections(ValueProducer values, Factory<PrimitiveCollection> factoryA, Factory<PrimitiveCollection> factoryB) {
    assumeTrue(values.isApplicable(factoryA));
    assumeTrue(values.isApplicable(factoryB));
    try (PrimitiveCollection a = factoryA.newInstance();
        PrimitiveCollection b = factoryB.newInstance()) {
        values.randomValue().add(a);
        values.randomValue().add(b);
        assertNotEquals(a, b);
    }
}
Also used : PrimitiveCollection(org.neo4j.collection.primitive.PrimitiveCollection) 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