Skip to content

Page 432: Bitset example does not pass tests. The bit order tests in it are backwards. #104

@WraithGlade

Description

@WraithGlade

The code in the book looks like this:

TEST_CASE("std::bitset supports integer initialization") 
{ 
	std::bitset<4> bs(0b0101);
	
	REQUIRE_FALSE(bs[0]);
	REQUIRE(bs[1]);
	REQUIRE_FALSE(bs[2]);
	REQUIRE(bs[3]);
}

But the code needed to actually pass the test is this:

TEST_CASE("std::bitset supports integer initialization") 
{ 
	std::bitset<4> bs(0b0101);
	
	REQUIRE(bs[0]);
	REQUIRE_FALSE(bs[1]);
	REQUIRE(bs[2]);
	REQUIRE_FALSE(bs[3]);
}

The original code tests the bits in human reading order, but the passing test requires them to instead be ordered in least-significant to most-significant bit order.

Perhaps you accidentally forgot to compile this example.

Alternatively, I suppose a bit ordering difference is also conceivable, although I doubt it. I'm on a 64-bit version of Windows 7, running Visual Studio C++ 2019, in case that's relevant in that case.

(Also, as usual, I'm on the Kindle ebook version of the book.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions