Added overloads for the StringBuilderHelper.Append() method to limit the number of decimal places being displayed; wrote unit tests for the new functionality

git-svn-id: file:///srv/devel/repo-conversion/nusu@190 d2e56fa2-650e-0410-a79f-9358c0239efd
This commit is contained in:
Markus Ewald 2010-02-15 19:19:26 +00:00
parent 03eb31403d
commit 35a4da16fc
2 changed files with 107 additions and 20 deletions

View file

@ -166,6 +166,26 @@ namespace Nuclex.Support {
Assert.AreEqual("1000000000.0", builder.ToString());
}
/// <summary>Tests whether the number of decimal places can be restricted</summary>
[Test]
public void TestAppendFloatLimitDecimalPlaces() {
StringBuilder builder = new StringBuilder();
StringBuilderHelper.Append(builder, 0.00390625f, 3);
Assert.AreEqual("0.003", builder.ToString());
}
/// <summary>
/// Verifies that a float with no decimal places is correctly appended
/// </summary>
[Test]
public void TestAppendFloatWithoutDecimalPlaces() {
StringBuilder builder = new StringBuilder();
StringBuilderHelper.Append(builder, 0.00390625f, 0);
Assert.AreEqual("0", builder.ToString()); // Note: no rounding!
}
/// <summary>
/// Verifies the behavior of the helper with unsupported floating point values
/// </summary>
@ -226,6 +246,26 @@ namespace Nuclex.Support {
Assert.AreEqual("1000000000000000000.0", builder.ToString());
}
/// <summary>Tests whether the number of decimal places can be restricted</summary>
[Test]
public void TestAppendDoubleLimitDecimalPlaces() {
StringBuilder builder = new StringBuilder();
StringBuilderHelper.Append(builder, 0.00390625, 3);
Assert.AreEqual("0.003", builder.ToString()); // Note: no rounding!
}
/// <summary>
/// Verifies that a double with no decimal places is correctly appended
/// </summary>
[Test]
public void TestAppendDoubleWithoutDecimalPlaces() {
StringBuilder builder = new StringBuilder();
StringBuilderHelper.Append(builder, 0.00390625, 0);
Assert.AreEqual("0", builder.ToString());
}
/// <summary>
/// Verifies the behavior of the helper with unsupported double precision
/// floating point values