コード例 #1
0
bool Test::test9()
{
        DoubleLinkedList<int> list;
        bool isPassed = false;

        std::cerr << "Test 9: find returns false when value not in list:  ";

        //add values from 0 to TEST_SIZE-1 inclusively
        for(int i=0; i<TEST_SIZE; i++)
        {
                list.pushFront(i);
        }

        //find value not in list
        if( list.find(-1) == nullptr )
        {
                isPassed = true;
                std::cerr << "PASSED" << std::endl;
        }
        else
        {
                std::cerr << "FAILED" << std::endl;
        }

        return (isPassed);
}
コード例 #2
0
bool Test::test10()
{
        DoubleLinkedList<int> list;
        bool isPassed = true;

        std::cerr << "Test 10: find returns point to node when value is in large list:  \n";

        //Add values 0-(TEST_SIZE-1)
        for(int i=0; i<TEST_SIZE; i++)
        {
                std::cerr << '\r' << "\tAdding " << (i+1) << "/" << TEST_SIZE << " nodes.  ";

                //Add every other node using pushBack
                if( i%2 == 0)
                {
                        list.pushBack(i);
                }
                else
                {
                        list.pushFront(i);
                }

                std::cerr.flush();
        }

        //find for all added values. Set flag if any value is not found
        for(int i=0; i<TEST_SIZE; i++)
        {
                std::cerr << '\r' << "\tfinding " << (i+1) << "/" << TEST_SIZE << " nodes.  ";
                Node<int>* temp = list.find(i);

                if( temp == nullptr || temp->getValue() != i)
                {
                        isPassed = false;
                }
                std::cerr.flush();
        }

        if(isPassed)
        {
                std::cerr << "PASSED" << std::endl;
        }
        else
        {
                std::cerr << "FAILED" << std::endl;
        }

        return (isPassed);
}
コード例 #3
0
bool Test::test8()
{
        DoubleLinkedList<int> list;
        bool isPassed = false;

        std::cerr << "Test 8: find returns nullptr on empty list:  ";

        if( list.find(42) == nullptr )
        {
                isPassed = true;
                std::cerr << "PASSED" << std::endl;
        }
        else
        {
                std::cerr << "FAILED" << std::endl;
        }

        return (isPassed);
}