This is an archive of the discontinued LLVM Phabricator instance.

[libcxx] [test] Fix non-Standard assumptions when testing sample().
ClosedPublic

Authored by STL_MSFT on Nov 17 2016, 1:38 PM.

Details

Summary

[libcxx] [test] Fix non-Standard assumptions when testing sample().

sample() isn't specified with a reproducible algorithm, so expecting
exact output is non-Standard. Mark those tests with LIBCPP_ASSERT.

In test_small_population(), we're guaranteed to get all of the elements,
but not necessarily in their original order. When PopulationCategory is
forward, we're guaranteed stability (and can therefore test equal()).
Otherwise, we can only test is_permutation(). (As it happens, both libcxx
and MSVC's STL provide stability in this scenario for input-only iterators.)

Diff Detail

Event Timeline

STL_MSFT updated this revision to Diff 78416.Nov 17 2016, 1:38 PM
STL_MSFT retitled this revision from to [libcxx] [test] Fix non-Standard assumptions when testing sample()..
STL_MSFT updated this object.
STL_MSFT added reviewers: EricWF, mclow.lists.
STL_MSFT added a subscriber: cfe-commits.
EricWF accepted this revision.Nov 17 2016, 11:00 PM
EricWF edited edge metadata.

LGTM.

test/std/algorithms/alg.modifying.operations/alg.random.sample/sample.pass.cpp
74

Please add a comment here explaining that the algorithm is non-reproducable.

This revision is now accepted and ready to land.Nov 17 2016, 11:00 PM
STL_MSFT marked an inline comment as done.Nov 18 2016, 1:59 PM

Added the requested comment, will commit.

test/std/algorithms/alg.modifying.operations/alg.random.sample/sample.pass.cpp
74

Adding:

// sample() is deterministic but non-reproducible;
// its results can vary between implementations.
STL_MSFT closed this revision.Nov 18 2016, 2:06 PM
STL_MSFT marked an inline comment as done.

Thanks, r287383 (including the requested comment).