Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[tests] Fix integer rounding error in GetTestFileName #52266

Merged
3 commits merged into from
May 5, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.Floor((double)excessLength / 2);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be Ceil not Floor, and then we don't need the +1 on the math.

danmoseley marked this conversation as resolved.
Show resolved Hide resolved
memberName = memberName.Substring(0, halfMemberNameLength - halfExcessLength) + "..." + memberName.Substring(halfMemberNameLength + halfExcessLength + 1);
danmoseley marked this conversation as resolved.
Show resolved Hide resolved

testFileName = GenerateTestFileName(index, memberName, lineNumber);
testFilePath = Path.Combine(TestDirectory, testFileName);
Expand Down