Skip to content

Commit

Permalink
Edit tests and comment on NaNs in FromObject(float) and FromObject(do…
Browse files Browse the repository at this point in the history
…uble) documentation
  • Loading branch information
peteroupc committed Jun 30, 2021
1 parent 825d473 commit 9ab001e
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 27 deletions.
22 changes: 20 additions & 2 deletions CBOR/PeterO/Cbor/CBORObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2490,7 +2490,17 @@ public static CBORObject FromObject(byte value) {
}

/// <summary>Generates a CBOR object from a 32-bit floating-point
/// number.</summary>
/// number. The input value can be a not-a-number (NaN) value (such as
/// <c>Single.NaN</c> in DotNet or Float.NaN in Java); however, NaN
/// values have multiple forms that are equivalent for many
/// applications' purposes, and <c>Single.NaN</c> / <c>Float.NaN</c> is
/// only one of these equivalent forms. In fact,
/// <c>CBORObject.FromObject(Single.NaN)</c> or
/// <c>CBORObject.FromObject(Float.NaN)</c> could produce a
/// CBOR-encoded object that differs between DotNet and Java, because
/// <c>Single.NaN</c> / <c>Float.NaN</c> may have a different form in
/// DotNet and Java (for example, the NaN value's sign may be negative
/// in DotNet, but positive in Java).</summary>
/// <param name='value'>The parameter <paramref name='value'/> is a
/// 32-bit floating-point number.</param>
/// <returns>A CBOR object generated from the given number.</returns>
Expand All @@ -2501,7 +2511,15 @@ public static CBORObject FromObject(float value) {
}

/// <summary>Generates a CBOR object from a 64-bit floating-point
/// number.</summary>
/// number. The input value can be a not-a-number (NaN) value (such as
/// <c>Double.NaN</c> ); however, NaN values have multiple forms that
/// are equivalent for many applications' purposes, and
/// <c>Double.NaN</c> is only one of these equivalent forms. In fact,
/// <c>CBORObject.FromObject(Double.NaN)</c> could produce a
/// CBOR-encoded object that differs between DotNet and Java, because
/// <c>Double.NaN</c> may have a different form in DotNet and Java (for
/// example, the NaN value's sign may be negative in DotNet, but
/// positive in Java).</summary>
/// <param name='value'>The parameter <paramref name='value'/> is a
/// 64-bit floating-point number.</param>
/// <returns>A CBOR object generated from the given number.</returns>
Expand Down
20 changes: 8 additions & 12 deletions CBORTest/CBORNumberTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -555,13 +555,6 @@ public void TestAsEDecimal() {
.AsNumber().ToEDecimal();
Assert.AreEqual(objectTemp, objectTemp2);
}
{
string stringTemp = ToObjectTest.TestToFromObjectRoundTrip(
Single.NaN).AsNumber().ToEDecimal().ToString();
Assert.AreEqual(
"NaN",
stringTemp);
}
{
object objectTemp = CBORTestCommon.DecPosInf;
object objectTemp2 =
Expand All @@ -577,12 +570,15 @@ public void TestAsEDecimal() {
Assert.AreEqual(objectTemp, objectTemp2);
}
{
object objectTemp = "NaN";
object objectTemp2 =
bool bo = ToObjectTest.TestToFromObjectRoundTrip(
Double.NaN).AsNumber().ToEDecimal().IsNaN();
Assert.IsTrue(bo);
}
{
bool bo =
ToObjectTest.TestToFromObjectRoundTrip(
Double.NaN).AsNumber().ToEDecimal()
.ToString();
Assert.AreEqual(objectTemp, objectTemp2);
Single.NaN).AsNumber().ToEDecimal().IsNaN();
Assert.IsTrue(bo);
}
try {
CBORObject.NewArray().AsNumber().ToEDecimal();
Expand Down
2 changes: 1 addition & 1 deletion CBORTest/CBORObjectTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8310,7 +8310,7 @@ public static void TestParseNumberFxxLine(string line) {
Assert.Fail(line);
}
string f64 = line.Substring(4 + 1 + 8 + 1, 16);
if (line[4+ 1 + 25] != ' ') {
if (line[4 + 26] != ' ') {
Assert.Fail(line);
}
string str = line.Substring(4 + 1 + 8 + 1 + 16 + 1);
Expand Down
20 changes: 8 additions & 12 deletions CBORTest/ToObjectTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -478,13 +478,6 @@ public void TestAsEDecimal() {
.ToObject(typeof(EDecimal));
Assert.AreEqual(objectTemp, objectTemp2);
}
{
string stringTemp = ToObjectTest.TestToFromObjectRoundTrip(Single.NaN)
.ToObject(typeof(EDecimal)).ToString();
Assert.AreEqual(
"NaN",
stringTemp);
}
{
object objectTemp = CBORTestCommon.DecPosInf;
object objectTemp2 =
Expand All @@ -500,11 +493,14 @@ public void TestAsEDecimal() {
Assert.AreEqual(objectTemp, objectTemp2);
}
{
object objectTemp = "NaN";
object objectTemp2 =
ToObjectTest.TestToFromObjectRoundTrip(Double.NaN)
.ToObject(typeof(EDecimal)).ToString();
Assert.AreEqual(objectTemp, objectTemp2);
bool bo = ((EDecimal)ToObjectTest.TestToFromObjectRoundTrip(Single.NaN)
.ToObject(typeof(EDecimal))).IsNaN();
Assert.IsTrue(bo);
}
{
bool bo = ((EDecimal)ToObjectTest.TestToFromObjectRoundTrip(Double.NaN)
.ToObject(typeof(EDecimal))).IsNaN();
Assert.IsTrue(bo);
}
try {
CBORObject.NewArray().ToObject(typeof(EDecimal));
Expand Down

0 comments on commit 9ab001e

Please sign in to comment.