mirror of
https://github.com/zeux/pugixml.git
synced 2024-12-25 20:14:10 +08:00
tests: Fix MSVC 2022 build
Instead of trying to detect if we can safely use random shuffle simply reimplement it ourselves. The quality of the RNG is not essential for these tests.
This commit is contained in:
parent
dd50fa5b45
commit
c60ca94cdd
@ -10,14 +10,6 @@
|
||||
#include <algorithm>
|
||||
#include <limits>
|
||||
|
||||
// std::random_shuffle is deprecated in c++14, is removed in c++17.
|
||||
#if defined(__cplusplus) && (__cplusplus >= 201402L)
|
||||
# include <random>
|
||||
# define PUGIXML_SHUFFLE(rng) std::shuffle(rng.begin(), rng.end(), std::default_random_engine{std::random_device{}()})
|
||||
#else
|
||||
# define PUGIXML_SHUFFLE(rng) std::random_shuffle(rng.begin(), rng.end())
|
||||
#endif
|
||||
|
||||
using namespace pugi;
|
||||
|
||||
static void load_document_copy(xml_document& doc, const char_t* text)
|
||||
@ -28,6 +20,22 @@ static void load_document_copy(xml_document& doc, const char_t* text)
|
||||
doc.append_copy(source.first_child());
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static void random_shuffle(std::vector<T>& v)
|
||||
{
|
||||
size_t rng = 2147483647;
|
||||
|
||||
for (size_t i = v.size() - 1; i > 0; --i)
|
||||
{
|
||||
// Fisher-Yates shuffle
|
||||
size_t j = rng % (i + 1);
|
||||
std::swap(v[j], v[i]);
|
||||
|
||||
// LCG RNG, constants from Numerical Recipes
|
||||
rng = rng * 1664525 + 1013904223;
|
||||
}
|
||||
}
|
||||
|
||||
TEST(xpath_allocator_many_pages)
|
||||
{
|
||||
std::basic_string<char_t> query = STR("0");
|
||||
@ -163,7 +171,7 @@ TEST(xpath_sort_random_medium)
|
||||
xpath_node_set ns = doc.select_nodes(STR("//node() | //@*"));
|
||||
|
||||
std::vector<xpath_node> nsv(ns.begin(), ns.end());
|
||||
PUGIXML_SHUFFLE(nsv);
|
||||
random_shuffle(nsv);
|
||||
|
||||
xpath_node_set copy(&nsv[0], &nsv[0] + nsv.size());
|
||||
copy.sort();
|
||||
@ -192,7 +200,7 @@ TEST(xpath_sort_random_large)
|
||||
xpath_node_set ns = doc.select_nodes(STR("//node() | //@*"));
|
||||
|
||||
std::vector<xpath_node> nsv(ns.begin(), ns.end());
|
||||
PUGIXML_SHUFFLE(nsv);
|
||||
random_shuffle(nsv);
|
||||
|
||||
xpath_node_set copy(&nsv[0], &nsv[0] + nsv.size());
|
||||
copy.sort();
|
||||
|
Loading…
x
Reference in New Issue
Block a user