-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Fix test_permutations()
in P0202R3_constexpr_algorithm_and_exchange
#2137
Fix test_permutations()
in P0202R3_constexpr_algorithm_and_exchange
#2137
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM (although I already fixed test_permutations
in #2043).
tests/std/tests/P0202R3_constexpr_algorithm_and_exchange/test.cpp
Outdated
Show resolved
Hide resolved
Co-authored-by: Adam Bucior <35536269+AdamBucior@users.noreply.github.com>
@AdamBucior Ah, my apologies for partially duplicating your work! I noticed that this test was incorrect last night (it came to my attention because it was suppressing clang-format) and didn't realize that your PR had already fixed it. I believe that our changes can be combined - I'd like to proceed with this PR's more extensive overhaul, and then #2043 can add the |
} | ||
|
||
constexpr bool test_permutations() { | ||
int buff[] = {1, 2, 3, 4}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<meme>I don't always fail to run broken STL test cases, but when I do ...</meme> (No change requested.)
I'm mirroring this to an MSVC-internal PR. Please notify me if any further changes are pushed. |
First, this simplifies the
P0202R3_constexpr_algorithm_and_exchange
test by avoiding a huge unnecessary&&
chain. When performing "dual mode" testing at runtime and compiletime, only the top-level function needs to beconstexpr bool
returningtrue
(even that isn't strictly necessary, but it's convenient). The helper functions can beconstexpr void
; any failures will still be detected by failedassert
s.Second, this adds a missing call to
test_permutations()
.Third, this fixes
test_permutations()
which never worked.<array>
; we can use a built-in multidimensional array with asize_t cursor
.int buff[] = {1, 2, 3, 4};
needs to beint buff[] = {10, 20, 30, 40};
.constexpr int expected[24][4]
instead ofconstexpr int expected[][4]
for clarity. I didn't bother to extract24
as a magic number, although I could do that if anyone wants.next_permutation()
, this verifies thatbuff
has wrapped around to be equal toexpected[0]
.assert(!prev_permutation(begin(buff), end(buff)));
, this dereferencedcursor == end(expected)
. Now we resetcursor = 23;
.prev_permutation()
, this attempted to verifyassert(is_sorted(begin(buff), end(buff)));
. That's incorrect - the array is in ascending order after cycling throughnext_permutation()
, but in descending order after cycling throughprev_permutation()
. I have replaced this with stricter tests: we inspect bothcursor
and verify that we have exactlyexpected[23]
's content (this is stricter than verifyingis_sorted()
withgreater<>{}
).do/while
loop afterassert(!prev_permutation(begin(buff), end(buff)));
) but it seems reasonable to maintain consistency with thenext_permutation()
code above.