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

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

Closed
WraithGlade opened this issue Jan 11, 2020 · 1 comment

Comments

@WraithGlade
Copy link

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.)

@JLospinoso
Copy link
Owner

Thanks, @WraithGlade! I specifically remember fixing this during copyedit. Hmm...

kruschk pushed a commit to kruschk/ccc that referenced this issue Apr 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants