private bool VerifyEnumerator( IEnumerator enumerator, Object[] expectedItems, int startIndex, int count, ExpectedEnumeratorRange expectedEnumeratorRange) { return(VerifyEnumerator(enumerator, expectedItems, startIndex, count, expectedEnumeratorRange, false)); }
private bool VerifyEnumerator( IEnumerator <T> enumerator, T[] expectedItems, int startIndex, int count, ExpectedEnumeratorRange expectedEnumeratorRange, bool looseMatchingUnspecifiedOrder) { bool retValue = true; int iterations = 0; if ((expectedEnumeratorRange & ExpectedEnumeratorRange.Start) != 0) { //[] Verify non deterministic behavior of current every time it is called before a call to MoveNext() has been made for (int i = 0; i < 3; i++) { try { T tempCurrent = enumerator.Current; } catch (Exception) { } } } if (_collectionOrder == CollectionOrder.Unspecified) { System.Collections.BitArray itemsVisited; bool itemFound; if (looseMatchingUnspecifiedOrder) { itemsVisited = new System.Collections.BitArray(expectedItems.Length, false); } else { itemsVisited = new System.Collections.BitArray(count, false); } while ((iterations < count) && enumerator.MoveNext()) { T currentItem = enumerator.Current; T tempItem; //[] Verify we have not gotten more items then we expected retValue &= m_test.Eval(iterations < count, "Err_9844awpa More items have been returned fromt the enumerator({0} items) then are " + "in the expectedElements({1} items)", iterations, count); //[] Verify Current returned the correct value itemFound = false; for (int i = 0; i < itemsVisited.Length; ++i) { if (!itemsVisited[i] && _comparer.Equals(currentItem, expectedItems[startIndex + i])) { itemsVisited[i] = true; itemFound = true; break; } } retValue &= m_test.Eval(itemFound, "Err_1432pauy Current returned unexpected value={0}", currentItem); //[] Verify Current always returns the same value every time it is called for (int i = 0; i < 3; i++) { tempItem = enumerator.Current; retValue &= m_test.Eval(_comparer.Equals(currentItem, tempItem), "Err_8776phaw Current is returning inconsistant results Current returned={0} expected={1}", tempItem, currentItem); } iterations++; } if (looseMatchingUnspecifiedOrder) { int visitedItemsCount = 0; for (int i = 0; i < itemsVisited.Length; ++i) { if (itemsVisited[i]) { ++visitedItemsCount; } } m_test.Eval(count, visitedItemsCount, "Err_2398289aheid Number of items enumerator returned"); } else { for (int i = 0; i < count; ++i) { retValue &= m_test.Eval(itemsVisited[i], "Err_052848ahiedoi Expected Current to return {0}", expectedItems[startIndex + i]); } } } else { while ((iterations < count) && enumerator.MoveNext()) { T currentItem = enumerator.Current; T tempItem; //[] Verify we have not gotten more items then we expected retValue &= m_test.Eval(iterations < count, "Err_9844awpa More items have been returned fromt the enumerator({0} items) then are " + "in the expectedElements({1} items)", iterations, count); //[] Verify Current returned the correct value retValue &= m_test.Eval(_comparer.Equals(currentItem, expectedItems[startIndex + iterations]), "Err_1432pauy Current returned unexpected value={0} expected={1}", currentItem, expectedItems[startIndex + iterations]); //[] Verify Current always returns the same value every time it is called for (int i = 0; i < 3; i++) { tempItem = enumerator.Current; retValue &= m_test.Eval(_comparer.Equals(currentItem, tempItem), "Err_8776phaw Current is returning inconsistant results Current returned={0} expected={1}", tempItem, currentItem); } iterations++; } } retValue &= m_test.Eval(count, iterations, "Err_658805eauz Number of items to iterate through"); if ((expectedEnumeratorRange & ExpectedEnumeratorRange.End) != 0) { for (int i = 0; i < 3; i++) { retValue &= m_test.Eval(!enumerator.MoveNext(), "Err_2929ahiea Expected MoveNext to return false after {0} iterations", iterations); } //[] Verify non deterministic behavior of current every time it is called after the enumerator is positioned after the last item for (int i = 0; i < 3; i++) { try { T tempCurrent = enumerator.Current; } catch (Exception) { } } } return(retValue); }
private bool VerifyEnumerator( IEnumerator enumerator, Object[] expectedItems, int startIndex, int count, ExpectedEnumeratorRange expectedEnumeratorRange, bool looseMatchingUnspecifiedOrder) { bool retValue = true; int iterations = 0; int i; bool scenarioResult; //[] Verify Current throws every time it is called before a call to MoveNext() has been made if ((expectedEnumeratorRange & ExpectedEnumeratorRange.Start) != 0) { for (i = 0, scenarioResult = true; i < 3 && scenarioResult; i++) { try { Object tempCurrent = enumerator.Current; retValue &= scenarioResult = m_test.Eval(_isGenericCompatibility, "Err_9484epha Expected Current to throw InvalidOperationException before MoveNext() " + "has been called and nothing was thrown Iterations({0})", i); } catch (InvalidOperationException) { } catch (Exception e) { retValue &= scenarioResult = m_test.Eval(_isGenericCompatibility, "Err_6458ahphl Expected Current to throw InvalidOperationException before MoveNext() " + "has been called and the following exception was thrown Iterations({0}): \n{1}", i, e); } } } scenarioResult = true; if (_collectionOrder == CollectionOrder.Unspecified) { System.Collections.BitArray itemsVisited; bool itemFound; if (looseMatchingUnspecifiedOrder) { itemsVisited = new System.Collections.BitArray(expectedItems.Length, false); } else { itemsVisited = new System.Collections.BitArray(count, false); } while ((iterations < count) && enumerator.MoveNext()) { Object currentItem = enumerator.Current; Object tempItem; //[] Verify we have not gotten more items then we expected retValue &= m_test.Eval(iterations < count, "Err_9844awpa More items have been returned fromt the enumerator({0} items) then are " + "in the expectedElements({1} items)", iterations, count); //[] Verify Current returned the correct value itemFound = false; if (looseMatchingUnspecifiedOrder) { for (i = 0; i < itemsVisited.Length; ++i) { if (!itemsVisited[i] && _comparer.Equals(currentItem, expectedItems[i])) { itemsVisited[i] = true; itemFound = true; break; } } } else { for (i = 0; i < itemsVisited.Length; ++i) { if (!itemsVisited[i] && _comparer.Equals(currentItem, expectedItems[startIndex + i])) { itemsVisited[i] = true; itemFound = true; break; } } } retValue &= m_test.Eval(itemFound, "Err_1432pauy Current returned unexpected value={0}", currentItem); //[] Verify Current always returns the same value every time it is called for (i = 0; i < 3; i++) { tempItem = enumerator.Current; retValue &= m_test.Eval(_comparer.Equals(currentItem, tempItem), "Err_8776phaw Current is returning inconsistant results Current returned={0} expected={1}", tempItem, currentItem); } iterations++; } if (looseMatchingUnspecifiedOrder) { int visitedItemsCount = 0; for (i = 0; i < itemsVisited.Length; ++i) { if (itemsVisited[i]) { ++visitedItemsCount; } } m_test.Eval(count, visitedItemsCount, "Err_2398289aheid Number of items enumerator returned"); } else { for (i = 0; i < count; ++i) { retValue &= m_test.Eval(itemsVisited[i], "Err_052848ahiedoi Expected Current to return {0}", expectedItems[startIndex + i]); } } } else { while ((iterations < count) && enumerator.MoveNext()) { Object currentItem = enumerator.Current; Object tempItem; //[] Verify we have not gotten more items then we expected retValue &= m_test.Eval(iterations < count, "Err_9844awpa More items have been returned fromt the enumerator({0} items) then are " + "in the expectedElements({1} items)", iterations, count); //[] Verify Current returned the correct value retValue &= m_test.Eval(_comparer.Equals(currentItem, expectedItems[startIndex + iterations]), "Err_1432pauy Current returned unexpected value={0} expected={1}", currentItem, expectedItems[startIndex + iterations]); //[] Verify Current always returns the same value every time it is called for (i = 0; i < 3; i++) { tempItem = enumerator.Current; retValue &= m_test.Eval(_comparer.Equals(currentItem, tempItem), "Err_8776phaw Current is returning inconsistant results Current returned={0} expected={1}", tempItem, currentItem); } iterations++; } } retValue &= m_test.Eval(count, iterations, "Err_189180ahieas Items iterated through"); if ((expectedEnumeratorRange & ExpectedEnumeratorRange.End) != 0) { //[] Verify MoveNext returns false every time it is called after the end of the collection has been reached for (i = 0, scenarioResult = true; i < 3 && scenarioResult; i++) { retValue &= scenarioResult &= m_test.Eval(!enumerator.MoveNext(), "Err_051896aheid Expected MoveNext to return false iteration {0}", i); } //[] Verify Current throws every time it is called after the end of the collection has been reached for (i = 0, scenarioResult = true; i < 3 && scenarioResult; i++) { try { Object tempCurrent = enumerator.Current; retValue &= scenarioResult = m_test.Eval(_isGenericCompatibility, "Err_7848pjy Expected Current to throw InvalidOperationException after the end of the collection " + "has been reached and nothing was thrown Iterations({0})", i); } catch (InvalidOperationException) { } catch (Exception e) { retValue &= scenarioResult = m_test.Eval(_isGenericCompatibility, "Err_31549hpnl Expected Current to throw InvalidOperationException after the end of the collection " + "has been reache and the following exception was thrown Iterations({0}): \n{1}", i, e); } } } return retValue; }
private bool VerifyEnumerator( IEnumerator enumerator, Object[] expectedItems, int startIndex, int count, ExpectedEnumeratorRange expectedEnumeratorRange) { return VerifyEnumerator(enumerator, expectedItems, startIndex, count, expectedEnumeratorRange, false); }
private bool VerifyEnumerator( IEnumerator enumerator, Object[] expectedItems, int startIndex, int count, ExpectedEnumeratorRange expectedEnumeratorRange, bool looseMatchingUnspecifiedOrder) { bool retValue = true; int iterations = 0; int i; bool scenarioResult; //[] Verify Current throws every time it is called before a call to MoveNext() has been made if ((expectedEnumeratorRange & ExpectedEnumeratorRange.Start) != 0) { for (i = 0, scenarioResult = true; i < 3 && scenarioResult; i++) { try { Object tempCurrent = enumerator.Current; retValue &= scenarioResult = m_test.Eval(_isGenericCompatibility, "Err_9484epha Expected Current to throw InvalidOperationException before MoveNext() " + "has been called and nothing was thrown Iterations({0})", i); } catch (InvalidOperationException) { } catch (Exception e) { retValue &= scenarioResult = m_test.Eval(_isGenericCompatibility, "Err_6458ahphl Expected Current to throw InvalidOperationException before MoveNext() " + "has been called and the following exception was thrown Iterations({0}): \n{1}", i, e); } } } scenarioResult = true; if (_collectionOrder == CollectionOrder.Unspecified) { System.Collections.BitArray itemsVisited; bool itemFound; if (looseMatchingUnspecifiedOrder) { itemsVisited = new System.Collections.BitArray(expectedItems.Length, false); } else { itemsVisited = new System.Collections.BitArray(count, false); } while ((iterations < count) && enumerator.MoveNext()) { Object currentItem = enumerator.Current; Object tempItem; //[] Verify we have not gotten more items then we expected retValue &= m_test.Eval(iterations < count, "Err_9844awpa More items have been returned fromt the enumerator({0} items) then are " + "in the expectedElements({1} items)", iterations, count); //[] Verify Current returned the correct value itemFound = false; if (looseMatchingUnspecifiedOrder) { for (i = 0; i < itemsVisited.Length; ++i) { if (!itemsVisited[i] && _comparer.Equals(currentItem, expectedItems[i])) { itemsVisited[i] = true; itemFound = true; break; } } } else { for (i = 0; i < itemsVisited.Length; ++i) { if (!itemsVisited[i] && _comparer.Equals(currentItem, expectedItems[startIndex + i])) { itemsVisited[i] = true; itemFound = true; break; } } } retValue &= m_test.Eval(itemFound, "Err_1432pauy Current returned unexpected value={0}", currentItem); //[] Verify Current always returns the same value every time it is called for (i = 0; i < 3; i++) { tempItem = enumerator.Current; retValue &= m_test.Eval(_comparer.Equals(currentItem, tempItem), "Err_8776phaw Current is returning inconsistant results Current returned={0} expected={1}", tempItem, currentItem); } iterations++; } if (looseMatchingUnspecifiedOrder) { int visitedItemsCount = 0; for (i = 0; i < itemsVisited.Length; ++i) { if (itemsVisited[i]) { ++visitedItemsCount; } } m_test.Eval(count, visitedItemsCount, "Err_2398289aheid Number of items enumerator returned"); } else { for (i = 0; i < count; ++i) { retValue &= m_test.Eval(itemsVisited[i], "Err_052848ahiedoi Expected Current to return {0}", expectedItems[startIndex + i]); } } } else { while ((iterations < count) && enumerator.MoveNext()) { Object currentItem = enumerator.Current; Object tempItem; //[] Verify we have not gotten more items then we expected retValue &= m_test.Eval(iterations < count, "Err_9844awpa More items have been returned fromt the enumerator({0} items) then are " + "in the expectedElements({1} items)", iterations, count); //[] Verify Current returned the correct value retValue &= m_test.Eval(_comparer.Equals(currentItem, expectedItems[startIndex + iterations]), "Err_1432pauy Current returned unexpected value={0} expected={1}", currentItem, expectedItems[startIndex + iterations]); //[] Verify Current always returns the same value every time it is called for (i = 0; i < 3; i++) { tempItem = enumerator.Current; retValue &= m_test.Eval(_comparer.Equals(currentItem, tempItem), "Err_8776phaw Current is returning inconsistant results Current returned={0} expected={1}", tempItem, currentItem); } iterations++; } } retValue &= m_test.Eval(count, iterations, "Err_189180ahieas Items iterated through"); if ((expectedEnumeratorRange & ExpectedEnumeratorRange.End) != 0) { //[] Verify MoveNext returns false every time it is called after the end of the collection has been reached for (i = 0, scenarioResult = true; i < 3 && scenarioResult; i++) { retValue &= scenarioResult &= m_test.Eval(!enumerator.MoveNext(), "Err_051896aheid Expected MoveNext to return false iteration {0}", i); } //[] Verify Current throws every time it is called after the end of the collection has been reached for (i = 0, scenarioResult = true; i < 3 && scenarioResult; i++) { try { Object tempCurrent = enumerator.Current; retValue &= scenarioResult = m_test.Eval(_isGenericCompatibility, "Err_7848pjy Expected Current to throw InvalidOperationException after the end of the collection " + "has been reached and nothing was thrown Iterations({0})", i); } catch (InvalidOperationException) { } catch (Exception e) { retValue &= scenarioResult = m_test.Eval(_isGenericCompatibility, "Err_31549hpnl Expected Current to throw InvalidOperationException after the end of the collection " + "has been reache and the following exception was thrown Iterations({0}): \n{1}", i, e); } } } return(retValue); }