Search in sources :

Example 1 with Doubles

use of java8.lang.Doubles in project streamsupport by stefan-zobel.

the class DoubleAccumulatorTest method testFloatValue.

/**
 * floatValue returns current value.
 */
public void testFloatValue() {
    DoubleAccumulator acc = new DoubleAccumulator(Doubles::max, 0.0);
    assertEquals(0.0f, acc.floatValue());
    acc.accumulate(1.0);
    assertEquals(1.0f, acc.floatValue());
}
Also used : Doubles(java8.lang.Doubles) DoubleAccumulator(java8.util.concurrent.atomic.DoubleAccumulator)

Example 2 with Doubles

use of java8.lang.Doubles in project streamsupport by stefan-zobel.

the class DoubleAccumulatorTest method testGetThenReset.

/**
 * getThenReset() returns current value; subsequent get() returns zero
 */
public void testGetThenReset() {
    DoubleAccumulator acc = new DoubleAccumulator(Doubles::max, 0.0);
    acc.accumulate(2.0);
    assertEquals(2.0, acc.get());
    assertEquals(2.0, acc.getThenReset());
    assertEquals(0.0, acc.get());
}
Also used : Doubles(java8.lang.Doubles) DoubleAccumulator(java8.util.concurrent.atomic.DoubleAccumulator)

Example 3 with Doubles

use of java8.lang.Doubles in project streamsupport by stefan-zobel.

the class DoubleAccumulatorTest method testReset.

/**
 * reset() causes subsequent get() to return zero
 */
public void testReset() {
    DoubleAccumulator acc = new DoubleAccumulator(Doubles::max, 0.0);
    acc.accumulate(2.0);
    assertEquals(2.0, acc.get());
    acc.reset();
    assertEquals(0.0, acc.get());
}
Also used : Doubles(java8.lang.Doubles) DoubleAccumulator(java8.util.concurrent.atomic.DoubleAccumulator)

Example 4 with Doubles

use of java8.lang.Doubles in project streamsupport by stefan-zobel.

the class DoubleAccumulatorTest method testIntValue.

/**
 * intValue returns current value.
 */
public void testIntValue() {
    DoubleAccumulator acc = new DoubleAccumulator(Doubles::max, 0.0);
    assertEquals(0, acc.intValue());
    acc.accumulate(1.0);
    assertEquals(1, acc.intValue());
}
Also used : Doubles(java8.lang.Doubles) DoubleAccumulator(java8.util.concurrent.atomic.DoubleAccumulator)

Example 5 with Doubles

use of java8.lang.Doubles in project streamsupport by stefan-zobel.

the class SplittableRandomTest method testDoublesCount.

/**
 * A parallel sized stream of doubles generates the given number of values
 */
public void testDoublesCount() {
    LongAdder counter = new LongAdder();
    SplittableRandom r = new SplittableRandom();
    long size = 0;
    for (int reps = 0; reps < REPS; ++reps) {
        counter.reset();
        r.doubles(size).parallel().forEach(x -> counter.increment());
        assertEquals(size, counter.sum());
        size += 524959;
    }
}
Also used : LongAdder(java8.util.concurrent.atomic.LongAdder) SplittableRandom(java8.util.SplittableRandom)

Aggregations

SplittableRandom (java8.util.SplittableRandom)13 ThreadLocalRandom (java8.util.concurrent.ThreadLocalRandom)12 LongAdder (java8.util.concurrent.atomic.LongAdder)12 Doubles (java8.lang.Doubles)8 DoubleAccumulator (java8.util.concurrent.atomic.DoubleAccumulator)8 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 DoubleConsumer (java8.util.function.DoubleConsumer)4 ArrayList (java.util.ArrayList)1 Comparator (java.util.Comparator)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Set (java.util.Set)1 Spliterator (java8.util.Spliterator)1 Spliterators (java8.util.Spliterators)1 Consumer (java8.util.function.Consumer)1 Function (java8.util.function.Function)1 DoubleStream (java8.util.stream.DoubleStream)1 DoubleStreamTestScenario (java8.util.stream.DoubleStreamTestScenario)1 IntStream (java8.util.stream.IntStream)1 IntStreamTestScenario (java8.util.stream.IntStreamTestScenario)1