Skip to content

Commit

Permalink
Correct a typo in Converters.ToFileSizeString and add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
heku committed Aug 20, 2022
1 parent 19aa269 commit 74e24d6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CommunityToolkit.Common/Converters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static string ToFileSizeString(long size)
}
else
{
return ((size >> 50) / 1024F).ToString("F0") + " EB";
return ((size >> 50) / 1024F).ToString("F1") + " EB";
}
}
}
24 changes: 24 additions & 0 deletions tests/CommunityToolkit.Common.UnitTests/Test_Converters.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace CommunityToolkit.Common.UnitTests;

[TestClass]
public class Test_Converters
{
[TestMethod]
[DataRow(1024L - 1, "1023 bytes")]
[DataRow(1024L, "1.0 KB")]
[DataRow(1024L * 1024, "1.0 MB")]
[DataRow(1024L * 1024 * 1024, "1.0 GB")]
[DataRow(1024L * 1024 * 1024 * 1024, "1.0 TB")]
[DataRow(1024L * 1024 * 1024 * 1024 * 1024, "1.0 PB")]
[DataRow(1024L * 1024 * 1024 * 1024 * 1024 * 1024, "1.0 EB")]
public void Test_ToFileSizeString(long size, string expected)
{
Assert.AreEqual(expected, Converters.ToFileSizeString(size));
}
}

0 comments on commit 74e24d6

Please sign in to comment.