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);
}
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);
}
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);
}
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()));
}
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);
// }
}
Aggregations