mirror of
https://github.com/ethauvin/JSON-java.git
synced 2025-06-17 07:50:52 -07:00
Updates test cases to support new optFloat and optNumber
This commit is contained in:
parent
49d47e3ff2
commit
2867aaa8c8
2 changed files with 47 additions and 7 deletions
|
@ -393,6 +393,20 @@ public class JSONArrayTest {
|
|||
assertTrue("Array opt double default implicit",
|
||||
new Double(jsonArray.optDouble(99)).isNaN());
|
||||
|
||||
assertTrue("Array opt float",
|
||||
new Float(23.45e-4).equals(jsonArray.optFloat(5)));
|
||||
assertTrue("Array opt float default",
|
||||
new Float(1).equals(jsonArray.optFloat(0, 1)));
|
||||
assertTrue("Array opt float default implicit",
|
||||
new Float(jsonArray.optFloat(99)).isNaN());
|
||||
|
||||
assertTrue("Array opt Number",
|
||||
new Double(23.45e-4).equals(jsonArray.optNumber(5)));
|
||||
assertTrue("Array opt Number default",
|
||||
new Double(1).equals(jsonArray.optNumber(0, 1d)));
|
||||
assertTrue("Array opt Number default implicit",
|
||||
new Double(jsonArray.optNumber(99,Double.NaN).doubleValue()).isNaN());
|
||||
|
||||
assertTrue("Array opt int",
|
||||
new Integer(42).equals(jsonArray.optInt(7)));
|
||||
assertTrue("Array opt int default",
|
||||
|
|
|
@ -614,6 +614,10 @@ public class JSONObjectTest {
|
|||
jsonObject.optDouble("doubleKey") == -23.45e7);
|
||||
assertTrue("opt doubleKey with Default should be double",
|
||||
jsonObject.optDouble("doubleStrKey", Double.NaN) == 1);
|
||||
assertTrue("optFloat doubleKey should be float",
|
||||
jsonObject.optFloat("doubleKey") == -23.45e7f);
|
||||
assertTrue("optFloat doubleKey with Default should be float",
|
||||
jsonObject.optFloat("doubleStrKey", Float.NaN) == 1f);
|
||||
assertTrue("intKey should be int",
|
||||
jsonObject.optInt("intKey") == 42);
|
||||
assertTrue("opt intKey should be int",
|
||||
|
@ -630,6 +634,18 @@ public class JSONObjectTest {
|
|||
jsonObject.optLong("longKey", 0) == 1234567890123456789L);
|
||||
assertTrue("longStrKey should be long",
|
||||
jsonObject.getLong("longStrKey") == 987654321098765432L);
|
||||
assertTrue("optNumber int should return Integer",
|
||||
jsonObject.optNumber("intKey") instanceof Integer);
|
||||
assertTrue("optNumber long should return Long",
|
||||
jsonObject.optNumber("longKey") instanceof Long);
|
||||
assertTrue("optNumber double should return Double",
|
||||
jsonObject.optNumber("doubleKey") instanceof Double);
|
||||
assertTrue("optNumber Str int should return BigDecimal",
|
||||
jsonObject.optNumber("intStrKey") instanceof BigDecimal);
|
||||
assertTrue("optNumber Str long should return BigDecimal",
|
||||
jsonObject.optNumber("longStrKey") instanceof BigDecimal);
|
||||
assertTrue("optNumber Str double should return BigDecimal",
|
||||
jsonObject.optNumber("doubleStrKey") instanceof BigDecimal);
|
||||
assertTrue("xKey should not exist",
|
||||
jsonObject.isNull("xKey"));
|
||||
assertTrue("stringKey should exist",
|
||||
|
@ -1937,9 +1953,13 @@ public class JSONObjectTest {
|
|||
assertTrue("optJSONObject() should return null ",
|
||||
null==jsonObject.optJSONObject("myKey"));
|
||||
assertTrue("optLong() should return default long",
|
||||
42 == jsonObject.optLong("myKey", 42));
|
||||
42l == jsonObject.optLong("myKey", 42l));
|
||||
assertTrue("optDouble() should return default double",
|
||||
42.3 == jsonObject.optDouble("myKey", 42.3));
|
||||
42.3d == jsonObject.optDouble("myKey", 42.3d));
|
||||
assertTrue("optFloat() should return default float",
|
||||
42.3f == jsonObject.optFloat("myKey", 42.3f));
|
||||
assertTrue("optNumber() should return default Number",
|
||||
42l == jsonObject.optNumber("myKey", Long.valueOf(42)).longValue());
|
||||
assertTrue("optString() should return default string",
|
||||
"hi".equals(jsonObject.optString("hiKey", "hi")));
|
||||
}
|
||||
|
@ -1967,9 +1987,13 @@ public class JSONObjectTest {
|
|||
assertTrue("optJSONObject() should return null ",
|
||||
null==jsonObject.optJSONObject("myKey"));
|
||||
assertTrue("optLong() should return default long",
|
||||
42 == jsonObject.optLong("myKey", 42));
|
||||
42l == jsonObject.optLong("myKey", 42l));
|
||||
assertTrue("optDouble() should return default double",
|
||||
42.3 == jsonObject.optDouble("myKey", 42.3));
|
||||
42.3d == jsonObject.optDouble("myKey", 42.3d));
|
||||
assertTrue("optFloat() should return default float",
|
||||
42.3f == jsonObject.optFloat("myKey", 42.3f));
|
||||
assertTrue("optNumber() should return default Number",
|
||||
42l == jsonObject.optNumber("myKey", Long.valueOf(42)).longValue());
|
||||
assertTrue("optString() should return default string",
|
||||
"hi".equals(jsonObject.optString("hiKey", "hi")));
|
||||
}
|
||||
|
@ -1983,11 +2007,13 @@ public class JSONObjectTest {
|
|||
assertTrue("unexpected optBoolean value",jo.optBoolean("true",false)==true);
|
||||
assertTrue("unexpected optBoolean value",jo.optBoolean("false",true)==false);
|
||||
assertTrue("unexpected optInt value",jo.optInt("int",0)==123);
|
||||
assertTrue("unexpected optLong value",jo.optLong("int",0)==123);
|
||||
assertTrue("unexpected optDouble value",jo.optDouble("int",0.0)==123.0);
|
||||
assertTrue("unexpected optLong value",jo.optLong("int",0)==123l);
|
||||
assertTrue("unexpected optDouble value",jo.optDouble("int",0.0d)==123.0d);
|
||||
assertTrue("unexpected optFloat value",jo.optFloat("int",0.0f)==123.0f);
|
||||
assertTrue("unexpected optBigInteger value",jo.optBigInteger("int",BigInteger.ZERO).compareTo(new BigInteger("123"))==0);
|
||||
assertTrue("unexpected optBigDecimal value",jo.optBigDecimal("int",BigDecimal.ZERO).compareTo(new BigDecimal("123"))==0);
|
||||
|
||||
assertTrue("unexpected optBigDecimal value",jo.optBigDecimal("int",BigDecimal.ZERO).compareTo(new BigDecimal("123"))==0);
|
||||
assertTrue("unexpected optNumber value",jo.optNumber("int",BigInteger.ZERO).longValue()==123l);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue