Search in sources :

Example 21 with MutableLongLongMap

use of org.eclipse.collections.api.map.primitive.MutableLongLongMap in project mapdb by jankotek.

the class AbstractMutableLongLongMapTestCase method addToValue.

@Test
public void addToValue() {
    MutableLongLongMap map1 = this.getEmptyMap();
    Assert.assertEquals(1L, map1.addToValue(0L, 1L));
    Assert.assertEquals(32L, map1.addToValue(31L, 32L));
    Assert.assertEquals(3L, map1.addToValue(1L, 3L));
    Assert.assertEquals(11L, map1.addToValue(0L, 10L));
    Assert.assertEquals(12L, map1.addToValue(1L, 9L));
    Assert.assertEquals(37L, map1.addToValue(31L, 5L));
    Assert.assertEquals(33L, map1.addToValue(32L, 33L));
    LongLongHashMap expected = LongLongHashMap.newWithKeysValues(0L, 11L, 1L, 12L, 31L, 37L, 32L, 33L);
    Assert.assertEquals(expected, map1);
    map1.removeKey(0L);
    map1.removeKey(1L);
    map1.removeKey(31L);
    map1.removeKey(32L);
    Assert.assertEquals(5L, map1.addToValue(31L, 5L));
    Assert.assertEquals(37L, map1.addToValue(31L, 32L));
    Assert.assertEquals(33L, map1.addToValue(32L, 33L));
    Assert.assertEquals(3L, map1.addToValue(1L, 3L));
    Assert.assertEquals(1L, map1.addToValue(0L, 1L));
    Assert.assertEquals(12L, map1.addToValue(1L, 9L));
    Assert.assertEquals(11L, map1.addToValue(0L, 10L));
    Assert.assertEquals(expected, map1);
}
Also used : LongLongHashMap(org.eclipse.collections.impl.map.mutable.primitive.LongLongHashMap) MutableLongLongMap(org.eclipse.collections.api.map.primitive.MutableLongLongMap) Test(org.junit.Test)

Example 22 with MutableLongLongMap

use of org.eclipse.collections.api.map.primitive.MutableLongLongMap in project mapdb by jankotek.

the class AbstractMutableLongLongMapTestCase method getIfAbsentPut_Function.

@Test
public void getIfAbsentPut_Function() {
    LongFunction0 factory = () -> 100L;
    LongFunction0 factoryThrows = () -> {
        throw new AssertionError();
    };
    MutableLongLongMap map1 = this.getEmptyMap();
    Assert.assertEquals(100L, map1.getIfAbsentPut(0L, factory));
    Assert.assertEquals(100L, map1.getIfAbsentPut(0L, factoryThrows));
    Assert.assertEquals(LongLongHashMap.newWithKeysValues(0L, 100L), map1);
    Assert.assertEquals(100L, map1.getIfAbsentPut(1L, factory));
    Assert.assertEquals(100L, map1.getIfAbsentPut(1L, factoryThrows));
    Assert.assertEquals(LongLongHashMap.newWithKeysValues(0L, 100L, 1L, 100L), map1);
    MutableLongLongMap map2 = this.getEmptyMap();
    Assert.assertEquals(100L, map2.getIfAbsentPut(1L, factory));
    Assert.assertEquals(100L, map2.getIfAbsentPut(1L, factoryThrows));
    Assert.assertEquals(LongLongHashMap.newWithKeysValues(1L, 100L), map2);
    Assert.assertEquals(100L, map2.getIfAbsentPut(0L, factory));
    Assert.assertEquals(100L, map2.getIfAbsentPut(0L, factoryThrows));
    Assert.assertEquals(LongLongHashMap.newWithKeysValues(0L, 100L, 1L, 100L), map2);
    MutableLongLongMap map3 = this.getEmptyMap();
    Assert.assertEquals(100L, map3.getIfAbsentPut(32L, factory));
    Assert.assertEquals(100L, map3.getIfAbsentPut(32L, factoryThrows));
    Assert.assertEquals(LongLongHashMap.newWithKeysValues(32L, 100L), map3);
    MutableLongLongMap map4 = this.getEmptyMap();
    Assert.assertEquals(100L, map4.getIfAbsentPut(33L, factory));
    Assert.assertEquals(100L, map4.getIfAbsentPut(33L, factoryThrows));
    Assert.assertEquals(LongLongHashMap.newWithKeysValues(33L, 100L), map4);
}
Also used : LongFunction0(org.eclipse.collections.api.block.function.primitive.LongFunction0) MutableLongLongMap(org.eclipse.collections.api.map.primitive.MutableLongLongMap) Test(org.junit.Test)

Example 23 with MutableLongLongMap

use of org.eclipse.collections.api.map.primitive.MutableLongLongMap in project mapdb by jankotek.

the class AbstractMutableLongLongMapTestCase method longIterator_with_remove.

@Test
public void longIterator_with_remove() {
    MutableLongLongMap mutableMap = this.classUnderTest();
    MutableLongIterator iterator = mutableMap.longIterator();
    while (iterator.hasNext()) {
        iterator.next();
        iterator.remove();
    }
    Assert.assertFalse(iterator.hasNext());
    Verify.assertEmpty(mutableMap);
    Verify.assertThrows(NoSuchElementException.class, iterator::next);
}
Also used : MutableLongLongMap(org.eclipse.collections.api.map.primitive.MutableLongLongMap) MutableLongIterator(org.eclipse.collections.api.iterator.MutableLongIterator) Test(org.junit.Test)

Example 24 with MutableLongLongMap

use of org.eclipse.collections.api.map.primitive.MutableLongLongMap in project mapdb by jankotek.

the class AbstractMutableLongLongMapTestCase method remove.

@Test
public void remove() {
    MutableLongLongMap map0 = this.newWithKeysValues(0L, 0L, 1L, 1L);
    map0.remove(1L);
    Assert.assertEquals(LongLongHashMap.newWithKeysValues(0L, 0L), map0);
    map0.remove(0L);
    Assert.assertEquals(new LongLongHashMap(), map0);
    MutableLongLongMap map1 = this.newWithKeysValues(0L, 0L, 1L, 1L);
    map1.remove(0L);
    Assert.assertEquals(LongLongHashMap.newWithKeysValues(1L, 1L), map1);
    map1.remove(1L);
    Assert.assertEquals(new LongLongHashMap(), map1);
    MutableLongLongMap map2 = this.classUnderTest();
    map2.remove(5L);
    map2.remove(50L);
    Assert.assertEquals(LongLongHashMap.newWithKeysValues(0L, 0L, 31L, 31L, 32L, 32L), map2);
    map2.remove(0L);
    Assert.assertEquals(LongLongHashMap.newWithKeysValues(31L, 31L, 32L, 32L), map2);
    map2.remove(31L);
    Assert.assertEquals(LongLongHashMap.newWithKeysValues(32L, 32L), map2);
    map2.remove(32L);
    Assert.assertEquals(new LongLongHashMap(), map2);
    map2.remove(0L);
    map2.remove(31L);
    map2.remove(32L);
    Assert.assertEquals(new LongLongHashMap(), map2);
    Verify.assertEmpty(map2);
    map2.put(AbstractMutableLongLongMapTestCase.generateCollisions().get(0), 1L);
    map2.put(AbstractMutableLongLongMapTestCase.generateCollisions().get(1), 2L);
    Assert.assertEquals(1L, map2.get(AbstractMutableLongLongMapTestCase.generateCollisions().get(0)));
    map2.remove(AbstractMutableLongLongMapTestCase.generateCollisions().get(0));
    Assert.assertEquals(0L, map2.get(AbstractMutableLongLongMapTestCase.generateCollisions().get(0)));
    Assert.assertEquals(2L, map2.get(AbstractMutableLongLongMapTestCase.generateCollisions().get(1)));
    map2.remove(AbstractMutableLongLongMapTestCase.generateCollisions().get(1));
    Assert.assertEquals(0L, map2.get(AbstractMutableLongLongMapTestCase.generateCollisions().get(1)));
}
Also used : LongLongHashMap(org.eclipse.collections.impl.map.mutable.primitive.LongLongHashMap) MutableLongLongMap(org.eclipse.collections.api.map.primitive.MutableLongLongMap) Test(org.junit.Test)

Example 25 with MutableLongLongMap

use of org.eclipse.collections.api.map.primitive.MutableLongLongMap in project mapdb by jankotek.

the class AbstractMutableLongLongMapTestCase method clear.

@Test
public void clear() {
    MutableLongLongMap map1 = this.classUnderTest();
    map1.clear();
    Assert.assertEquals(new LongLongHashMap(), map1);
    map1.put(1L, 0L);
    Assert.assertEquals(LongLongHashMap.newWithKeysValues(1L, 0L), map1);
    map1.clear();
    Assert.assertEquals(new LongLongHashMap(), map1);
    map1.put(33L, 0L);
    Assert.assertEquals(LongLongHashMap.newWithKeysValues(33L, 0L), map1);
    map1.clear();
    Assert.assertEquals(new LongLongHashMap(), map1);
}
Also used : LongLongHashMap(org.eclipse.collections.impl.map.mutable.primitive.LongLongHashMap) MutableLongLongMap(org.eclipse.collections.api.map.primitive.MutableLongLongMap) Test(org.junit.Test)

Aggregations

MutableLongLongMap (org.eclipse.collections.api.map.primitive.MutableLongLongMap)30 Test (org.junit.Test)30 MutableLongCollection (org.eclipse.collections.api.collection.primitive.MutableLongCollection)6 LongLongHashMap (org.eclipse.collections.impl.map.mutable.primitive.LongLongHashMap)6 LongToLongFunction (org.eclipse.collections.api.block.function.primitive.LongToLongFunction)2 LongArrayList (org.eclipse.collections.impl.list.mutable.primitive.LongArrayList)2 LongFunction0 (org.eclipse.collections.api.block.function.primitive.LongFunction0)1 MutableLongIterator (org.eclipse.collections.api.iterator.MutableLongIterator)1 LongSet (org.eclipse.collections.api.set.primitive.LongSet)1