Skip to content

Commit 74e24d6

Browse files
committed
Correct a typo in Converters.ToFileSizeString and add unit tests
1 parent 19aa269 commit 74e24d6

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

CommunityToolkit.Common/Converters.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public static string ToFileSizeString(long size)
4242
}
4343
else
4444
{
45-
return ((size >> 50) / 1024F).ToString("F0") + " EB";
45+
return ((size >> 50) / 1024F).ToString("F1") + " EB";
4646
}
4747
}
4848
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using Microsoft.VisualStudio.TestTools.UnitTesting;
6+
7+
namespace CommunityToolkit.Common.UnitTests;
8+
9+
[TestClass]
10+
public class Test_Converters
11+
{
12+
[TestMethod]
13+
[DataRow(1024L - 1, "1023 bytes")]
14+
[DataRow(1024L, "1.0 KB")]
15+
[DataRow(1024L * 1024, "1.0 MB")]
16+
[DataRow(1024L * 1024 * 1024, "1.0 GB")]
17+
[DataRow(1024L * 1024 * 1024 * 1024, "1.0 TB")]
18+
[DataRow(1024L * 1024 * 1024 * 1024 * 1024, "1.0 PB")]
19+
[DataRow(1024L * 1024 * 1024 * 1024 * 1024 * 1024, "1.0 EB")]
20+
public void Test_ToFileSizeString(long size, string expected)
21+
{
22+
Assert.AreEqual(expected, Converters.ToFileSizeString(size));
23+
}
24+
}

0 commit comments

Comments
 (0)