Search in sources :

Example 11 with Person

use of org.eclipse.collections.impl.test.domain.Person in project eclipse-collections by eclipse.

the class HashingStrategiesTest method fromFunction.

@Test
public void fromFunction() {
    Person john = new Person("John", "Smith");
    Person jane = new Person("Jane", "Smith");
    HashingStrategy<Person> lastHashingStrategy = HashingStrategies.fromFunction(Person.TO_LAST);
    HashingStrategy<Person> firstHashingStrategy = HashingStrategies.fromFunction(Person.TO_FIRST);
    Assert.assertEquals("John".hashCode(), firstHashingStrategy.computeHashCode(john));
    Assert.assertNotEquals(john.hashCode(), firstHashingStrategy.computeHashCode(john));
    Assert.assertFalse(firstHashingStrategy.equals(john, jane));
    Assert.assertEquals("Smith".hashCode(), lastHashingStrategy.computeHashCode(john));
    Assert.assertNotEquals(john.hashCode(), lastHashingStrategy.computeHashCode(john));
    Assert.assertTrue(lastHashingStrategy.equals(john, jane));
    Assert.assertNotEquals(lastHashingStrategy.computeHashCode(john), firstHashingStrategy.computeHashCode(john));
    Assert.assertNotEquals(lastHashingStrategy.computeHashCode(john), firstHashingStrategy.computeHashCode(jane));
    Assert.assertEquals(lastHashingStrategy.computeHashCode(john), lastHashingStrategy.computeHashCode(jane));
}
Also used : Person(org.eclipse.collections.impl.test.domain.Person) Test(org.junit.Test)

Example 12 with Person

use of org.eclipse.collections.impl.test.domain.Person in project eclipse-collections by eclipse.

the class HashingStrategiesTest method fromFunctionsTwoArgs.

@Test
public void fromFunctionsTwoArgs() {
    Person john1 = new Person("John", "Smith");
    Person john2 = new Person("John", "Smith", 10);
    Person john3 = new Person("John", "Doe");
    HashingStrategy<Person> chainedHashingStrategy = HashingStrategies.fromFunctions(Person.TO_FIRST, Person.TO_LAST);
    Assert.assertTrue(chainedHashingStrategy.equals(john1, john2));
    Assert.assertFalse(chainedHashingStrategy.equals(john1, john3));
}
Also used : Person(org.eclipse.collections.impl.test.domain.Person) Test(org.junit.Test)

Example 13 with Person

use of org.eclipse.collections.impl.test.domain.Person in project eclipse-collections by eclipse.

the class HashingStrategiesTest method chainedHashingStrategy.

@Test
public void chainedHashingStrategy() {
    Person john1 = new Person("John", "Smith");
    Person john2 = new Person("John", "Smith");
    Person john3 = new Person("John", "Doe");
    HashingStrategy<Person> chainedHashingStrategy = HashingStrategies.chain(HashingStrategies.fromFunction(Person.TO_FIRST), HashingStrategies.fromFunction(Person.TO_LAST));
    Assert.assertTrue(chainedHashingStrategy.equals(john1, john2));
    HashingStrategy<Person> chainedHashingStrategy2 = HashingStrategies.chain(HashingStrategies.fromFunction(Person.TO_FIRST));
    Assert.assertEquals("John".hashCode(), chainedHashingStrategy2.computeHashCode(john1));
    Assert.assertTrue(chainedHashingStrategy2.equals(john1, john3));
}
Also used : Person(org.eclipse.collections.impl.test.domain.Person) Test(org.junit.Test)

Example 14 with Person

use of org.eclipse.collections.impl.test.domain.Person in project eclipse-collections by eclipse.

the class AbstractMutableSortedBagTestCase method zip.

@Override
@Test
public void zip() {
    super.zip();
    MutableSortedBag<Integer> revInt = this.newWith(Collections.reverseOrder(), 2, 2, 3, 5, 1, 4);
    MutableSortedBag<Integer> integers = this.newWith(1, 3, 2, 2, 4, 5);
    MutableList<Pair<Integer, Integer>> zip = integers.zip(revInt);
    Verify.assertSize(6, zip);
    Assert.assertEquals(FastList.newListWith(Tuples.pair(1, 5), Tuples.pair(2, 4), Tuples.pair(2, 3), Tuples.pair(3, 2), Tuples.pair(4, 2), Tuples.pair(5, 1)), zip);
    MutableList<Pair<Integer, Integer>> revZip = revInt.zip(integers);
    Verify.assertSize(6, revZip);
    Assert.assertEquals(FastList.newListWith(Tuples.pair(5, 1), Tuples.pair(4, 2), Tuples.pair(3, 2), Tuples.pair(2, 3), Tuples.pair(2, 4), Tuples.pair(1, 5)), revZip);
    Person john = new Person("John", "Smith");
    Person johnDoe = new Person("John", "Doe");
    MutableSortedBag<Person> people = this.newWith(john, johnDoe);
    MutableList<Integer> list = FastList.newListWith(1, 2, 3);
    MutableList<Pair<Person, Integer>> pairs = people.zip(list);
    Assert.assertEquals(FastList.newListWith(Tuples.pair(johnDoe, 1), Tuples.pair(john, 2)), pairs);
    Assert.assertTrue(pairs.add(Tuples.pair(new Person("Jack", "Baker"), 3)));
    Assert.assertEquals(Tuples.pair(new Person("Jack", "Baker"), 3), pairs.getLast());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Person(org.eclipse.collections.impl.test.domain.Person) ObjectIntPair(org.eclipse.collections.api.tuple.primitive.ObjectIntPair) Pair(org.eclipse.collections.api.tuple.Pair) Test(org.junit.Test)

Example 15 with Person

use of org.eclipse.collections.impl.test.domain.Person in project eclipse-collections by eclipse.

the class ComparatorsTest method chainedComparator.

@Test
public void chainedComparator() {
    Verify.assertThrows(IllegalArgumentException.class, (Runnable) Comparators::chain);
    Comparator<Person> byName = Comparators.byFunction(Person.TO_FIRST);
    Comparator<Person> byAge = Comparators.byFunction(Person.TO_AGE);
    Person fred10 = new Person("Fred", "Smith", 10);
    Person jim10 = new Person("Jim", "Smith", 10);
    Person jim16 = new Person("Jim", "Smith", 16);
    Person sheila12 = new Person("Sheila", "Smith", 12);
    Person sheila14 = new Person("Sheila", "Smith", 14);
    MutableList<Person> people = mList(jim16, fred10, sheila14, sheila12, fred10, jim10);
    MutableList<Person> expectedNameThenAgeOrder = mList(fred10, fred10, jim10, jim16, sheila12, sheila14);
    MutableList<Person> expectedAgeThenNameOrder = mList(fred10, fred10, jim10, sheila12, sheila14, jim16);
    Verify.assertListsEqual(expectedNameThenAgeOrder, people.sortThis(Comparators.chain(byName, byAge)));
    Verify.assertListsEqual(expectedAgeThenNameOrder, people.sortThis(Comparators.chain(byAge, byName)));
}
Also used : Person(org.eclipse.collections.impl.test.domain.Person) Test(org.junit.Test)

Aggregations

Person (org.eclipse.collections.impl.test.domain.Person)17 Test (org.junit.Test)17 Pair (org.eclipse.collections.api.tuple.Pair)3 ObjectIntPair (org.eclipse.collections.api.tuple.primitive.ObjectIntPair)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1