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

Example test in readme.md doesn't really test addition #81

Open
Kristine1975 opened this issue Feb 18, 2022 · 0 comments
Open

Example test in readme.md doesn't really test addition #81

Kristine1975 opened this issue Feb 18, 2022 · 0 comments

Comments

@Kristine1975
Copy link

The example code in README.md aims to test the += operator of safe_umx, but because it adds 42 to 0, it would also pass if the operator was (incorrectly) implemented as an assignment instead of an addition (as zero is the identity element of addition).

The fix would be to initialize data2 to a non-zero value.

bsl/README.md

Lines 139 to 144 in 6509cff

constexpr auto data1{42_umx};
bsl::safe_umx data2{};
bsl::ut_when{} = [&]() noexcept {
data2 += data1;
bsl::ut_then{} = [&]() noexcept {
bsl::ut_check(data2.checked() == data1);

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

1 participant