use of org.eclipse.collections.impl.test.domain.Person in project eclipse-collections by eclipse.
the class UnifiedSetWithHashingStrategyTest method addALLIterable_with_hashingStrategy.
@Test
public void addALLIterable_with_hashingStrategy() {
UnifiedSetWithHashingStrategy<Person> people = UnifiedSetWithHashingStrategy.newSet(HashingStrategies.nullSafeHashingStrategy(LAST_NAME_HASHING_STRATEGY), 2);
// Testing adding an iterable
Assert.assertTrue(people.addAllIterable(PEOPLE));
Verify.assertSetsEqual(UnifiedSet.newSet(LAST_NAME_HASHED_SET), people);
// Testing the set uses its own hashing strategy and not the target sets
Assert.assertFalse(people.addAllIterable(UnifiedSetWithHashingStrategy.newSet(FIRST_NAME_HASHING_STRATEGY, PEOPLE)));
Verify.assertSize(2, people);
// Testing adding with null where the call to addALLIterable forces a rehash
Person notInSet = new Person("Not", "InSet");
Assert.assertTrue(people.addAllIterable(UnifiedSet.newSetWith(notInSet, null)));
Verify.assertSetsEqual(UnifiedSet.newSet(LAST_NAME_HASHED_SET).with(notInSet, null), people);
// Testing addAllIterable throws NullPointerException if the hashingStrategy is not null safe
Verify.assertThrows(NullPointerException.class, () -> UnifiedSetWithHashingStrategy.newSet(LAST_NAME_HASHING_STRATEGY).addAllIterable(UnifiedSet.newSetWith((Person) null)));
}
use of org.eclipse.collections.impl.test.domain.Person in project eclipse-collections by eclipse.
the class UnifiedSetWithHashingStrategyTest method put_with_hashingStrategy.
@Test
public void put_with_hashingStrategy() {
UnifiedSetWithHashingStrategy<Person> people = UnifiedSetWithHashingStrategy.newSet(HashingStrategies.nullSafeHashingStrategy(LAST_NAME_HASHING_STRATEGY), 2).withAll(PEOPLE.castToList());
// Testing if element already exists, returns the instance in the set
Assert.assertSame(JOHNSMITH, people.put(new Person("Anything", "Smith")));
Verify.assertSize(2, people);
// Testing if the element doesn't exist, returns the element itself
Person notInSet = new Person("Not", "inSet");
Assert.assertSame(notInSet, people.put(notInSet));
Verify.assertSize(3, people);
// Testing putting a null to force a rehash
Assert.assertNull(people.put(null));
Verify.assertSize(4, people);
// Testing put throws NullPointerException if the hashingStrategy is not null safe
Verify.assertThrows(NullPointerException.class, () -> UnifiedSetWithHashingStrategy.newSet(LAST_NAME_HASHING_STRATEGY).put(null));
}
use of org.eclipse.collections.impl.test.domain.Person in project eclipse-collections by eclipse.
the class AbstractSortedSetTestCase method zipWithIndex.
@Override
@Test
public void zipWithIndex() {
super.zipWithIndex();
MutableSortedSet<Integer> integers = this.newWith(Collections.reverseOrder(), 1, 3, 5, 2, 4);
Iterator<Pair<Integer, Integer>> zip = integers.zipWithIndex().iterator();
for (int i = 5; i > 0; --i) {
Assert.assertEquals(Tuples.pair(i, 5 - i), zip.next());
}
Person john = new Person("John", "Smith");
Person jane = new Person("Jane", "Smith");
Person johnDoe = new Person("John", "Doe");
MutableSortedSet<Person> people = this.newWith(Collections.reverseOrder(), john, johnDoe, jane);
MutableSortedSet<Pair<Person, Integer>> pairs = people.zipWithIndex();
Verify.assertListsEqual(Lists.mutable.with(Tuples.pair(john, 0), Tuples.pair(johnDoe, 1)), pairs.toList());
}
use of org.eclipse.collections.impl.test.domain.Person in project eclipse-collections by eclipse.
the class AbstractSortedSetTestCase method zip.
@Override
@Test
public void zip() {
super.zip();
MutableSortedSet<Integer> revInt = this.newWith(Collections.reverseOrder(), 2, 3, 5, 1, 4);
MutableSortedSet<Integer> integers = this.newWith(1, 3, 2, 4, 5);
MutableList<Pair<Integer, Integer>> zip = integers.zip(revInt);
MutableList<Pair<Integer, Integer>> revZip = revInt.zip(integers);
Verify.assertSize(5, zip);
Verify.assertSize(5, revZip);
Iterator<Pair<Integer, Integer>> zipItr = zip.iterator();
Iterator<Pair<Integer, Integer>> revZipItr = revZip.iterator();
for (int i = 1; i < 6; ++i) {
Assert.assertEquals(Tuples.pair(i, 6 - i), zipItr.next());
Assert.assertEquals(Tuples.pair(6 - i, i), revZipItr.next());
}
Person john = new Person("John", "Smith");
Person jane = new Person("Jane", "Smith");
Person johnDoe = new Person("John", "Doe");
MutableSortedSet<Person> people = this.newWith(john, johnDoe);
MutableList<Holder> list = Lists.mutable.with(new Holder(1), new Holder(2), new Holder(3));
MutableList<Pair<Person, Holder>> pairs = people.zip(list);
Assert.assertEquals(Lists.mutable.with(Tuples.pair(johnDoe, new Holder(1)), Tuples.pair(john, new Holder(2))), pairs.toList());
Assert.assertTrue(pairs.add(Tuples.pair(new Person("Jack", "Baker"), new Holder(3))));
Assert.assertEquals(Tuples.pair(new Person("Jack", "Baker"), new Holder(3)), pairs.getLast());
}
use of org.eclipse.collections.impl.test.domain.Person in project eclipse-collections by eclipse.
the class UnifiedSetWithHashingStrategyMultimapTest method testMultimapConstructor.
@Test
public void testMultimapConstructor() {
MutableSetMultimap<Integer, Person> map = UnifiedSetMultimap.newMultimap();
UnifiedSetWithHashingStrategyMultimap<Integer, Person> map2 = UnifiedSetWithHashingStrategyMultimap.newMultimap(LAST_NAME_STRATEGY);
for (Person person : PEOPLE) {
map.put(1, person);
map2.put(1, person);
}
UnifiedSetWithHashingStrategyMultimap<Integer, Person> hashingMap = UnifiedSetWithHashingStrategyMultimap.newMultimap(LAST_NAME_STRATEGY, map);
UnifiedSetWithHashingStrategyMultimap<Integer, Person> hashingMap2 = UnifiedSetWithHashingStrategyMultimap.newMultimap(map2);
Verify.assertSetsEqual(hashingMap.get(1), hashingMap2.get(1));
Assert.assertSame(hashingMap.getValueHashingStrategy(), hashingMap2.getValueHashingStrategy());
}
Aggregations