コード例 #1
0
ファイル: Test.cpp プロジェクト: hamzasclone2/EECS-268
bool Test::test17()
{
	LinkedList list;
	bool isPassed = true;
	int num=0;


	std::cerr << "Test 17: order preserved by removeFront on populated 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 ";
		list.addBack(i);
		std::cerr.flush();
	}

	//Remove half of the node
	for(int i=0; i<TEST_SIZE/2; i++)
	{
		list.removeFront();
	}


	redirectOS();
	ss_redirect.clear();
	list.printList();
	restoreOS();

	//Check the order of the printed list
	for(int i=TEST_SIZE/2; i<TEST_SIZE; i++)
	{
		ss_redirect >> num;

		if( i!=num )
		{
			isPassed = false;
		}
	}

	if(isPassed)
	{
		std::cerr << "PASS" << std::endl;
	}
	else
	{
		std::cerr << "FAIL" << std::endl;
	}

	return (isPassed);
}
コード例 #2
0
ファイル: Test.cpp プロジェクト: chengyeh/EECS268
bool Test::test4()
{
	Stack<int> s;

	std::cout << "Test 4: printStack an empty list : ";

	// this test only tries to trigger a seg fault

    	redirectOS();
	ss_redirect.clear();
	s.printStack();
	restoreOS();

	std::cout << "PASS" << std::endl;

	return true;
}
コード例 #3
0
ファイル: Test.cpp プロジェクト: hamzasclone2/EECS-268
bool Test::test12()
{
	LinkedList list;
	bool isPassed = true;
	int num=0;


	std::cerr << "Test 12: printList prints the contents of large list correctly \n";

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

	redirectOS();
	ss_redirect.clear();
	list.printList();
	restoreOS();

	//Check the order of the numbers produced by the printList call
	for(int i=0; i<TEST_SIZE; i++)
	{
		ss_redirect >> num;

		if( i!=num )
		{
			isPassed = false;
		}
	}

	if(isPassed)
	{
		std::cerr << "PASS" << std::endl;
	}
	else
	{
		std::cerr << "FAIL" << std::endl;
	}

	return (isPassed);
}
コード例 #4
0
bool Test::test28()
{
        DoubleLinkedList<int> list;
        bool isPassed = false;
        int num1=0, num2=0;

        std::cerr << "Test 28: insertAhead of list size 1 retains list order:";
        list.pushBack(1);


        try
        {
                list.insertAhead(1,0);

                redirectOS();
                ss_redirect.clear();
                list.printList();
                restoreOS();

                ss_redirect >> num1;
                ss_redirect >> num2;

                if(num1 == 0 && num2 == 1)
                {
                        isPassed = true;
                }
        }
        catch(std::exception& e)
        {
                std::cerr << "\nException thrown! ";
                isPassed = false;
        }

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

        return(isPassed);
}
コード例 #5
0
ファイル: Test.cpp プロジェクト: KueiHsienChu/EECS_268
bool Test::test10()
{
	Stack<int> stack;
	bool isPassed = false;
	printTestMessage(10, "print on empty list print empty string");

	redirectOS();
	ss_redirect.clear();
	stack.print();
	restoreOS();

	if(ss_redirect.str().length() == 0)
	{
		isPassed = true;
	}

	printPassFail(isPassed);	
	return(isPassed);
}
コード例 #6
0
ファイル: Test.cpp プロジェクト: KueiHsienChu/EECS_268
bool Test::test12()
{
	Stack<int> stack;
	int num = 0;
	bool isPassed = true;
	printTestMessage(12, "print after lots of pushes, pops, and peeks retains order");

	loadValues(stack);
	
	std::cerr << std::endl;	
	//Remove half the stack
	for(int i=0; i<TEST_SIZE/2; i++)
	{
		
		//call peek just to ensure peek does not alter order
		std::cerr << '\r' << "\tpeeking at and popping " << (i+1) << "/" << TEST_SIZE/2 << " nodes.  "; 
		stack.peek();
		stack.pop();
		std::cerr.flush();
	}

	redirectOS();
	ss_redirect.clear();
	stack.print();
	restoreOS();

	//sizes will be printed in reverse, since you know, stacks.
	for(int i=(TEST_SIZE/2)-1; i>=0; i--)
	{
		ss_redirect >> num;
		
		if( i!=num )
		{
			isPassed = false;
		}
	}
	
	printPassFail(isPassed);	
	return(isPassed);
}
コード例 #7
0
bool Test::test23()
{
        DoubleLinkedList<int> list;
        bool isPassed = true;
        int num = 0;

        std::cerr << "Test 23: order preserved by remove(value) on populated list\n";

        for(int i=0; i<TEST_SIZE; i++)
        {
                std::cerr << '\r' << "\tAdding " << (i+1) << "/" << TEST_SIZE << " nodes. ";
                list.pushBack(i);
                std::cerr.flush();
        }

        std::cerr << std::endl;

        for(int i=0; i<TEST_SIZE; i++)
        {
                std::cerr << '\r' << "\tRemoving " << (i+1)/2 << "/" << TEST_SIZE/2 << " nodes. ";
                if(i%2 == 0)
                {
                        list.remove(i);
                }
                std::cerr.flush();
        }
        std::cerr << std::endl;

        redirectOS();
        ss_redirect.clear();
        list.printList();
        restoreOS();

        int count=1;
        //Check the order of the printed list
        for(int i=1; i<TEST_SIZE; i+=2)
        {
                ss_redirect >> num;

                if( i!=num )
                {
                        isPassed = false;
                }

                std::cerr << '\r' << "\tChecking " << count << "/" << TEST_SIZE/2 << " nodes. ";
                std::cerr.flush();
                count++;
        }

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

        return(isPassed);

}
コード例 #8
0
bool Test::test31()
{
        DoubleLinkedList<int> list;
        bool isPassed = true;
        bool isExceptionThrown = false;
        int num=0;
        int count=0;

        std::cerr << "Test 31: insertBehind on large list retains list order \n";

        count=1;//keep track of how many nodes are added
        //Add even numbers from 0 to TEST_SIZE to list
        for(int i=0; i<TEST_SIZE; i+=2)
        {
                std::cerr << '\r' << "\tAdding " << count << "/" << TEST_SIZE/2 << " nodes.";
                list.pushBack(i);
                std::cerr.flush();
                count++;
        }
        std::cerr << std::endl;

        count=1;//keep track of how many nodes are added
        //insert odd numbers from 1 to TEST_SIZE to list
        for(int i=1; i<TEST_SIZE; i+=2)
        {
                std::cerr << '\r' << "\tInserting " << count << "/" << TEST_SIZE/2 << " nodes.";
                try
                {
                        list.insertBehind(i-1, i);
                }
                catch(std::exception& e)
                {
                        isExceptionThrown = true;
                }
                std::cerr.flush();
                count++;
        }
        std::cerr << std::endl;

        if(isExceptionThrown)
        {
                std::cerr << "Exception was thrown during insertion!\n";
        }

        redirectOS();
        ss_redirect.clear();
        list.printList();
        restoreOS();

        //Check the order of the numbers produced by the printList call
        for(int i=0; i<TEST_SIZE; i++)
        {
                ss_redirect >> num;

                if( i!=num )
                {
                        isPassed = false;
                }

                std::cerr << '\r' << "\tChecking " << (i+1) << "/" << TEST_SIZE << " nodes. ";
                std::cerr.flush();
        }

        isPassed = isPassed && !isExceptionThrown;

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

        return (isPassed);
}