diff --git a/include/gp/algorithms/partition.hpp b/include/gp/algorithms/partition.hpp index 0bf9284..1dcf969 100644 --- a/include/gp/algorithms/partition.hpp +++ b/include/gp/algorithms/partition.hpp @@ -4,18 +4,17 @@ namespace gp { template it_t lomuto_partition(it_t first, it_t last, pred predicate = pred{}) { - auto i = --it_t(first); + auto i = it_t(first); auto j = first; - ++j; for(; j != last; ++j) { if(predicate(*j)){ - ++i; gp::swap(*i, *j); + ++i; } } - return ++i; + return i; } template diff --git a/tests/dynarray_test.cpp b/tests/dynarray_test.cpp index 498ed8f..eff8cc6 100644 --- a/tests/dynarray_test.cpp +++ b/tests/dynarray_test.cpp @@ -60,4 +60,50 @@ struct dynarray_test : public test_scaffold { } }; -append_test dummy_afdglys543(new dynarray_test{}); \ No newline at end of file +append_test dummy_afdglys543(new dynarray_test{}); + +struct dynarray2_test : public test_scaffold { + uint32_t seed; + + dynarray2_test() { + name = __FILE__ ":2_seed"; + seed = std::random_device{}(); + name += std::to_string(seed); + } + + virtual int run() { + using val = gp::dynarray; + cheap_rand setter(seed); + + std::unique_ptr> store = std::make_unique>(); + gp::buddy alloc{&*store->begin(), store->size()}; + + gp::vector vals{alloc}; + std::uniform_int_distribution dist(0,49); + std::uniform_int_distribution coin(false,true); + bool happened = false; + for(int i = 0; i < 1000; i++) { + val a; + if(coin(setter)) { + a.emplace_back(dist(setter)); + } + a.emplace_back(dist(setter)); + for(int j = 0; j < 1000; j++) { + val b; + if(coin(setter)) { + b.emplace_back(dist(setter)); + } + b.emplace_back(dist(setter)); + if(a == b) { + if(! (a != b)) { + happened = true; + } + } + } + } + + return !happened; + } +}; + +append_test dummy_5dfqlys543(new dynarray2_test{}); \ No newline at end of file