Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add coverage #1322

Merged
merged 1 commit into from
Dec 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/neo/IO/Json/JNumber.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public JNumber(double value = 0)

public override bool AsBoolean()
{
return Value != 0 && !double.IsNaN(Value);
return Value != 0;
}

public override double AsNumber()
Expand Down
3 changes: 3 additions & 0 deletions tests/neo.UnitTests/IO/Json/UT_JNumber.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ public void TestAsString()

Action action2 = () => new JNumber(double.NegativeInfinity).AsString();
action2.Should().Throw<FormatException>();

Action action3 = () => new JNumber(double.NaN).AsString();
action3.Should().Throw<FormatException>();
}

[TestMethod]
Expand Down
20 changes: 17 additions & 3 deletions tests/neo.UnitTests/IO/Json/UT_JString.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class UT_JString
[TestMethod]
public void TestConstructor()
{
String s = "hello world";
string s = "hello world";
JString jstring = new JString(s);
Assert.AreEqual(s, jstring.Value);
Assert.ThrowsException<ArgumentNullException>(() => new JString(null));
Expand All @@ -20,14 +20,28 @@ public void TestConstructor()
[TestMethod]
public void TestAsBoolean()
{
String s1 = "hello world";
String s2 = "";
string s1 = "hello world";
string s2 = "";
JString jstring1 = new JString(s1);
JString jstring2 = new JString(s2);
Assert.AreEqual(true, jstring1.AsBoolean());
Assert.AreEqual(false, jstring2.AsBoolean());
}

[TestMethod]
public void TestAsNumber()
{
string s1 = "hello world";
string s2 = "123";
string s3 = "";
JString jstring1 = new JString(s1);
JString jstring2 = new JString(s2);
JString jstring3 = new JString(s3);
Assert.AreEqual(double.NaN, jstring1.AsNumber());
Assert.AreEqual(123, jstring2.AsNumber());
Assert.AreEqual(0, jstring3.AsNumber());
}

[TestMethod]
public void TestTryGetEnum()
{
Expand Down