Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 3, 2025

Fixes #[issue_number]

Summary

BitOperationsTests was missing explicit casts to nuint in several test methods, causing them to inadvertently test the wrong overloads (ulong and uint instead of nuint). This resulted in incomplete test coverage for the nuint overloads of BitOperations methods.

Changes

BitOps_RotateRight_nuint (lines 758-767)

The 64-bit test path was calling BitOperations.RotateRight(value, ...) where value is a ulong, which tests the ulong overload instead of the nuint overload. Fixed by:

  • Casting all expected values to (nuint)
  • Casting the value parameter to (nuint) in all BitOperations.RotateRight() calls
// Before
Assert.Equal(0b10101010..., BitOperations.RotateRight(value, 1));

// After
Assert.Equal((nuint)0b10101010..., BitOperations.RotateRight((nuint)value, 1));

BitOps_LeadingZeroCount_nuint_32 (line 243)

Changed BitOperations.LeadingZeroCount(n) to BitOperations.LeadingZeroCount((nuint)n) to test the nuint overload instead of the uint overload.

BitOps_LeadingZeroCount_nuint_64 (line 266)

Changed BitOperations.LeadingZeroCount(n) to BitOperations.LeadingZeroCount((nuint)n) to test the nuint overload instead of the ulong overload.

Testing

All affected tests now pass and correctly test the nuint overloads:

  • BitOps_RotateRight_nuint
  • BitOps_LeadingZeroCount_nuint_32 ✅ (skipped on 64-bit as expected)
  • BitOps_LeadingZeroCount_nuint_64 ✅ (all 17 test cases passed)

The underlying implementation code is correct; only the tests needed fixing to ensure proper coverage.

Original prompt

This section details on the original issue you should resolve

<issue_title>BitOperationsTests has broken coverage for nuint</issue_title>
<issue_description>### Description

TestBitOperations is missing some casts to nunit and is testing the wrong overload in some cases.

Reproduction Steps

const ulong value = 0b01010101_01010101_01010101_01010101_01010101_01010101_01010101_01010101ul;
Assert.Equal(0b10101010_10101010_10101010_10101010_10101010_10101010_10101010_10101010ul,
BitOperations.RotateRight(value, 1));
Assert.Equal(0b01010101_01010101_01010101_01010101_01010101_01010101_01010101_01010101ul,
BitOperations.RotateRight(value, 2));
Assert.Equal(0b10101010_10101010_10101010_10101010_10101010_10101010_10101010_10101010ul,
BitOperations.RotateRight(value, 3));
Assert.Equal(value, BitOperations.RotateRight(value, int.MinValue)); // % 64 = 0
Assert.Equal(BitOperations.RotateLeft(value, 63),
BitOperations.RotateRight(value, int.MaxValue)); // % 64 = 63

Should be:

                    const ulong value = 0b01010101_01010101_01010101_01010101_01010101_01010101_01010101_01010101ul;
                    Assert.Equal((nuint)0b10101010_10101010_10101010_10101010_10101010_10101010_10101010_10101010ul,
                        BitOperation.RotateRight((nuint)value, 1));
                    Assert.Equal((nuint)0b01010101_01010101_01010101_01010101_01010101_01010101_01010101_01010101ul,
                        BitOperation.RotateRight((nuint)value, 2));
                    Assert.Equal((nuint)0b10101010_10101010_10101010_10101010_10101010_10101010_10101010_10101010ul,
                        BitOperation.RotateRight((nuint)value, 3));
                    Assert.Equal((nuint)value, BitOperation.RotateRight((nuint)value, int.MinValue)); // % 64 = 0
                    Assert.Equal(BitOperation.RotateLeft((nuint)value, 63),
                        BitOperation.RotateRight((nuint)value, int.MaxValue)); // % 64 = 63

Should be:

int actual = BitOperations.LeadingZeroCount((nuint)n);

Should be:

int actual = BitOperations.LeadingZeroCount((nuint)n);

The code under test is fine once the tests are corrected.

Expected behavior

Tests should be for the correct overload (in this case nunit).

Actual behavior

Tests are calling the wrong overload and coverage is missed.

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

No response</issue_description>

<agent_instructions>The issue description has detailed description of the problem and the fix.</agent_instructions>

Comments on the Issue (you are @copilot in this section)

Fixes #120356

💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot AI changed the title [WIP] BitOperationsTests has broken coverage for nuint Fix missing nuint casts in BitOperationsTests Oct 3, 2025
Copilot AI requested a review from jkotas October 3, 2025 14:32
Copilot finished work on behalf of jkotas October 3, 2025 14:32
@dotnet-policy-service
Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-system-runtime
See info in area-owners.md if you want to be subscribed.

@jkotas jkotas marked this pull request as ready for review October 11, 2025 21:19
Copilot AI review requested due to automatic review settings October 11, 2025 21:19
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes missing explicit casts to nuint in BitOperationsTests, ensuring that the tests properly cover the nuint overloads of BitOperations methods instead of inadvertently testing ulong and uint overloads.

  • Added explicit (nuint) casts in LeadingZeroCount test methods to test the correct overload
  • Fixed RotateRight test method to cast both the input value and expected results to nuint
  • Ensured proper test coverage for nuint overloads in BitOperations class

@jkotas jkotas requested a review from stephentoub October 11, 2025 21:20
@stephentoub stephentoub enabled auto-merge (squash) October 11, 2025 21:22
@stephentoub stephentoub merged commit 2afad2e into main Oct 12, 2025
86 checks passed
@jkotas jkotas deleted the copilot/fix-abd93428-b747-4030-bdba-2c97122beb20 branch October 12, 2025 00:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BitOperationsTests has broken coverage for nuint

3 participants