Skip to content

Commit 42d2304

Browse files
committed
update Java version
1 parent 65f346c commit 42d2304

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

src/test/java/com/upokecenter/test/CBORObjectTest.java

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10000,6 +10000,73 @@ public void TestFromJsonStringLongSpecific1() {
1000010000
}
1000110001
}
1000210002

10003+
private static final JSONOptions JSONOptionsDouble = new JSONOptions(
10004+
"numberconversion=double");
10005+
private static final JSONOptions JSONOptionsFull = new JSONOptions(
10006+
"numberconversion=full");
10007+
10008+
@Test
10009+
public static void TestParseNumberFxxLine(String line) {
10010+
// Parse test case format used in:
10011+
// https://github.com/nigeltao/parse-number-fxx-test-data
10012+
String f16 = line.substring(0, 4);
10013+
if (line.charAt(4) != ' ') {
10014+
Assert.fail(line);
10015+
}
10016+
String f32 = line.substring(4 + 1, (4 + 1)+(8));
10017+
if (line.charAt(4+ 1 + 8) != ' ') {
10018+
Assert.fail(line);
10019+
}
10020+
String f64 = line.substring(4 + 1 + 8 + 1, (4 + 1 + 8 + 1)+(16));
10021+
if (line.charAt(4+1+8+1 + 16) != ' ') {
10022+
Assert.fail(line);
10023+
}
10024+
String str = line.substring(4 + 1 + 8 + 1 + 16 + 1);
10025+
short sf16 = EInteger.FromRadixString(f16, 16).ToInt16Unchecked();
10026+
int sf32 = EInteger.FromRadixString(f32, 16).ToInt32Unchecked();
10027+
long sf64 = EInteger.FromRadixString(f64, 16).ToInt64Unchecked();
10028+
TestParseNumberFxx(str, sf16, sf32, sf64, line);
10029+
}
10030+
10031+
public static void TestParseNumberFxx(
10032+
String str,
10033+
short _f16,
10034+
int f32,
10035+
long f64,
10036+
String line) {
10037+
if (str.charAt(0) == '.') {
10038+
// Not a valid JSON number, so skip
10039+
// System.out.println(str);
10040+
return;
10041+
}
10042+
CBORObject cbor = CBORDataUtilities.ParseJSONNumber(str,
10043+
JSONOptionsDouble);
10044+
if (cbor == null) {
10045+
System.out.println(str);
10046+
return;
10047+
}
10048+
Assert.assertEquals(line, f64, cbor.AsDoubleBits());
10049+
cbor = CBORObject.FromJSONString(str, JSONOptionsDouble);
10050+
Assert.assertEquals(line, f64, cbor.AsDoubleBits());
10051+
cbor = CBORObject.FromJSONBytes(
10052+
DataUtilities.GetUtf8Bytes(str, false),
10053+
JSONOptionsDouble);
10054+
Assert.assertEquals(line, f64, cbor.AsDoubleBits());
10055+
float sing = CBORObject.FromFloatingPointBits(f32, 4).AsSingle();
10056+
cbor = CBORDataUtilities.ParseJSONNumber(str, JSONOptionsFull);
10057+
if (cbor == null) {
10058+
Assert.fail();
10059+
}
10060+
Assert.assertEquals(line, sing, cbor.AsSingle());
10061+
cbor = CBORObject.FromJSONString(str, JSONOptionsFull);
10062+
Assert.assertEquals(line, sing, cbor.AsSingle());
10063+
cbor = CBORObject.FromJSONBytes(
10064+
DataUtilities.GetUtf8Bytes(str, false),
10065+
JSONOptionsFull);
10066+
Assert.assertEquals(line, sing, cbor.AsSingle());
10067+
// TODO: Test f16
10068+
}
10069+
1000310070
@Test
1000410071
public void TestFromJsonStringFastCases() {
1000510072
JSONOptions op = new JSONOptions("numberconversion=double");

0 commit comments

Comments
 (0)