Example #1
0
void turnTurtleLeftTest()	{
	enterSuite("Turning Turtle AntiClockWise");
	setAngle(0);
	testVal(turnTurtleLeft(90),270,"Valid: Turning turtle facing 0 degrees anti-clockwise 90 degrees",EQUALS);
	testVal(turnTurtleLeft(240),30,"Valid: Turning turtle facing 270 degrees anti-clockwise 240 degrees",EQUALS);
	testVal(turnTurtleLeft(110),280,"Valid: Turning turtle facing 30 degrees anti-clockwise 110 degrees",EQUALS);
	initTurtle();	
	leaveSuite();
}
Example #2
0
void turnTurtleRightTest()	{

	enterSuite("Turning Turtle ClockWise");
	setAngle(0);
	testVal((int) turnTurtleRight(90),90,"Valid: Turning turtle facing 0 degrees clockwise 90 degrees",EQUALS);
	testVal((int) turnTurtleRight(360),90,"Valid: Turning turtle facing 90 degrees clockwise 360 degrees",EQUALS);
	testVal((int) turnTurtleRight(270),0,"Valid: Turning turtle facing 90 degrees clockwise 270 degrees",EQUALS);
	setAngle(330);
	testVal((int) turnTurtleRight(100),70,"Valid: Turning turtle facing 330 degrees clockwise 100 degrees",EQUALS);
	initTurtle();
	leaveSuite();
}
int main()
{
    int a[] = {1, 4, 3 ,8, 9};

    for(int i=0; i<5; ++i)
    {
        setVal(a[i]);
    }

    std::cout << testVal(5) << std::endl;

    return 0;
}
Example #4
0
// returns true if the bitvector maps all of its variables to val and false otherwise
bool VarBitVector::isAllEq(bool val)
{
        VarBitVector::boolPlus testVal(val);
        return isAllEq(testVal);
}
void CGroupViewTester::HandleContactViewEvent( const CContactViewBase& aView,
    const TContactViewEvent& aEvent )
	{
    // Log events from both underlying view and group view.
    LogEvent( const_cast<TContactViewEvent&>( aEvent ) );

	switch (iCurrentTest)
		{
		case ECreateLocalView:
			test(iLocalView==&aView);
			test(aEvent.iEventType==TContactViewEvent::EReady);
			break;

		case ECreateGroupOneView:
			{
			test(iGroupViewOne == &aView);
			test(aEvent.iEventType == TContactViewEvent::EReady);

			//Reserve the IDs of last three contacts in the group
			TInt index = KNumContactsInGroupOne-1;
            TRAPD(err, iLastContactID = iGroupViewOne->ContactAtL(index).Id() );
			if (err)
				{
				_LIT(KErrMsg, "Contact view error in CGroupViewTester::HandleContactViewEvent() assigning iLastContactID\n");
				test.Printf(KErrMsg);
				User::Invariant();
				}

            --index;
            TRAP(err, iSecondLastContactID = iGroupViewOne->ContactAtL(index).Id() );
			if (err)
				{
				_LIT(KErrMsg, "Contact view error in CGroupViewTester::HandleContactViewEvent() assigning iSecondLastContactID\n");
				test.Printf(KErrMsg);
				User::Invariant();
				}

            --index;
            TRAP(err, iThirdLastContactID = iGroupViewOne->ContactAtL(index).Id() );
			if (err)
				{
				_LIT(KErrMsg, "Contact view error in CGroupViewTester::HandleContactViewEvent() assigning iThirdLastContactID\n");
				test.Printf(KErrMsg);
				User::Invariant();
				}

			}
			break;

        case ECreateGroupTwoView:
			test( iGroupViewTwo == &aView );
			test( aEvent.iEventType == TContactViewEvent::EReady );
            break;

        case EDeleteItemsFromView:
            {
            // Bulk delete complete when the last Ready is received from the 
            // base view. This comes after the group view ready event. Break to 
            // run next test.
            TBool lastEvent = (aEvent.iEventType == TContactViewEvent::EReady) &&
                (&aView == iLocalView);
            if (lastEvent) 
                { 
                break; 
                }

            if (aEvent.iEventType == TContactViewEvent::EItemRemoved)
                {
                // Only proces events from group view.
                if (&aView == iGroupViewOne)
                    {
                    // Ensure that only 1 contact is removed per notification.
                     iNumRemovedEvents++;
                    TInt numItemsExpected = KNumContactsInGroupOne - iNumRemovedEvents;
		            
		            TInt numItems(0);
		            TRAPD(err, numItems = iGroupViewOne->CountL() );
					if (err)
						{
						_LIT(KErrMsg, "Contact view error in CGroupViewTester::HandleContactViewEvent() assigning numItems\n");
						test.Printf(KErrMsg);
						User::Invariant();
						}
		            test(numItems == numItemsExpected );

                    // Verify the contacts were deleted as expected.
                    TBool testVal(EFalse);
                    TInt index = numItemsExpected - 1;
					TRAP(err, testVal = (iGroupViewOne->ContactAtL(index).Id() == iLastContactID) );
					if (err)
						{
						_LIT(KErrMsg, "Contact view error in CGroupViewTester::HandleContactViewEvent() assigning testVal for iLastContactID\n");
						test.Printf(KErrMsg);
						User::Invariant();
						}
					test(testVal);

                    --index;
					TRAP(err, testVal = (iGroupViewOne->ContactAtL(index).Id() == iSecondLastContactID) );
					if (err)
						{
						_LIT(KErrMsg, "Contact view error in CGroupViewTester::HandleContactViewEvent() assigning testVal for iSecondLastContactID\n");
						test.Printf(KErrMsg);
						User::Invariant();
						}
					test(testVal);

                    --index;
					TRAP(err, testVal = (iGroupViewOne->ContactAtL(index).Id() == iThirdLastContactID) );
					if (err)
						{
						_LIT(KErrMsg, "Contact view error in CGroupViewTester::HandleContactViewEvent() assigning testVal for iThirdLastContactID\n");
						test.Printf(KErrMsg);
						User::Invariant();
						}
					test(testVal);
                    }

                // More events expected, don't run next test.
                return;
                }
            else
                {
                // Ignore all other events.
                return;
                }
            }

        case EAddItemToGroup:
            {
            // Break to run next test if this is the last expected event. The last
            // event is the group being added from the base view. The local view
            // removes and then adds the group id whenever the group changes. These
            // events are meaningless.
            TBool lastEvent = (&aView == iLocalView) && 
                (aEvent.iEventType == TContactViewEvent::EItemAdded) &&
                (aEvent.iContactId == iGroupOneId);
            if (lastEvent)
                {
                break; // Run next test.
                }

            // Verify contact has been added.
            if (aEvent.iEventType == TContactViewEvent::EItemAdded && 
                &aView == iGroupViewOne)
                {
                // Check if contact was added.
                test( aEvent.iContactId == iIdAdded );

                TInt index = iGroupViewOne->FindL( iIdAdded );
                test (index != KErrNotFound);

                // More events expected, don't run next test.
                return;
                }
            else
                {
                // Ignore all other events.
                return;
                }
            }

		default:
			test( EFalse );
			break;
		}

    // Run the next test.
	if (--iNumNotificationExpected <= 0)
		{
		NextTest();
		iNumNotificationExpected = 0;
		}
	}