BigFloatStream { public static Stream<BigFloat> rangeClosed(BigFloat startInclusive, BigFloat endInclusive, BigFloat step) { if (step.isZero()) { throw new IllegalArgumentException("invalid step: 0"); } if (endInclusive.subtract(startInclusive).signum() == -step.signum()) { return Stream.empty(); } return StreamSupport.stream(new BigFloatSpliterator(startInclusive, endInclusive, true, 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 testRangeClosedStepZero() { Context context = BigFloat.context(20); BigFloatStream.rangeClosed(context.valueOf(0), context.valueOf(10), context.valueOf(0)); }
@Test public void testRangeClosedStep3() { Context context = BigFloat.context(20); List<BigFloat> list = BigFloatStream.rangeClosed(context.valueOf(0), context.valueOf(12), context.valueOf(3)) .collect(Collectors.toList()); assertEquals(5, 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(true, list.contains(context.valueOf(12))); assertEquals(0, BigFloatStream.rangeClosed(context.valueOf(0), context.valueOf(-1), context.valueOf(3)).collect(Collectors.toList()).size()); assertEquals(1, BigFloatStream.rangeClosed(context.valueOf(0), context.valueOf(0), context.valueOf(3)).collect(Collectors.toList()).size()); assertEquals(1, BigFloatStream.rangeClosed(context.valueOf(0), context.valueOf(1), context.valueOf(3)).collect(Collectors.toList()).size()); assertEquals(1, BigFloatStream.rangeClosed(context.valueOf(0), context.valueOf(2), context.valueOf(3)).collect(Collectors.toList()).size()); assertEquals(2, BigFloatStream.rangeClosed(context.valueOf(0), context.valueOf(3), context.valueOf(3)).collect(Collectors.toList()).size()); assertEquals(2, BigFloatStream.rangeClosed(context.valueOf(0), context.valueOf(4), context.valueOf(3)).collect(Collectors.toList()).size()); assertEquals(2, BigFloatStream.rangeClosed(context.valueOf(0), context.valueOf(5), context.valueOf(3)).collect(Collectors.toList()).size()); assertEquals(3, BigFloatStream.rangeClosed(context.valueOf(0), context.valueOf(6), context.valueOf(3)).collect(Collectors.toList()).size()); assertEquals(3, BigFloatStream.rangeClosed(context.valueOf(0), context.valueOf(7), context.valueOf(3)).collect(Collectors.toList()).size()); assertEquals(3, BigFloatStream.rangeClosed(context.valueOf(0), context.valueOf(8), context.valueOf(3)).collect(Collectors.toList()).size()); assertEquals(4, BigFloatStream.rangeClosed(context.valueOf(0), context.valueOf(9), context.valueOf(3)).collect(Collectors.toList()).size()); assertEquals(4, BigFloatStream.rangeClosed(context.valueOf(0), context.valueOf(10), context.valueOf(3)).collect(Collectors.toList()).size()); assertEquals(4, BigFloatStream.rangeClosed(context.valueOf(0), context.valueOf(11), context.valueOf(3)).collect(Collectors.toList()).size()); assertEquals(5, BigFloatStream.rangeClosed(context.valueOf(0), context.valueOf(12), context.valueOf(3)).collect(Collectors.toList()).size()); }
@Test public void testRangeClosedLongStep3() { Context context = BigFloat.context(20); List<BigFloat> list = BigFloatStream.rangeClosed(0, 12, 3, context) .collect(Collectors.toList()); assertEquals(5, 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(true, list.contains(context.valueOf(12))); }
@Test public void testRangeClosedDoubleStep3() { Context context = BigFloat.context(20); List<BigFloat> list = BigFloatStream.rangeClosed(0.0, 12.0, 3.0, context) .collect(Collectors.toList()); assertEquals(5, 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(true, list.contains(context.valueOf(12))); }
@Test public void testRangeClosedStep1() { Context context = BigFloat.context(20); List<BigFloat> list = BigFloatStream.rangeClosed(context.valueOf(0), context.valueOf(10), context.valueOf(1)) .collect(Collectors.toList()); assertListClosed(list, 0, 10); }
@Test public void testRangeClosedStepMinus1() { Context context = BigFloat.context(20); List<BigFloat> list = BigFloatStream.rangeClosed(context.valueOf(0), context.valueOf(10), context.valueOf(-1)) .collect(Collectors.toList()); assertList(list, 0, 0); }
@Test public void testRangeClosedDown() { Context context = BigFloat.context(20); List<BigFloat> list = BigFloatStream.rangeClosed(context.valueOf(10), context.valueOf(0), context.valueOf(-1)) .collect(Collectors.toList()); assertListClosed(list, 0, 10); }