Search in sources :

Example 31 with Context

use of ch.obermuhlner.math.big.BigFloat.Context in project big-math by eobermuhlner.

the class BigFloatStreamTest method testRangeStep3.

@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());
}
Also used : Context(ch.obermuhlner.math.big.BigFloat.Context) BigFloat(ch.obermuhlner.math.big.BigFloat) Test(org.junit.Test)

Example 32 with Context

use of ch.obermuhlner.math.big.BigFloat.Context in project big-math by eobermuhlner.

the class BigFloatStreamTest method testRangeClosedDoubleStep3.

@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)));
}
Also used : Context(ch.obermuhlner.math.big.BigFloat.Context) BigFloat(ch.obermuhlner.math.big.BigFloat) Test(org.junit.Test)

Example 33 with Context

use of ch.obermuhlner.math.big.BigFloat.Context in project big-math by eobermuhlner.

the class BigFloatStreamTest method testRangeStepZero.

@Test(expected = IllegalArgumentException.class)
public void testRangeStepZero() {
    Context context = BigFloat.context(20);
    BigFloatStream.range(context.valueOf(0), context.valueOf(10), context.valueOf(0));
}
Also used : Context(ch.obermuhlner.math.big.BigFloat.Context) Test(org.junit.Test)

Example 34 with Context

use of ch.obermuhlner.math.big.BigFloat.Context in project big-math by eobermuhlner.

the class BigFloatStreamTest method testRangeClosedStepZero.

@Test(expected = IllegalArgumentException.class)
public void testRangeClosedStepZero() {
    Context context = BigFloat.context(20);
    BigFloatStream.rangeClosed(context.valueOf(0), context.valueOf(10), context.valueOf(0));
}
Also used : Context(ch.obermuhlner.math.big.BigFloat.Context) Test(org.junit.Test)

Example 35 with Context

use of ch.obermuhlner.math.big.BigFloat.Context in project big-math by eobermuhlner.

the class BigFloatStreamTest method testRangeClosedStepMinus1.

@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);
}
Also used : Context(ch.obermuhlner.math.big.BigFloat.Context) BigFloat(ch.obermuhlner.math.big.BigFloat) Test(org.junit.Test)

Aggregations

Context (ch.obermuhlner.math.big.BigFloat.Context)78 Test (org.junit.Test)76 MathContext (java.math.MathContext)61 BigFloat (ch.obermuhlner.math.big.BigFloat)15