From 6e887adb12f299f7caf2c3b01dbe920b66f27773 Mon Sep 17 00:00:00 2001 From: Mitchell Hwang Date: Tue, 4 May 2021 15:41:57 -0400 Subject: [PATCH 1/3] [tests] Fix integer rounding error in GetTestFileName --- .../tests/TestUtilities/System/IO/FileCleanupTestBase.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/libraries/Common/tests/TestUtilities/System/IO/FileCleanupTestBase.cs b/src/libraries/Common/tests/TestUtilities/System/IO/FileCleanupTestBase.cs index 4e1528200ac0d1..b105ebdfa4092c 100644 --- a/src/libraries/Common/tests/TestUtilities/System/IO/FileCleanupTestBase.cs +++ b/src/libraries/Common/tests/TestUtilities/System/IO/FileCleanupTestBase.cs @@ -102,7 +102,9 @@ protected string GetTestFileName(int? index = null, [CallerMemberName] string me if (excessLength < memberName.Length + "...".Length) { // Take a chunk out of the middle as perhaps it's the least interesting part of the name - memberName = memberName.Substring(0, memberName.Length / 2 - excessLength / 2) + "..." + memberName.Substring(memberName.Length / 2 + excessLength / 2); + int halfMemberNameLength = (int)Math.Floor((double)memberName.Length / 2); + int halfExcessLength = (int)Math.Floor((double)excessLength / 2); + memberName = memberName.Substring(0, halfMemberNameLength - halfExcessLength) + "..." + memberName.Substring(halfMemberNameLength + halfExcessLength + 1); testFileName = GenerateTestFileName(index, memberName, lineNumber); testFilePath = Path.Combine(TestDirectory, testFileName); From 57934d0ea8dc7ef812112ae7382d76c4753cf672 Mon Sep 17 00:00:00 2001 From: Dan Moseley Date: Tue, 4 May 2021 22:27:49 -0700 Subject: [PATCH 2/3] Update src/libraries/Common/tests/TestUtilities/System/IO/FileCleanupTestBase.cs --- .../Common/tests/TestUtilities/System/IO/FileCleanupTestBase.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libraries/Common/tests/TestUtilities/System/IO/FileCleanupTestBase.cs b/src/libraries/Common/tests/TestUtilities/System/IO/FileCleanupTestBase.cs index b105ebdfa4092c..0c223fe1f7cb68 100644 --- a/src/libraries/Common/tests/TestUtilities/System/IO/FileCleanupTestBase.cs +++ b/src/libraries/Common/tests/TestUtilities/System/IO/FileCleanupTestBase.cs @@ -104,7 +104,7 @@ protected string GetTestFileName(int? index = null, [CallerMemberName] string me // Take a chunk out of the middle as perhaps it's the least interesting part of the name int halfMemberNameLength = (int)Math.Floor((double)memberName.Length / 2); int halfExcessLength = (int)Math.Floor((double)excessLength / 2); - memberName = memberName.Substring(0, halfMemberNameLength - halfExcessLength) + "..." + memberName.Substring(halfMemberNameLength + halfExcessLength + 1); + memberName = memberName.Substring(0, halfMemberNameLength - halfExcessLength) + "..." + memberName.Substring(halfMemberNameLength + halfExcessLength); testFileName = GenerateTestFileName(index, memberName, lineNumber); testFilePath = Path.Combine(TestDirectory, testFileName); From eb045c8d155918731d1fa2693735f67cb87e5875 Mon Sep 17 00:00:00 2001 From: Dan Moseley Date: Tue, 4 May 2021 22:28:09 -0700 Subject: [PATCH 3/3] Update src/libraries/Common/tests/TestUtilities/System/IO/FileCleanupTestBase.cs --- .../Common/tests/TestUtilities/System/IO/FileCleanupTestBase.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libraries/Common/tests/TestUtilities/System/IO/FileCleanupTestBase.cs b/src/libraries/Common/tests/TestUtilities/System/IO/FileCleanupTestBase.cs index 0c223fe1f7cb68..a0542ef930c028 100644 --- a/src/libraries/Common/tests/TestUtilities/System/IO/FileCleanupTestBase.cs +++ b/src/libraries/Common/tests/TestUtilities/System/IO/FileCleanupTestBase.cs @@ -103,7 +103,7 @@ protected string GetTestFileName(int? index = null, [CallerMemberName] string me { // Take a chunk out of the middle as perhaps it's the least interesting part of the name int halfMemberNameLength = (int)Math.Floor((double)memberName.Length / 2); - int halfExcessLength = (int)Math.Floor((double)excessLength / 2); + int halfExcessLength = (int)Math.Ceiling((double)excessLength / 2); memberName = memberName.Substring(0, halfMemberNameLength - halfExcessLength) + "..." + memberName.Substring(halfMemberNameLength + halfExcessLength); testFileName = GenerateTestFileName(index, memberName, lineNumber);