public void TestAsSingle()
{
try {
CBORObject.NewArray().AsSingle();
Assert.Fail("Should have failed");
} catch (InvalidOperationException) {
new Object();
} catch (Exception ex) {
Assert.Fail(ex.ToString());
throw new InvalidOperationException(String.Empty, ex);
}
try {
CBORObject.NewMap().AsSingle();
Assert.Fail("Should have failed");
} catch (InvalidOperationException) {
new Object();
} catch (Exception ex) {
Assert.Fail(ex.ToString());
throw new InvalidOperationException(String.Empty, ex);
}
try {
CBORObject.True.AsSingle();
Assert.Fail("Should have failed");
} catch (InvalidOperationException) {
new Object();
} catch (Exception ex) {
Assert.Fail(ex.ToString());
throw new InvalidOperationException(String.Empty, ex);
}
try {
CBORObject.False.AsSingle();
Assert.Fail("Should have failed");
} catch (InvalidOperationException) {
new Object();
} catch (Exception ex) {
Assert.Fail(ex.ToString());
throw new InvalidOperationException(String.Empty, ex);
}
try {
CBORObject.Undefined.AsSingle();
Assert.Fail("Should have failed");
} catch (InvalidOperationException) {
new Object();
} catch (Exception ex) {
Assert.Fail(ex.ToString());
throw new InvalidOperationException(String.Empty, ex);
}
try {
CBORObject.FromObject(String.Empty).AsSingle();
Assert.Fail("Should have failed");
} catch (InvalidOperationException) {
new Object();
} catch (Exception ex) {
Assert.Fail(ex.ToString());
throw new InvalidOperationException(String.Empty, ex);
}
CBORObject numbers = GetNumberData();
for (int i = 0; i < numbers.Count; ++i) {
CBORObject numberinfo = numbers[i];
CBORObject cbornumber =
CBORObject.FromObject(EDecimal.FromString(
numberinfo["number"].AsString()));
AreEqualExact(
(float)EDecimal.FromString(numberinfo["number"].AsString()).ToSingle(),
cbornumber.AsSingle());
}
}