Added double precision overloads for the garbage-free string builder appending methods; the string builder helper methods for floating point values now tell whether they successfully appended a value instead of using an assertion and appending a wrong(!) value; restored full test coverage for the whole assembly
git-svn-id: file:///srv/devel/repo-conversion/nusu@189 d2e56fa2-650e-0410-a79f-9358c0239efd
This commit is contained in:
parent
237fb57fc8
commit
03eb31403d
2 changed files with 201 additions and 22 deletions
|
|
@ -89,6 +89,39 @@ namespace Nuclex.Support {
|
|||
Assert.AreEqual("-12345", builder.ToString());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that a positive long integer is correctly appended to a string builder
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestAppendPositiveLong() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
StringBuilderHelper.Append(builder, 12345L);
|
||||
|
||||
Assert.AreEqual("12345", builder.ToString());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that a long integer with value 0 is correctly appended to a string builder
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestAppendNullLong() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
StringBuilderHelper.Append(builder, 0L);
|
||||
|
||||
Assert.AreEqual("0", builder.ToString());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that a negative long integer is correctly appended to a string builder
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestAppendNegativeLong() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
StringBuilderHelper.Append(builder, -12345L);
|
||||
|
||||
Assert.AreEqual("-12345", builder.ToString());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that negative floating point values are correctly converted
|
||||
/// </summary>
|
||||
|
|
@ -133,6 +166,81 @@ namespace Nuclex.Support {
|
|||
Assert.AreEqual("1000000000.0", builder.ToString());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies the behavior of the helper with unsupported floating point values
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestAppendOutOfRangeFloat() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
Assert.IsFalse(StringBuilderHelper.Append(builder, float.PositiveInfinity));
|
||||
Assert.IsFalse(StringBuilderHelper.Append(builder, float.NegativeInfinity));
|
||||
Assert.IsFalse(StringBuilderHelper.Append(builder, float.NaN));
|
||||
Assert.IsFalse(StringBuilderHelper.Append(builder, 0.000000059604644775390625f));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that negative double precision floating point values are
|
||||
/// correctly converted
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestAppendNegativeDouble() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
StringBuilderHelper.Append(builder, -32.015625);
|
||||
|
||||
Assert.AreEqual("-32.015625", builder.ToString());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that positive double precision floating point values are
|
||||
/// correctly converted
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestAppendPositiveDouble() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
StringBuilderHelper.Append(builder, 10.0625);
|
||||
|
||||
Assert.AreEqual("10.0625", builder.ToString());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that very small double precision floating point values are
|
||||
/// correctly converted
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestAppendSmallDouble() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
StringBuilderHelper.Append(builder, 0.00390625);
|
||||
|
||||
Assert.AreEqual("0.00390625", builder.ToString());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that very large double precision floating point values are
|
||||
/// correctly converted
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestAppendHugeDouble() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
StringBuilderHelper.Append(builder, 1000000000000000000.0);
|
||||
|
||||
Assert.AreEqual("1000000000000000000.0", builder.ToString());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies the behavior of the helper with unsupported double precision
|
||||
/// floating point values
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestAppendOutOfRangeDouble() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
Assert.IsFalse(StringBuilderHelper.Append(builder, double.PositiveInfinity));
|
||||
Assert.IsFalse(StringBuilderHelper.Append(builder, double.NegativeInfinity));
|
||||
Assert.IsFalse(StringBuilderHelper.Append(builder, double.NaN));
|
||||
Assert.IsFalse(
|
||||
StringBuilderHelper.Append(builder, 1.1102230246251565404236316680908e-16)
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that the contents of a string builder can be cleared
|
||||
/// </summary>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue