Skip to content

Commit 1e56660

Browse files
authored
Test coverage for search_n with impossible value (#5440)
1 parent 90ff1a6 commit 1e56660

File tree

1 file changed

+24
-8
lines changed
  • tests/std/tests/Dev11_0316853_find_memchr_optimization

1 file changed

+24
-8
lines changed

tests/std/tests/Dev11_0316853_find_memchr_optimization/test.cpp

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -767,18 +767,18 @@ int main() {
767767
}
768768

769769
{ // quick checks to exercise more codepaths with _Could_compare_equal_to_value_type()
770-
const vector<uint32_t> v{200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215};
770+
const vector<uint32_t> v{200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 205, 205, 205, 214, 215};
771771
const uint32_t u32{205};
772772
const uint64_t u64{0x1234'5678'0000'00CDull};
773773

774774
assert(u32 != u64); // u64 is out-of-range for uint32_t, so it can never compare equal...
775775
assert(u32 == static_cast<uint32_t>(u64)); // ... unless an algorithm performs an improper cast
776776

777-
assert(count(v.begin(), v.end(), u32) == 1);
777+
assert(count(v.begin(), v.end(), u32) == 4);
778778
assert(count(v.begin(), v.end(), u64) == 0);
779779

780780
#if _HAS_CXX20
781-
assert(ranges::count(v, u32) == 1);
781+
assert(ranges::count(v, u32) == 4);
782782
assert(ranges::count(v, u64) == 0);
783783
#endif // _HAS_CXX20
784784

@@ -793,7 +793,7 @@ int main() {
793793
#if _HAS_CXX23
794794
{
795795
const auto result = ranges::find_last(v, u32);
796-
assert(result.begin() == v.begin() + 5);
796+
assert(result.begin() == v.end() - 3);
797797
assert(result.end() == v.end());
798798
}
799799
{
@@ -803,11 +803,27 @@ int main() {
803803
}
804804
#endif // _HAS_CXX23
805805

806+
assert(search_n(v.begin(), v.end(), 2, u32) == v.end() - 5);
807+
assert(search_n(v.begin(), v.end(), 2, u64) == v.end());
808+
809+
#if _HAS_CXX20
810+
{
811+
const auto result = ranges::search_n(v, 2, u32);
812+
assert(begin(result) == v.end() - 5);
813+
assert(end(result) == v.end() - 3);
814+
}
815+
{
816+
const auto result = ranges::search_n(v, 2, u64);
817+
assert(begin(result) == v.end());
818+
assert(end(result) == v.end());
819+
}
820+
#endif // _HAS_CXX20
821+
806822
{
807-
const vector<uint32_t> rem{200, 201, 202, 203, 204, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 0};
823+
const vector<uint32_t> rem{200, 201, 202, 203, 204, 206, 207, 208, 209, 210, 214, 215, 0, 0, 0, 0};
808824

809825
vector<uint32_t> dst(v.size(), 0);
810-
assert(remove_copy(v.begin(), v.end(), dst.begin(), u32) == dst.end() - 1);
826+
assert(remove_copy(v.begin(), v.end(), dst.begin(), u32) == dst.end() - 4);
811827
assert(dst == rem);
812828

813829
dst.assign(v.size(), 0);
@@ -819,7 +835,7 @@ int main() {
819835
dst.assign(v.size(), 0);
820836
const auto result = ranges::remove_copy(v, dst.begin(), u32);
821837
assert(result.in == v.end());
822-
assert(result.out == dst.end() - 1);
838+
assert(result.out == dst.end() - 4);
823839
assert(dst == rem);
824840
}
825841
{
@@ -833,7 +849,7 @@ int main() {
833849
}
834850

835851
{
836-
const vector<uint32_t> rep{200, 201, 202, 203, 204, 333, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215};
852+
const vector<uint32_t> rep{200, 201, 202, 203, 204, 333, 206, 207, 208, 209, 210, 333, 333, 333, 214, 215};
837853
const uint32_t val{333};
838854

839855
vector<uint32_t> dst = v;

0 commit comments

Comments
 (0)