|
27 | 27 | import java.util.function.Supplier; |
28 | 28 | import java.util.function.UnaryOperator; |
29 | 29 | import java.util.stream.IntStream; |
30 | | -import java.util.stream.LongStream; |
31 | 30 | import java.util.stream.Stream; |
32 | 31 | import org.apache.commons.rng.UniformRandomProvider; |
33 | 32 | import org.apache.commons.rng.simple.RandomSource; |
@@ -145,6 +144,28 @@ void testOfLong(long x) { |
145 | 144 | Assertions.assertEquals(BigDecimal.valueOf(-x).subtract(bd(-x)).doubleValue(), dd.lo(), "-x lo should be remaining bits"); |
146 | 145 | } |
147 | 146 |
|
| 147 | + /** |
| 148 | + * Test conversion of an unsigned {@code int}. |
| 149 | + */ |
| 150 | + @ParameterizedTest |
| 151 | + @ValueSource(ints = {0, 1, 42, 89545664, |
| 152 | + -1, -42, -89545664, |
| 153 | + Integer.MAX_VALUE - (1 << 10), Integer.MAX_VALUE - 42, Integer.MAX_VALUE - 1, Integer.MAX_VALUE, |
| 154 | + Integer.MIN_VALUE + (1 << 10), Integer.MIN_VALUE + 42, Integer.MIN_VALUE + 1, Integer.MIN_VALUE}) |
| 155 | + @MethodSource |
| 156 | + void testOfUnsignedInt(int x) { |
| 157 | + final DD dd = DD.ofUnsigned(x); |
| 158 | + Assertions.assertTrue(dd.hi() >= 0, "x hi should be positive"); |
| 159 | + final double expected = Integer.toUnsignedLong(x); |
| 160 | + Assertions.assertEquals(expected, dd.hi(), "x hi"); |
| 161 | + Assertions.assertEquals(0, dd.lo(), "x lo"); |
| 162 | + } |
| 163 | + |
| 164 | + static int[] testOfUnsignedInt() { |
| 165 | + // Random |
| 166 | + return createRNG().ints(10).toArray(); |
| 167 | + } |
| 168 | + |
148 | 169 | /** |
149 | 170 | * Test conversion of an unsigned {@code long}. |
150 | 171 | */ |
@@ -172,9 +193,9 @@ void testOfUnsignedLong(long x) { |
172 | 193 | Assertions.assertEquals(lo, dd.lo(), "x lo"); |
173 | 194 | } |
174 | 195 |
|
175 | | - static LongStream testOfUnsignedLong() { |
| 196 | + static long[] testOfUnsignedLong() { |
176 | 197 | // Random |
177 | | - return createRNG().longs(10); |
| 198 | + return createRNG().longs(10).toArray(); |
178 | 199 | } |
179 | 200 |
|
180 | 201 | @ParameterizedTest |
|
0 commit comments