Skip to content

Commit

Permalink
[tests] Fix integer rounding error in GetTestFileName (#52266)
Browse files Browse the repository at this point in the history
* [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 <mitchell.hwang@microsoft.com>
Co-authored-by: Dan Moseley <danmose@microsoft.com>
  • Loading branch information
3 people authored May 5, 2021
1 parent c587b8d commit 69ac4c5
Showing 1 changed file with 3 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 69ac4c5

Please sign in to comment.