Some more thorough checking of Find(), which revealed small problems.
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@3753 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -428,7 +428,27 @@ public:
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
Iterator Find(const Value &value, const Iterator &_start = Begin())
|
Iterator Find(const Value &value)
|
||||||
|
{
|
||||||
|
Iterator start(Begin());
|
||||||
|
if (start.fReferenceIterator != fReferenceVector.end()) {
|
||||||
|
for (; start.fReferenceIterator != fReferenceVector.end();
|
||||||
|
++start.fReferenceIterator, ++start.fMyIterator) {
|
||||||
|
if (*start.fReferenceIterator == value) {
|
||||||
|
MyIterator myIt = fMyVector.Find(value);
|
||||||
|
CHK(&*myIt == &*start.fMyIterator);
|
||||||
|
return start;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
CHK(fMyVector.Find(value) == fMyVector.End());
|
||||||
|
CHK(start.fMyIterator == fMyVector.End());
|
||||||
|
return start;
|
||||||
|
}
|
||||||
|
CHK(fMyVector.Find(value) == fMyVector.End());
|
||||||
|
return start;
|
||||||
|
}
|
||||||
|
|
||||||
|
Iterator Find(const Value &value, const Iterator &_start)
|
||||||
{
|
{
|
||||||
Iterator start(_start);
|
Iterator start(_start);
|
||||||
if (start.fReferenceIterator != fReferenceVector.end()) {
|
if (start.fReferenceIterator != fReferenceVector.end()) {
|
||||||
@@ -449,8 +469,27 @@ public:
|
|||||||
return start;
|
return start;
|
||||||
}
|
}
|
||||||
|
|
||||||
ConstIterator Find(const Value &value,
|
ConstIterator Find(const Value &value) const
|
||||||
const ConstIterator &_start = Begin()) const
|
{
|
||||||
|
ConstIterator start(Begin());
|
||||||
|
if (start.fReferenceIterator != fReferenceVector.end()) {
|
||||||
|
for (; start.fReferenceIterator != fReferenceVector.end();
|
||||||
|
++start.fReferenceIterator, ++start.fMyIterator) {
|
||||||
|
if (*start.fReferenceIterator == value) {
|
||||||
|
MyConstIterator myIt = fMyVector.Find(value);
|
||||||
|
CHK(&*myIt == &*start.fMyIterator);
|
||||||
|
return start;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
CHK(fMyVector.Find(value) == fMyVector.End());
|
||||||
|
CHK(start.fMyIterator == fMyVector.End());
|
||||||
|
return start;
|
||||||
|
}
|
||||||
|
CHK(fMyVector.Find(value) == fMyVector.End());
|
||||||
|
return start;
|
||||||
|
}
|
||||||
|
|
||||||
|
ConstIterator Find(const Value &value, const ConstIterator &_start) const
|
||||||
{
|
{
|
||||||
ConstIterator start(_start);
|
ConstIterator start(_start);
|
||||||
if (start.fReferenceIterator != fReferenceVector.end()) {
|
if (start.fReferenceIterator != fReferenceVector.end()) {
|
||||||
@@ -831,6 +870,7 @@ GenericFindTest(ValueStrategy strategy, int32 maxNumber)
|
|||||||
typedef typename ValueStrategy::Value Value;
|
typedef typename ValueStrategy::Value Value;
|
||||||
TestVector<Value> v;
|
TestVector<Value> v;
|
||||||
GenericFill(v, strategy, maxNumber);
|
GenericFill(v, strategy, maxNumber);
|
||||||
|
// find the values in the vector
|
||||||
const TestVector<Value> &cv = v;
|
const TestVector<Value> &cv = v;
|
||||||
for (int32 i = 0; i < maxNumber; i++) {
|
for (int32 i = 0; i < maxNumber; i++) {
|
||||||
TestVector<Value>::ConstIterator cit = cv.Begin();
|
TestVector<Value>::ConstIterator cit = cv.Begin();
|
||||||
@@ -844,6 +884,14 @@ GenericFindTest(ValueStrategy strategy, int32 maxNumber)
|
|||||||
index = v.IndexOf(v[i], index + 1);
|
index = v.IndexOf(v[i], index + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// try to find some random values
|
||||||
|
for (int32 i = 0; i < maxNumber; i++) {
|
||||||
|
Value value = strategy.Generate();
|
||||||
|
TestVector<Value>::Iterator it = v.Find(value);
|
||||||
|
TestVector<Value>::ConstIterator cit = cv.Find(value);
|
||||||
|
if (it != v.End())
|
||||||
|
CHK(&*it == &*cit);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// FindTest
|
// FindTest
|
||||||
|
|||||||
Reference in New Issue
Block a user