Search in sources :

Example 6 with DoubleArrayList

use of org.eclipse.collections.impl.list.mutable.primitive.DoubleArrayList in project eclipse-collections by eclipse.

the class ArrayListIterateTest method collectDoubleOverOptimizeLimit.

@Test
public void collectDoubleOverOptimizeLimit() {
    ArrayList<Integer> list = new ArrayList<>(Interval.zeroTo(OVER_OPTIMIZED_LIMIT));
    MutableDoubleList actual = ArrayListIterate.collectDouble(list, PrimitiveFunctions.unboxIntegerToDouble());
    DoubleArrayList expected = new DoubleArrayList(list.size());
    for (int i = 0; i <= OVER_OPTIMIZED_LIMIT; i++) {
        expected.add((double) i);
    }
    Assert.assertEquals(expected, actual);
}
Also used : MutableDoubleList(org.eclipse.collections.api.list.primitive.MutableDoubleList) DoubleArrayList(org.eclipse.collections.impl.list.mutable.primitive.DoubleArrayList) ShortArrayList(org.eclipse.collections.impl.list.mutable.primitive.ShortArrayList) IntArrayList(org.eclipse.collections.impl.list.mutable.primitive.IntArrayList) ByteArrayList(org.eclipse.collections.impl.list.mutable.primitive.ByteArrayList) CharArrayList(org.eclipse.collections.impl.list.mutable.primitive.CharArrayList) FloatArrayList(org.eclipse.collections.impl.list.mutable.primitive.FloatArrayList) LongArrayList(org.eclipse.collections.impl.list.mutable.primitive.LongArrayList) ArrayList(java.util.ArrayList) BooleanArrayList(org.eclipse.collections.impl.list.mutable.primitive.BooleanArrayList) DoubleArrayList(org.eclipse.collections.impl.list.mutable.primitive.DoubleArrayList) Test(org.junit.Test)

Example 7 with DoubleArrayList

use of org.eclipse.collections.impl.list.mutable.primitive.DoubleArrayList in project eclipse-collections by eclipse.

the class ArrayListIterateTest method collectDoubleWithTargetOverOptimizeLimit.

@Test
public void collectDoubleWithTargetOverOptimizeLimit() {
    ArrayList<Integer> list = new ArrayList<>(Interval.zeroTo(OVER_OPTIMIZED_LIMIT));
    MutableDoubleList target = new DoubleArrayList();
    MutableDoubleList actual = ArrayListIterate.collectDouble(list, PrimitiveFunctions.unboxIntegerToDouble(), target);
    DoubleArrayList expected = new DoubleArrayList(list.size());
    for (int i = 0; i <= OVER_OPTIMIZED_LIMIT; i++) {
        expected.add((double) i);
    }
    Assert.assertEquals(expected, actual);
    Assert.assertSame("Target sent as parameter was not returned as result", target, actual);
}
Also used : MutableDoubleList(org.eclipse.collections.api.list.primitive.MutableDoubleList) DoubleArrayList(org.eclipse.collections.impl.list.mutable.primitive.DoubleArrayList) ShortArrayList(org.eclipse.collections.impl.list.mutable.primitive.ShortArrayList) IntArrayList(org.eclipse.collections.impl.list.mutable.primitive.IntArrayList) ByteArrayList(org.eclipse.collections.impl.list.mutable.primitive.ByteArrayList) CharArrayList(org.eclipse.collections.impl.list.mutable.primitive.CharArrayList) FloatArrayList(org.eclipse.collections.impl.list.mutable.primitive.FloatArrayList) LongArrayList(org.eclipse.collections.impl.list.mutable.primitive.LongArrayList) ArrayList(java.util.ArrayList) BooleanArrayList(org.eclipse.collections.impl.list.mutable.primitive.BooleanArrayList) DoubleArrayList(org.eclipse.collections.impl.list.mutable.primitive.DoubleArrayList) Test(org.junit.Test)

Example 8 with DoubleArrayList

use of org.eclipse.collections.impl.list.mutable.primitive.DoubleArrayList in project eclipse-collections by eclipse.

the class ArrayListIterateTest method collectDoubleWithTarget.

@Test
public void collectDoubleWithTarget() {
    ArrayList<Integer> list = this.createIntegerList();
    MutableDoubleList target = new DoubleArrayList();
    MutableDoubleList actual = ArrayListIterate.collectDouble(list, PrimitiveFunctions.unboxIntegerToDouble(), target);
    Assert.assertSame("Target list sent as parameter not returned", target, actual);
    Assert.assertEquals(DoubleArrayList.newListWith(-1.0d, 0.0d, 4.0d), actual);
}
Also used : MutableDoubleList(org.eclipse.collections.api.list.primitive.MutableDoubleList) DoubleArrayList(org.eclipse.collections.impl.list.mutable.primitive.DoubleArrayList) Test(org.junit.Test)

Example 9 with DoubleArrayList

use of org.eclipse.collections.impl.list.mutable.primitive.DoubleArrayList in project eclipse-collections by eclipse.

the class IterateTest method collectDoubleWithTarget.

@Test
public void collectDoubleWithTarget() {
    this.iterables.each(each -> {
        MutableDoubleCollection expected = new DoubleArrayList();
        MutableDoubleCollection actual = Iterate.collectDouble(each, PrimitiveFunctions.unboxIntegerToDouble(), expected);
        Assert.assertTrue(actual.containsAll(1.0d, 2.0d, 3.0d, 4.0d, 5.0d));
        Assert.assertSame("Target list sent as parameter not returned", expected, actual);
    });
    Verify.assertThrows(IllegalArgumentException.class, () -> Iterate.collectDouble(null, PrimitiveFunctions.unboxIntegerToDouble(), new DoubleArrayList()));
}
Also used : MutableDoubleCollection(org.eclipse.collections.api.collection.primitive.MutableDoubleCollection) DoubleArrayList(org.eclipse.collections.impl.list.mutable.primitive.DoubleArrayList) Test(org.junit.Test)

Example 10 with DoubleArrayList

use of org.eclipse.collections.impl.list.mutable.primitive.DoubleArrayList in project narchy by automenta.

the class Rect1DTest method rect2DSearchTest.

/**
 * Use an small bounding box to ensure that only expected rectangles are returned.
 * Verifies the count returned from search AND the number of rectangles results.
 */
@Test
public void rect2DSearchTest() {
    final int entryCount = 20;
    // for (RTree.Split type : RTree.Split.values()) {
    RTree<Double> t = new RTree<>((x) -> new RectDouble1D.DefaultRect1D(x, x), 2, 3, Spatialization.DefaultSplits.LINEAR);
    for (int i = 0; i < entryCount; i++) {
        t.add((double) (i * i));
    }
    // t.forEach(x -> System.out.println(x));
    Stats s = t.stats();
    System.out.println(s);
    DoubleArrayList d = new DoubleArrayList();
    t.whileEachIntersecting(new RectDouble1D.DefaultRect1D(1, 101), d::add);
    assertEquals(10, d.size());
    System.out.println(d);
// final Rect2D searchRect = new Rect2D(5, 5, 10, 10);
// Rect2D[] results = new Rect2D[entryCount];
// 
// final int foundCount = rTree.search(searchRect, results);
// int resultCount = 0;
// for(int i = 0; i < results.length; i++) {
// if(results[i] != null) {
// resultCount++;
// }
// }
// 
// final int expectedCount = 9;
// assertEquals("[" + type + "] Search returned incorrect search result count - expected: " + expectedCount + " actual: " + foundCount, expectedCount, foundCount);
// assertEquals("[" + type + "] Search returned incorrect number of rectangles - expected: " + expectedCount + " actual: " + resultCount, expectedCount, resultCount);
// 
// // If the order of nodes in the tree changes, this test may fail while returning the correct results.
// for (int i = 0; i < resultCount; i++) {
// assertTrue("Unexpected result found", results[i].min.x == i + 2 && results[i].min.y == i + 2 && results[i].max.x == i + 5 && results[i].max.y == i + 5);
// }
}
Also used : RectDouble1D(jcog.tree.rtree.rect.RectDouble1D) Stats(jcog.tree.rtree.util.Stats) DoubleArrayList(org.eclipse.collections.impl.list.mutable.primitive.DoubleArrayList) Test(org.junit.jupiter.api.Test)

Aggregations

DoubleArrayList (org.eclipse.collections.impl.list.mutable.primitive.DoubleArrayList)20 Test (org.junit.Test)9 ArrayList (java.util.ArrayList)3 MutableDoubleCollection (org.eclipse.collections.api.collection.primitive.MutableDoubleCollection)3 MutableDoubleList (org.eclipse.collections.api.list.primitive.MutableDoubleList)3 BooleanArrayList (org.eclipse.collections.impl.list.mutable.primitive.BooleanArrayList)2 ByteArrayList (org.eclipse.collections.impl.list.mutable.primitive.ByteArrayList)2 CharArrayList (org.eclipse.collections.impl.list.mutable.primitive.CharArrayList)2 FloatArrayList (org.eclipse.collections.impl.list.mutable.primitive.FloatArrayList)2 IntArrayList (org.eclipse.collections.impl.list.mutable.primitive.IntArrayList)2 LongArrayList (org.eclipse.collections.impl.list.mutable.primitive.LongArrayList)2 ShortArrayList (org.eclipse.collections.impl.list.mutable.primitive.ShortArrayList)2 Test (org.junit.jupiter.api.Test)2 BigInteger (java.math.BigInteger)1 Distributor (jcog.math.Distributor)1 RectDouble1D (jcog.tree.rtree.rect.RectDouble1D)1 Stats (jcog.tree.rtree.util.Stats)1 DoubleIterable (org.eclipse.collections.api.DoubleIterable)1 DoubleHashBag (org.eclipse.collections.impl.bag.mutable.primitive.DoubleHashBag)1