Пример #1
0
  // Launch unit test.
  EUnitTestResult test()
  { CALL
    CArray<Tsint> array;
    CListDC<Tsint> circle;
    CListDL<Tsint> list;

    // Fill the array.
    UT_ASSERT(array.insertLast(1));
    UT_ASSERT(array.insertLast(2));
    UT_ASSERT(array.insertLast(3));
    UT_ASSERT(array.insertLast(4));
    UT_ASSERT(array.insertLast(5));
    UT_ASSERT(array.insertLast(6));

    // Fill the double circled list.
    UT_ASSERT(circle.insertCurrentForward(1));
    UT_ASSERT(circle.insertNext(6));
    UT_ASSERT(circle.insertNext(5));
    UT_ASSERT(circle.insertNext(4));
    UT_ASSERT(circle.insertNext(3));
    UT_ASSERT(circle.insertNext(2));

    // Fill the double linked list.
    UT_ASSERT(list.insertLast(1));
    UT_ASSERT(list.insertLast(2));
    UT_ASSERT(list.insertLast(3));
    UT_ASSERT(list.insertLast(4));
    UT_ASSERT(list.insertLast(5));
    UT_ASSERT(list.insertLast(6));

    // Check counts.
    UT_ASSERT_EQUAL(count(array), 6);
    UT_ASSERT_EQUAL(countPrev(array.getItLast()), 6);
    UT_ASSERT_EQUAL(countNext(boundItForward(array.getItIndex(1), array.getItIndex(4))), 4);
    UT_ASSERT_EQUAL(countPrev(boundItBackward(array.getItIndex(3), array.getItIndex(2))), 2);
    UT_ASSERT_EQUAL(count(circle), 6);
    UT_ASSERT_EQUAL(countPrev(circle.getItCurrent().getBackward()), 6);
    UT_ASSERT_EQUAL(count(list), 6);
    UT_ASSERT_EQUAL(countPrev(list.getItLast()), 6);

    // Check conditional counts.
    UT_ASSERT_EQUAL(countIf(array, isOdd), 3);
    UT_ASSERT_EQUAL(countIfPrev(array.getItLast(), isOdd), 3);
    UT_ASSERT_EQUAL(countIfNext(boundItForward(array.getItIndex(1), array.getItIndex(4)), isOdd), 2);
    UT_ASSERT_EQUAL(countIfPrev(boundItBackward(array.getItIndex(3), array.getItIndex(2)), isOdd), 1);
    UT_ASSERT_EQUAL(countIf(circle, isOdd), 3);
    UT_ASSERT_EQUAL(countIfPrev(circle.getItCurrent().getBackward(), isOdd), 3);
    UT_ASSERT_EQUAL(countIf(list, isOdd), 3);
    UT_ASSERT_EQUAL(countIfPrev(list.getItLast(), isOdd), 3);

    UT_ACCEPT;
  }
Пример #2
0
 // Check the remove functionality of the CArray<Tsint>.
 void UT_ASSERT_CHECK_REMOVE(CArray<Tsint>& a_rArray, Tbool a_cDirectOrder, const Tbool a_cReversed = false)
 { CALL
   Tsint value = (a_cDirectOrder || a_cReversed) ? 1 : 6;
   CArray<Tsint>::TIterator it = (a_cDirectOrder ? a_rArray.getItFirst() : a_rArray.getItLast());
   while (it.isValid())
   {
     UT_ASSERT_EQUAL(*it, value);
     (a_cDirectOrder || a_cReversed) ? ++value : --value;
     UT_ASSERT(a_cDirectOrder ? it.removeForward() : it.removeBackward());
   }
   UT_ASSERT_EQUAL(value, ((a_cDirectOrder || a_cReversed) ? 7 : 0));
 }
 // Check the remove functionality of the CArray<Tbool>.
 void UT_ASSERT_CHECK_REMOVE(CArray<Tbool>& a_rArray, Tbool a_cDirectOrder, const Tbool a_cReversed = false)
 { CALL
   Tbool value = (a_cDirectOrder || a_cReversed) ? true : false;
   CArray<Tbool>::TIterator it = (a_cDirectOrder ? a_rArray.getItFirst() : a_rArray.getItLast());
   while (it.isValid())
   {
     UT_ASSERT_EQUAL(*it, value);
     value = !value;
     UT_ASSERT(a_cDirectOrder ? it.removeForward() : it.removeBackward());
   }
   UT_ASSERT((a_cDirectOrder || a_cReversed) ? (value == true) : (value == false));
 }
 // Remove all items from the instance of the CArray<Tbool> class.
 static void remove(IWriter& writer, CArray<Tbool>& a_rArray, const Tbool a_cDirectOrder)
 {   CALL
     writer << STR("CArray<Tbool>(") << STR("size = ") << a_rArray.getSize() << STR(")") << ln;
     CArray<Tbool>::TIterator it = (a_cDirectOrder ? a_rArray.getItFirst() : a_rArray.getItLast());
     writer << STR("{") << ln;
     while (it.isValid())
     {
         writer << STR(" removed item = ") << *it << ln;
         a_cDirectOrder ? it.removeForward() : it.removeBackward();
     }
     writer << STR("}") << ln;
 }
Пример #5
0
 // Check the show reversed functionality of the CArray<Tsint>.
 void UT_ASSERT_CHECK_SHOW_REVERSED(const CArray<Tsint>& a_crArray, const Tbool a_cDirectOrder)
 { CALL
   Tsint value = (a_cDirectOrder ? 6 : 1);
   CArray<Tsint>::TIteratorConst it = (a_cDirectOrder ? a_crArray.getItFirst() : a_crArray.getItLast());
   if (it.isValid())
   {
     do
     {
       UT_ASSERT_EQUAL(*it, value);
       (a_cDirectOrder) ? --value : ++value;
     } while ((a_cDirectOrder ? it.stepForward() : it.stepBackward()) == 1);
   }
   UT_ASSERT_EQUAL(value, (a_cDirectOrder ? 0 : 7));
 }
 // Check the show reversed functionality of the CArray<Tbool>.
 void UT_ASSERT_CHECK_SHOW_REVERSED(const CArray<Tbool>& a_crArray, const Tbool a_cDirectOrder)
 { CALL
   Tbool value = (a_cDirectOrder ? false : true);
   CArray<Tbool>::TIteratorConst it = (a_cDirectOrder ? a_crArray.getItFirst() : a_crArray.getItLast());
   if (it.isValid())
   {
     do
     {
       UT_ASSERT_EQUAL(*it, value);
       value = !value;
     } while ((a_cDirectOrder ? it.stepForward() : it.stepBackward()) == 1);
   }
   UT_ASSERT((a_cDirectOrder) ? !value : value);
 }
  // Launch unit test.
  EUnitTestResult test()
  { CALL
    CArray<Tsint> array;
    CListDC<Tsint> circle;
    CListDL<Tsint> list;

    // Fill the array.
    UT_ASSERT(array.insertLast(1));
    UT_ASSERT(array.insertLast(2));
    UT_ASSERT(array.insertLast(3));
    UT_ASSERT(array.insertLast(4));
    UT_ASSERT(array.insertLast(5));
    UT_ASSERT(array.insertLast(6));

    // Fill the double circled list.
    UT_ASSERT(circle.insertCurrentForward(1));
    UT_ASSERT(circle.insertNext(6));
    UT_ASSERT(circle.insertNext(5));
    UT_ASSERT(circle.insertNext(4));
    UT_ASSERT(circle.insertNext(3));
    UT_ASSERT(circle.insertNext(2));

    // Fill the double linked list.
    UT_ASSERT(list.insertLast(1));
    UT_ASSERT(list.insertLast(2));
    UT_ASSERT(list.insertLast(3));
    UT_ASSERT(list.insertLast(4));
    UT_ASSERT(list.insertLast(5));
    UT_ASSERT(list.insertLast(6));

    // Check upper bounds.
    UT_ASSERT(!upperBound(array, CONSTS(0)).isValid());
    UT_ASSERT_EQUAL(upperBound(array, CONSTS(1)).getValueRef(), 1);
    UT_ASSERT_EQUAL(upperBound(array, CONSTS(4)).getValueRef(), 4);
    UT_ASSERT_EQUAL(upperBound(array, CONSTS(6)).getValueRef(), 6);
    UT_ASSERT_EQUAL(upperBound(array, CONSTS(8)).getValueRef(), 6);
    UT_ASSERT(!upperBoundPrev(array.getItLast(), CONSTS(0)).isValid());
    UT_ASSERT_EQUAL(upperBoundPrev(array.getItLast(), CONSTS(1)).getValueRef(), 1);
    UT_ASSERT_EQUAL(upperBoundPrev(array.getItLast(), CONSTS(4)).getValueRef(), 4);
    UT_ASSERT_EQUAL(upperBoundPrev(array.getItLast(), CONSTS(6)).getValueRef(), 6);
    UT_ASSERT_EQUAL(upperBoundPrev(array.getItLast(), CONSTS(8)).getValueRef(), 6);
    UT_ASSERT(!upperBound(circle, CONSTS(0)).isValid());
    UT_ASSERT_EQUAL(upperBound(circle, CONSTS(1)).getValueRef(), 1);
    UT_ASSERT_EQUAL(upperBound(circle, CONSTS(4)).getValueRef(), 4);
    UT_ASSERT_EQUAL(upperBound(circle, CONSTS(6)).getValueRef(), 6);
    UT_ASSERT_EQUAL(upperBound(circle, CONSTS(8)).getValueRef(), 6);
    UT_ASSERT(!upperBoundPrev(circle.getItCurrent().getBackward(), CONSTS(0)).isValid());
    UT_ASSERT_EQUAL(upperBoundPrev(circle.getItCurrent().getBackward(), CONSTS(1)).getValueRef(), 1);
    UT_ASSERT_EQUAL(upperBoundPrev(circle.getItCurrent().getBackward(), CONSTS(4)).getValueRef(), 4);
    UT_ASSERT_EQUAL(upperBoundPrev(circle.getItCurrent().getBackward(), CONSTS(6)).getValueRef(), 6);
    UT_ASSERT_EQUAL(upperBoundPrev(circle.getItCurrent().getBackward(), CONSTS(8)).getValueRef(), 6);
    UT_ASSERT(!upperBound(list, CONSTS(0)).isValid());
    UT_ASSERT_EQUAL(upperBound(list, CONSTS(1)).getValueRef(), 1);
    UT_ASSERT_EQUAL(upperBound(list, CONSTS(4)).getValueRef(), 4);
    UT_ASSERT_EQUAL(upperBound(list, CONSTS(6)).getValueRef(), 6);
    UT_ASSERT_EQUAL(upperBound(list, CONSTS(8)).getValueRef(), 6);
    UT_ASSERT(!upperBoundPrev(list.getItLast(), CONSTS(0)).isValid());
    UT_ASSERT_EQUAL(upperBoundPrev(list.getItLast(), CONSTS(1)).getValueRef(), 1);
    UT_ASSERT_EQUAL(upperBoundPrev(list.getItLast(), CONSTS(4)).getValueRef(), 4);
    UT_ASSERT_EQUAL(upperBoundPrev(list.getItLast(), CONSTS(6)).getValueRef(), 6);
    UT_ASSERT_EQUAL(upperBoundPrev(list.getItLast(), CONSTS(8)).getValueRef(), 6);

    UT_ACCEPT;
  }