Search in sources :

Example 11 with LongLongMap

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

the class AbstractLongLongMapTestCase method average.

@Test
public void average() {
    LongLongMap map = this.newWithKeysValues(0L, 0L, 1L, 1L, 2L, 2L, 3L, 3L);
    Assert.assertEquals(1.5, map.average(), 0.0);
    LongLongMap map1 = this.newWithKeysValues(1L, 1L);
    Assert.assertEquals(1.0, map1.average(), 0.0);
}
Also used : ImmutableLongLongMap(org.eclipse.collections.api.map.primitive.ImmutableLongLongMap) LongLongMap(org.eclipse.collections.api.map.primitive.LongLongMap) Test(org.junit.Test)

Example 12 with LongLongMap

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

the class AbstractLongLongMapTestCase method sum.

@Test
public void sum() {
    LongLongMap map = this.newWithKeysValues(0L, 0L, 1L, 1L, 2L, 2L, 3L, 3L);
    Assert.assertEquals(6L, map.sum());
    LongLongMap map2 = this.newWithKeysValues(2L, 2L, 3L, 3L, 4L, 4L);
    Assert.assertEquals(9L, map2.sum());
    LongLongMap map3 = this.newWithKeysValues(2L, 2L);
    Assert.assertEquals(2L, map3.sum());
}
Also used : ImmutableLongLongMap(org.eclipse.collections.api.map.primitive.ImmutableLongLongMap) LongLongMap(org.eclipse.collections.api.map.primitive.LongLongMap) Test(org.junit.Test)

Example 13 with LongLongMap

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

the class AbstractLongLongMapTestCase method appendString.

@Test
public void appendString() {
    Appendable appendable = new StringBuilder();
    this.getEmptyMap().appendString(appendable);
    Assert.assertEquals("", appendable.toString());
    this.getEmptyMap().appendString(appendable, "/");
    Assert.assertEquals("", appendable.toString());
    this.getEmptyMap().appendString(appendable, "{", "/", "}");
    Assert.assertEquals("{}", appendable.toString());
    Appendable appendable0 = new StringBuilder();
    this.newWithKeysValues(0L, 0L).appendString(appendable0);
    Assert.assertEquals("0", appendable0.toString());
    Appendable appendable01 = new StringBuilder();
    this.newWithKeysValues(0L, 0L).appendString(appendable01, "/");
    Assert.assertEquals("0", appendable01.toString());
    Appendable appendable02 = new StringBuilder();
    this.newWithKeysValues(0L, 0L).appendString(appendable02, "{", "/", "}");
    Assert.assertEquals("{0}", appendable02.toString());
    Appendable appendable1 = new StringBuilder();
    this.newWithKeysValues(1L, 1L).appendString(appendable1);
    Assert.assertEquals("1", appendable1.toString());
    Appendable appendable2 = new StringBuilder();
    this.newWithKeysValues(5L, 5L).appendString(appendable2);
    Assert.assertEquals("5", appendable2.toString());
    Appendable appendable3 = new StringBuilder();
    LongLongMap map1 = this.newWithKeysValues(0L, 0L, 1L, 1L);
    map1.appendString(appendable3);
    Assert.assertTrue(appendable3.toString(), "0, 1".equals(appendable3.toString()) || "1, 0".equals(appendable3.toString()));
    Appendable appendable4 = new StringBuilder();
    LongLongMap map2 = this.newWithKeysValues(1L, 1L, 32L, 32L);
    map2.appendString(appendable4, "[", "/", "]");
    Assert.assertTrue(appendable4.toString(), "[1/32]".equals(appendable4.toString()) || "[32/1]".equals(appendable4.toString()));
    Appendable appendable5 = new StringBuilder();
    LongLongMap map3 = this.newWithKeysValues(1L, 1L, 32L, 32L);
    map3.appendString(appendable5, "[", "/", "]");
    Assert.assertTrue(appendable5.toString(), "[1/32]".equals(appendable5.toString()) || "[32/1]".equals(appendable5.toString()));
    Appendable appendable6 = new StringBuilder();
    map1.appendString(appendable6, "/");
    Assert.assertTrue(appendable6.toString(), "0/1".equals(appendable6.toString()) || "1/0".equals(appendable6.toString()));
}
Also used : ImmutableLongLongMap(org.eclipse.collections.api.map.primitive.ImmutableLongLongMap) LongLongMap(org.eclipse.collections.api.map.primitive.LongLongMap) Test(org.junit.Test)

Example 14 with LongLongMap

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

the class AbstractLongLongMapTestCase method toBag.

@Test
public void toBag() {
    LongLongMap map = this.newWithKeysValues(0L, 0L, 1L, 1L, 2L, 2L, 3L, 3L);
    Assert.assertEquals(LongHashBag.newBagWith(0L, 1L, 2L, 3L), map.toBag());
    Assert.assertEquals(LongHashBag.newBagWith(), this.getEmptyMap().toBag());
    Assert.assertEquals(LongHashBag.newBagWith(1L), this.newWithKeysValues(1L, 1L).toBag());
}
Also used : ImmutableLongLongMap(org.eclipse.collections.api.map.primitive.ImmutableLongLongMap) LongLongMap(org.eclipse.collections.api.map.primitive.LongLongMap) Test(org.junit.Test)

Example 15 with LongLongMap

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

the class AbstractLongLongMapTestCase method select.

@Test
public void select() {
    LongLongMap map = this.newWithKeysValues(0L, 0L, 1L, 1L, 2L, 2L, 3L, 3L);
    LongLongMap actual1 = map.select((long key, long value) -> key == 1L || value == 3L);
    Assert.assertEquals(LongLongHashMap.newWithKeysValues(1L, 1L, 3L, 3L), actual1);
    LongLongMap actual2 = map.select((long key, long value) -> key == 0L || value == 2L);
    Assert.assertEquals(LongLongHashMap.newWithKeysValues(0L, 0L, 2L, 2L), actual2);
}
Also used : ImmutableLongLongMap(org.eclipse.collections.api.map.primitive.ImmutableLongLongMap) LongLongMap(org.eclipse.collections.api.map.primitive.LongLongMap) Test(org.junit.Test)

Aggregations

ImmutableLongLongMap (org.eclipse.collections.api.map.primitive.ImmutableLongLongMap)30 LongLongMap (org.eclipse.collections.api.map.primitive.LongLongMap)30 Test (org.junit.Test)30 LazyLongIterable (org.eclipse.collections.api.LazyLongIterable)3 LongIterable (org.eclipse.collections.api.LongIterable)3 Arrays (java.util.Arrays)1 NoSuchElementException (java.util.NoSuchElementException)1 MutableBag (org.eclipse.collections.api.bag.MutableBag)1 LongToObjectFunction (org.eclipse.collections.api.block.function.primitive.LongToObjectFunction)1 LongIterator (org.eclipse.collections.api.iterator.LongIterator)1 MutableLongSet (org.eclipse.collections.api.set.primitive.MutableLongSet)1 LongLongPair (org.eclipse.collections.api.tuple.primitive.LongLongPair)1 LongHashBag (org.eclipse.collections.impl.bag.mutable.primitive.LongHashBag)1 LongPredicates (org.eclipse.collections.impl.block.factory.primitive.LongPredicates)1 Bags (org.eclipse.collections.impl.factory.Bags)1 LongBags (org.eclipse.collections.impl.factory.primitive.LongBags)1 LongLongMaps (org.eclipse.collections.impl.factory.primitive.LongLongMaps)1 LongArrayList (org.eclipse.collections.impl.list.mutable.primitive.LongArrayList)1 LongLongHashMap (org.eclipse.collections.impl.map.mutable.primitive.LongLongHashMap)1 LongHashSet (org.eclipse.collections.impl.set.mutable.primitive.LongHashSet)1