|
20 | 20 |
|
21 | 21 | import com.fasterxml.jackson.databind.ObjectMapper; |
22 | 22 | import com.fasterxml.jackson.databind.node.ArrayNode; |
| 23 | +import com.fasterxml.jackson.databind.node.FloatNode; |
23 | 24 | import com.fasterxml.jackson.databind.node.ObjectNode; |
24 | 25 |
|
25 | 26 | @SuppressWarnings({ "boxing", "static-method" }) |
@@ -208,24 +209,47 @@ private static void addTestString(Map<String, byte[]> tests, byte ctrl[], |
208 | 209 |
|
209 | 210 | static Map<Double, byte[]> doubles() { |
210 | 211 | Map<Double, byte[]> doubles = new HashMap<Double, byte[]>(); |
211 | | - DecoderTest.addTestDouble(doubles, (byte) 0x71, "-1073741824.12457"); |
212 | | - DecoderTest.addTestDouble(doubles, (byte) 0x70, "1073741824.12457"); |
213 | | - DecoderTest.addTestDouble(doubles, (byte) 0x6e, "-3.14159265359"); |
214 | | - DecoderTest.addTestDouble(doubles, (byte) 0x63, "123"); |
215 | | - DecoderTest.addTestDouble(doubles, (byte) 0x62, ".5"); |
216 | | - DecoderTest.addTestDouble(doubles, (byte) 0x63, "-.5"); |
| 212 | + doubles.put(0.0, new byte[] { 0x68, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, |
| 213 | + 0x0 }); |
| 214 | + doubles.put(0.5, new byte[] { 0x68, 0x3F, (byte) 0xE0, 0x0, 0x0, 0x0, |
| 215 | + 0x0, 0x0, 0x0 }); |
| 216 | + doubles.put(3.14159265359, new byte[] { 0x68, 0x40, 0x9, 0x21, |
| 217 | + (byte) 0xFB, 0x54, 0x44, 0x2E, (byte) 0xEA }); |
| 218 | + doubles.put(123.0, new byte[] { 0x68, 0x40, 0x5E, (byte) 0xC0, 0x0, |
| 219 | + 0x0, 0x0, 0x0, 0x0 }); |
| 220 | + doubles.put(1073741824.12457, new byte[] { 0x68, 0x41, (byte) 0xD0, |
| 221 | + 0x0, 0x0, 0x0, 0x7, (byte) 0xF8, (byte) 0xF4 }); |
| 222 | + doubles.put(-0.5, new byte[] { 0x68, (byte) 0xBF, (byte) 0xE0, 0x0, |
| 223 | + 0x0, 0x0, 0x0, 0x0, 0x0 }); |
| 224 | + doubles.put(-3.14159265359, new byte[] { 0x68, (byte) 0xC0, 0x9, 0x21, |
| 225 | + (byte) 0xFB, 0x54, 0x44, 0x2E, (byte) 0xEA }); |
| 226 | + doubles.put(-1073741824.12457, new byte[] { 0x68, (byte) 0xC1, |
| 227 | + (byte) 0xD0, 0x0, 0x0, 0x0, 0x7, (byte) 0xF8, (byte) 0xF4 }); |
| 228 | + |
217 | 229 | return doubles; |
218 | 230 | } |
219 | 231 |
|
220 | | - private static void addTestDouble(Map<Double, byte[]> tests, byte ctrl, |
221 | | - String str) { |
222 | | - |
223 | | - byte[] sb = str.getBytes(Charset.forName("US-ASCII")); |
224 | | - byte[] bytes = new byte[1 + sb.length]; |
225 | | - |
226 | | - bytes[0] = ctrl; |
227 | | - System.arraycopy(sb, 0, bytes, 1, sb.length); |
228 | | - tests.put(new Double(str), bytes); |
| 232 | + static Map<Float, byte[]> floats() { |
| 233 | + Map<Float, byte[]> floats = new HashMap<Float, byte[]>(); |
| 234 | + floats.put((float) 0.0, new byte[] { 0x4, 0x8, 0x0, 0x0, 0x0, 0x0 }); |
| 235 | + floats.put((float) 1.0, new byte[] { 0x4, 0x8, 0x3F, (byte) 0x80, 0x0, |
| 236 | + 0x0 }); |
| 237 | + floats.put((float) 1.1, new byte[] { 0x4, 0x8, 0x3F, (byte) 0x8C, |
| 238 | + (byte) 0xCC, (byte) 0xCD }); |
| 239 | + floats.put((float) 3.14, new byte[] { 0x4, 0x8, 0x40, 0x48, |
| 240 | + (byte) 0xF5, (byte) 0xC3 }); |
| 241 | + floats.put((float) 9999.99, new byte[] { 0x4, 0x8, 0x46, 0x1C, 0x3F, |
| 242 | + (byte) 0xF6 }); |
| 243 | + floats.put((float) -1.0, new byte[] { 0x4, 0x8, (byte) 0xBF, |
| 244 | + (byte) 0x80, 0x0, 0x0 }); |
| 245 | + floats.put((float) -1.1, new byte[] { 0x4, 0x8, (byte) 0xBF, |
| 246 | + (byte) 0x8C, (byte) 0xCC, (byte) 0xCD }); |
| 247 | + floats.put((float) -3.14, new byte[] { 0x4, 0x8, (byte) 0xC0, 0x48, |
| 248 | + (byte) 0xF5, (byte) 0xC3 }); |
| 249 | + floats.put((float) -9999.99, new byte[] { 0x4, 0x8, (byte) 0xC6, 0x1C, |
| 250 | + 0x3F, (byte) 0xF6 }); |
| 251 | + |
| 252 | + return floats; |
229 | 253 | } |
230 | 254 |
|
231 | 255 | static Map<Boolean, byte[]> booleans() { |
@@ -348,6 +372,11 @@ public void testDoubles() throws InvalidDatabaseException, IOException { |
348 | 372 | .testTypeDecoding(Decoder.Type.DOUBLE, DecoderTest.doubles()); |
349 | 373 | } |
350 | 374 |
|
| 375 | + @Test |
| 376 | + public void testFloats() throws InvalidDatabaseException, IOException { |
| 377 | + DecoderTest.testTypeDecoding(Decoder.Type.FLOAT, DecoderTest.floats()); |
| 378 | + } |
| 379 | + |
351 | 380 | @Test |
352 | 381 | public void testPointers() throws InvalidDatabaseException, IOException { |
353 | 382 | DecoderTest.testTypeDecoding(Decoder.Type.POINTER, pointers()); |
@@ -416,6 +445,9 @@ static <T> void testTypeDecoding(Decoder.Type type, Map<T, byte[]> tests) |
416 | 445 | } else if (type.equals(Decoder.Type.DOUBLE)) { |
417 | 446 | assertEquals(desc, expect, decoder.decode(0).getNode() |
418 | 447 | .asDouble()); |
| 448 | + } else if (type.equals(Decoder.Type.FLOAT)) { |
| 449 | + assertEquals(desc, new FloatNode((Float) expect), decoder |
| 450 | + .decode(0).getNode()); |
419 | 451 | } else if (type.equals(Decoder.Type.UTF8_STRING)) { |
420 | 452 | assertEquals(desc, expect, decoder.decode(0).getNode() |
421 | 453 | .asText()); |
|
0 commit comments