Skip to content

BitOperationsTests has broken coverage for nuint #120356

@NightOwl888

Description

@NightOwl888

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions