From 69ac4c5cc3ea583dcdbc98fb93573f3836e2fb47 Mon Sep 17 00:00:00 2001 From: Mitchell Hwang Date: Wed, 5 May 2021 09:46:17 -0400 Subject: [PATCH] [tests] Fix integer rounding error in GetTestFileName (#52266) * [tests] Fix integer rounding error in GetTestFileName * Update src/libraries/Common/tests/TestUtilities/System/IO/FileCleanupTestBase.cs * Update src/libraries/Common/tests/TestUtilities/System/IO/FileCleanupTestBase.cs Co-authored-by: Mitchell Hwang Co-authored-by: Dan Moseley --- .../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 4e1528200ac0d..a0542ef930c02 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.Ceiling((double)excessLength / 2); + memberName = memberName.Substring(0, halfMemberNameLength - halfExcessLength) + "..." + memberName.Substring(halfMemberNameLength + halfExcessLength); testFileName = GenerateTestFileName(index, memberName, lineNumber); testFilePath = Path.Combine(TestDirectory, testFileName);