#ifndef TESTSPR_SPROUT_ALGORITHM_NTH_ELEMENT_HPP #define TESTSPR_SPROUT_ALGORITHM_NTH_ELEMENT_HPP #include #include #include #include #include namespace testspr { static void algorithm_nth_element_test() { using namespace sprout; { SPROUT_STATIC_CONSTEXPR auto arr1 = array{{10, 7, 8, 6, 9, 2, 5, 3, 4, 1}}; // ソート { SPROUT_STATIC_CONSTEXPR auto nth = sprout::nth_element( arr1, sprout::begin(arr1) + 4 ); TESTSPR_DOUBLE_ASSERT(testspr::equal( nth, array{{2, 4, 1, 3, 5, 10, 9, 8, 7, 6}} )); } { SPROUT_STATIC_CONSTEXPR auto nth = sprout::fit::nth_element( arr1, sprout::begin(arr1) + 4 ); TESTSPR_DOUBLE_ASSERT(testspr::equal( nth, array{{2, 4, 1, 3, 5}} )); } // ソート // 範囲の切り出し { SPROUT_STATIC_CONSTEXPR auto nth = sprout::nth_element( sprout::sub(arr1, 2, 8), sprout::begin(arr1) + 4 ); TESTSPR_DOUBLE_ASSERT(testspr::equal( nth, array{{2, 3, 5, 9, 8, 6}} )); TESTSPR_DOUBLE_ASSERT(testspr::equal( sprout::get_fixed(nth), array{{10, 7, 2, 3, 5, 9, 8, 6, 4, 1}} )); } { SPROUT_STATIC_CONSTEXPR auto nth = sprout::fit::nth_element( sprout::sub(arr1, 2, 8), sprout::begin(arr1) + 4 ); TESTSPR_DOUBLE_ASSERT(testspr::equal( nth, array{{2, 3, 5}} )); TESTSPR_DOUBLE_ASSERT(testspr::equal( sprout::get_fixed(nth), array{{10, 7, 2, 3, 5, 9, 8, 6, 4, 1}} )); } } { SPROUT_STATIC_CONSTEXPR auto arr1 = array{{10, 7, 8, 6, 9, 2, 5, 3, 4, 1}}; // ソート { SPROUT_STATIC_CONSTEXPR auto nth = sprout::nth_element( arr1, sprout::begin(arr1) + 4, testspr::less() ); TESTSPR_DOUBLE_ASSERT(testspr::equal( nth, array{{2, 4, 1, 3, 5, 10, 9, 8, 7, 6}} )); } { SPROUT_STATIC_CONSTEXPR auto nth = sprout::fit::nth_element( arr1, sprout::begin(arr1) + 4, testspr::less() ); TESTSPR_DOUBLE_ASSERT(testspr::equal( nth, array{{2, 4, 1, 3, 5}} )); } // ソート // 範囲の切り出し { SPROUT_STATIC_CONSTEXPR auto nth = sprout::nth_element( sprout::sub(arr1, 2, 8), sprout::begin(arr1) + 4, testspr::less() ); TESTSPR_DOUBLE_ASSERT(testspr::equal( nth, array{{2, 3, 5, 9, 8, 6}} )); TESTSPR_DOUBLE_ASSERT(testspr::equal( sprout::get_fixed(nth), array{{10, 7, 2, 3, 5, 9, 8, 6, 4, 1}} )); } { SPROUT_STATIC_CONSTEXPR auto nth = sprout::fit::nth_element( sprout::sub(arr1, 2, 8), sprout::begin(arr1) + 4, testspr::less() ); TESTSPR_DOUBLE_ASSERT(testspr::equal( nth, array{{2, 3, 5}} )); TESTSPR_DOUBLE_ASSERT(testspr::equal( sprout::get_fixed(nth), array{{10, 7, 2, 3, 5, 9, 8, 6, 4, 1}} )); } } } } // namespace testspr #endif // #ifndef TESTSPR_SPROUT_ALGORITHM_NTH_ELEMENT_HPP