-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Open
Labels
area-System.CollectionsuntriagedNew issue has not been triaged by the area ownerNew issue has not been triaged by the area owner
Description
Consider:
[Fact]
public static void PopCount_LeftShiftLeavesDanglingBits()
{
BitArray ba = new(33);
ba[^1] = true;
Assert.True(ba.HasAnySet());
Assert.Equal(1, ba.PopCount());
ba = ba.LeftShift(1);
Assert.False(ba.HasAnySet());
Assert.Equal(0, ba.PopCount()); // Fails here
}This test will fail. Despite HasAnySet returning false, PopCount will return 1.
Likewise manually counting the bits will disagree with PopCount
[Fact]
public static void PopCount_LeftShiftLeavesDanglingBits()
{
BitArray ba = new(33);
ba[^1] = true;
Assert.Equal(ManualCountBits(ba), ba.PopCount());
ba = ba.LeftShift(1);
Assert.False(ba.HasAnySet());
Assert.Equal(ManualCountBits(ba), ba.PopCount());
static int ManualCountBits(BitArray ba)
{
int count = 0;
foreach (bool bit in ba)
{
if (bit)
{
count++;
}
}
return count;
}
}Copilot
Metadata
Metadata
Assignees
Labels
area-System.CollectionsuntriagedNew issue has not been triaged by the area ownerNew issue has not been triaged by the area owner