Merge pull request #9766 from DavidSamir/test/libc-vector-algorithms-sizes

test(libc): cover the sized find, count, min and max vector helpers
This commit is contained in:
Dean authored and GitHub committed 2026-10-25 19:06:50 +13:00
commit ec1fdd4e6d
1 file changed
+36
+36
View File
@@ -5,8 +5,43 @@
#include <cstdlib>
#include <cstring>
static void Require(bool value) { if (!value) std::abort(); }
static void CheckSizedHelpers() {
const std::uint8_t bytes[] = {3, 0xff, 3, 9, 0xff};
Require(__std_find_trivial_1_nid_postfix(bytes, bytes + 5, 0xff) == bytes + 1);
Require(__std_find_trivial_1_nid_postfix(bytes, bytes + 5, 4) == bytes + 5);
Require(__std_find_trivial_1_nid_postfix(bytes, bytes, 3) == bytes);
Require(__std_count_trivial_1_nid_postfix(bytes, bytes + 5, 3) == 2 && __std_count_trivial_1_nid_postfix(bytes, bytes + 5, 7) == 0);
Require(__std_max_element_1_nid_postfix(bytes, bytes + 5, false) == bytes + 1);
Require(__std_max_element_1_nid_postfix(bytes, bytes + 5, true) == bytes + 3);
const std::uint16_t halves[] = {0x8000, 5, 0x7fff, 5, 0x8000};
Require(__std_count_trivial_2_nid_postfix(halves, halves + 5, 5) == 2 && __std_count_trivial_2_nid_postfix(halves, halves, 5) == 0);
Require(__std_min_element_2_nid_postfix(halves, halves + 5, false) == halves + 1);
Require(__std_min_element_2_nid_postfix(halves, halves + 5, true) == halves);
Require(__std_max_element_2_nid_postfix(halves, halves + 5, false) == halves);
Require(__std_max_element_2_nid_postfix(halves, halves + 5, true) == halves + 2);
const std::uint32_t words[] = {7, 0xfffffff0u, 1, 1, 0xfffffff0u};
Require(__std_find_trivial_4_nid_postfix(words, words + 5, 1) == words + 2);
Require(__std_find_trivial_4_nid_postfix(words, words + 5, 2) == words + 5);
Require(__std_count_trivial_4_nid_postfix(words, words + 5, 0xfffffff0u) == 2);
Require(__std_min_element_4_nid_postfix(words, words + 5, false) == words + 2);
Require(__std_min_element_4_nid_postfix(words, words + 5, true) == words + 1);
Require(__std_min_element_4_nid_postfix(words, words, true) == words);
const std::uint64_t wides[] = {0x8000000000000000ull, 2, 0x7fffffffffffffffull, 0x8000000000000000ull};
Require(__std_find_trivial_8_nid_postfix(wides, wides + 4, 0x8000000000000000ull) == wides);
Require(__std_find_trivial_8_nid_postfix(wides + 1, wides + 4, 0x8000000000000000ull) == wides + 3);
Require(__std_min_element_8_nid_postfix(wides, wides + 4, true) == wides);
Require(__std_min_element_8_nid_postfix(wides, wides + 4, false) == wides + 1);
Require(__std_max_element_8_nid_postfix(wides, wides + 4, false) == wides);
Require(__std_max_element_8_nid_postfix(wides, wides + 4, true) == wides + 2);
Require(__std_max_element_8_nid_postfix(wides, wides, false) == wides);
}
static void CheckFindAndCount() {
const std::uint16_t halves[] = {5, 7, 9, 7};
Require(__std_find_trivial_2_nid_postfix(halves, halves + 4, 7) == halves + 1);
@@ -103,6 +138,7 @@ static void CheckReverseAndSwap() {
}
int main() {
CheckSizedHelpers();
CheckFindAndCount();
CheckUnsizedRescan();
CheckMinMax();