BigFloatStream { public static Stream<BigFloat> range(BigFloat startInclusive, BigFloat endExclusive, BigFloat step) { if (step.isZero()) { throw new IllegalArgumentException("invalid step: 0"); } if (endExclusive.subtract(startInclusive).signum() != step.signum()) { return Stream.empty(); } return StreamSupport.stream(new BigFloatSpliterator(startInclusive, endExclusive, false, step), false); }  static Stream<BigFloat> range(BigFloat startInclusive, BigFloat endExclusive, BigFloat step); static Stream<BigFloat> range(long startInclusive, long endExclusive, long step, Context context); static Stream<BigFloat> range(double startInclusive, double endExclusive, double step, Context context); static Stream<BigFloat> rangeClosed(BigFloat startInclusive, BigFloat endInclusive, BigFloat step); static Stream<BigFloat> rangeClosed(long startInclusive, long endInclusive, long step, Context context); static Stream<BigFloat> rangeClosed(double startInclusive, double endInclusive, double step, Context context);  }
@Test(expected = IllegalArgumentException.class) public void testRangeStepZero() { Context context = BigFloat.context(20); BigFloatStream.range(context.valueOf(0), context.valueOf(10), context.valueOf(0)); }
@Test public void testRangeStep1() { Context context = BigFloat.context(20); List<BigFloat> list = BigFloatStream.range(context.valueOf(0), context.valueOf(10), context.valueOf(1)) .collect(Collectors.toList()); assertList(list, 0, 10); }
@Test public void testRangeStep3() { Context context = BigFloat.context(20); List<BigFloat> list = BigFloatStream.range(context.valueOf(0), context.valueOf(10), context.valueOf(3)) .collect(Collectors.toList()); assertEquals(4, list.size()); assertEquals(true, list.contains(context.valueOf(0))); assertEquals(true, list.contains(context.valueOf(3))); assertEquals(true, list.contains(context.valueOf(6))); assertEquals(true, list.contains(context.valueOf(9))); assertEquals(0, BigFloatStream.range(context.valueOf(0), context.valueOf(-1), context.valueOf(3)).collect(Collectors.toList()).size()); assertEquals(0, BigFloatStream.range(context.valueOf(0), context.valueOf(0), context.valueOf(3)).collect(Collectors.toList()).size()); assertEquals(1, BigFloatStream.range(context.valueOf(0), context.valueOf(1), context.valueOf(3)).collect(Collectors.toList()).size()); assertEquals(1, BigFloatStream.range(context.valueOf(0), context.valueOf(2), context.valueOf(3)).collect(Collectors.toList()).size()); assertEquals(1, BigFloatStream.range(context.valueOf(0), context.valueOf(3), context.valueOf(3)).collect(Collectors.toList()).size()); assertEquals(2, BigFloatStream.range(context.valueOf(0), context.valueOf(4), context.valueOf(3)).collect(Collectors.toList()).size()); assertEquals(2, BigFloatStream.range(context.valueOf(0), context.valueOf(5), context.valueOf(3)).collect(Collectors.toList()).size()); assertEquals(2, BigFloatStream.range(context.valueOf(0), context.valueOf(6), context.valueOf(3)).collect(Collectors.toList()).size()); assertEquals(3, BigFloatStream.range(context.valueOf(0), context.valueOf(7), context.valueOf(3)).collect(Collectors.toList()).size()); assertEquals(3, BigFloatStream.range(context.valueOf(0), context.valueOf(8), context.valueOf(3)).collect(Collectors.toList()).size()); assertEquals(3, BigFloatStream.range(context.valueOf(0), context.valueOf(9), context.valueOf(3)).collect(Collectors.toList()).size()); assertEquals(4, BigFloatStream.range(context.valueOf(0), context.valueOf(10), context.valueOf(3)).collect(Collectors.toList()).size()); assertEquals(4, BigFloatStream.range(context.valueOf(0), context.valueOf(11), context.valueOf(3)).collect(Collectors.toList()).size()); assertEquals(4, BigFloatStream.range(context.valueOf(0), context.valueOf(12), context.valueOf(3)).collect(Collectors.toList()).size()); }
@Test public void testRangeLongStep3() { Context context = BigFloat.context(20); List<BigFloat> list = BigFloatStream.range(0, 10, 3, context) .collect(Collectors.toList()); assertEquals(4, list.size()); assertEquals(true, list.contains(context.valueOf(0))); assertEquals(true, list.contains(context.valueOf(3))); assertEquals(true, list.contains(context.valueOf(6))); assertEquals(true, list.contains(context.valueOf(9))); }
@Test public void testRangeDoubleStep3() { Context context = BigFloat.context(20); List<BigFloat> list = BigFloatStream.range(0.0, 10.0, 3.0, context) .collect(Collectors.toList()); assertEquals(4, list.size()); assertEquals(true, list.contains(context.valueOf(0))); assertEquals(true, list.contains(context.valueOf(3))); assertEquals(true, list.contains(context.valueOf(6))); assertEquals(true, list.contains(context.valueOf(9))); }
@Test public void testRangeStepMinus1() { Context context = BigFloat.context(20); List<BigFloat> list = BigFloatStream.range(context.valueOf(0), context.valueOf(10), context.valueOf(-1)) .collect(Collectors.toList()); assertList(list, 0, 0); }
@Test public void testRangeParallel() { Context context = BigFloat.context(20); List<BigFloat> list = BigFloatStream.range(context.valueOf(0), context.valueOf(10), context.valueOf(1)) .parallel() .collect(Collectors.toList()); assertList(list, 0, 10); }
@Test public void testRangeDown() { Context context = BigFloat.context(20); List<BigFloat> list = BigFloatStream.range(context.valueOf(9), context.valueOf(-1), context.valueOf(-1)) .collect(Collectors.toList()); assertList(list, 0, 10); }
@Test public void testSingleStep() { Context context = BigFloat.context(20); Stream<BigFloat> stream = BigFloatStream.range(0, 3, 1, context); Spliterator<BigFloat> spliterator = stream.spliterator(); assertEquals(true, spliterator.tryAdvance(value -> assertEquals(context.valueOf(0), value))); assertEquals(true, spliterator.tryAdvance(value -> assertEquals(context.valueOf(1), value))); assertEquals(true, spliterator.tryAdvance(value -> assertEquals(context.valueOf(2), value))); assertEquals(false, spliterator.tryAdvance(value -> fail("Should not be called"))); }