예제 #1
0
파일: lsq_tests.c 프로젝트: Taller/Rhonda
/* Test moving on list with setPosition */
void test4(void)
{
    int i, j;
    srand ( time(NULL) );
    LSQ_IteratorT iter = LSQ_GetFrontElement(handleAll);
    assert( iter != NULL);

//    print_LSQ(handleAll);
    printf("Testing SetPosition");
    for(i = 0; i < MAX_TEST_ATTEMPTS; i++)
    {
        j = rand() % 1000;
//        printf("\n Step = %d \t setPosition = %d ", i, j);
        LSQ_SetPosition(iter, j);
        if( j < LSQ_GetSize(handleAll))
        {
//            printf("\n Expecting value = %d \t ", all[j]);
//            printf("\n Found value = %d \t ", iter->self->value);
            assert( *LSQ_DereferenceIterator(iter) == all[j]);
            assert( *LSQ_DereferenceIterator(iter) != MAX_ELEMENT_VALUE + 1);
        } 
    }
    printf("\t\t ---\t OK \n");
    LSQ_DestroyIterator(iter);
}	
extern void LSQ_DeleteRearElement(LSQ_HandleT handle)
{
	LSQ_IteratorT iterator = LSQ_GetPastRearElement(handle);
	LSQ_RewindOneElement(iterator);
	LSQ_DeleteGivenElement(iterator);
	LSQ_DestroyIterator(iterator);
}
예제 #3
0
파일: lsq_tests.c 프로젝트: Taller/Rhonda
/* Test delete with DeleteRearElement */
void test9(void)
{
    int i, j;

    printf("Testing DeleteRearElement");
    while(LSQ_GetSize(handleAll))
    {
        LSQ_IteratorT iter = LSQ_GetFrontElement(handleAll);
        assert( iter != NULL);
//        print_LSQ(handleAll);
        for(j = 0; j < LSQ_GetSize(handleAll); j++)
        {
//            printf("\nFound = %d \t Expecting = %d \t at index = %d", *LSQ_DereferenceIterator(iter), all[j], j);
            assert( *LSQ_DereferenceIterator(iter) == all[j]);
            assert( *LSQ_DereferenceIterator(iter) != MAX_ELEMENT_VALUE + 1);
            LSQ_AdvanceOneElement(iter);
        }
        LSQ_DestroyIterator(iter);
        LSQ_DeleteRearElement(handleAll);
    }
    printf("\t\t ---\t OK \n");
    for(i = 0; i < MAX_handleALL_LEN; i++)
    {
        LSQ_InsertRearElement(handleAll, all[i]);
    }
}
예제 #4
0
파일: lsq_tests.c 프로젝트: Taller/Rhonda
/* Test moving on list with Advance/Rewind */
void test5(void)
{
    int i;
    LSQ_IteratorT iter = LSQ_GetFrontElement(handleAll);
    assert( iter != NULL);

//    print_LSQ(handleAll);
    printf("Testing Advance");
    for(i = 0; i < LSQ_GetSize(handleAll); i++)
    {
        assert( *LSQ_DereferenceIterator(iter) == all[i]);
        assert( *LSQ_DereferenceIterator(iter) != MAX_ELEMENT_VALUE + 1);
        LSQ_AdvanceOneElement(iter);
    }
    printf("\t\t ---\t OK \n");


    printf("Testing Rewind");
    iter = LSQ_GetPastRearElement(handleAll);
    for(i = LSQ_GetSize(handleAll)-1; i >= 0; i--)
    {
        LSQ_RewindOneElement(iter);
        assert( *LSQ_DereferenceIterator(iter) == all[i]);
        assert( *LSQ_DereferenceIterator(iter) != MAX_ELEMENT_VALUE + 1);
    }
    printf("\t\t ---\t OK \n");

    LSQ_DestroyIterator(iter);
}
예제 #5
0
extern void LSQ_DeleteRearElement(LSQ_HandleT handle)
{
	IteratorT *iterator = (IteratorT *)LSQ_GetPastRearElement(handle);
	LSQ_RewindOneElement(iterator);
	LSQ_DeleteElement(handle, iterator->node->key);
	LSQ_DestroyIterator(iterator);
}
예제 #6
0
/* Функция, удаляющая первый элемент контейнера */
void LSQ_DeleteFrontElement(LSQ_HandleT handle){
	TypeIterator *iterator = ITR(LSQ_GetFrontElement(handle));
	if(iterator != LSQ_HandleInvalid){
		LSQ_DeleteGivenElement(iterator);
		LSQ_DestroyIterator(iterator);
	}
}
예제 #7
0
파일: lsq_tests.c 프로젝트: Taller/Rhonda
/* Checking front and rear filling */
void test2(void)
{
    int i;
//    print_LSQ(handle);    

    LSQ_IteratorT iter = LSQ_GetFrontElement(handle);
    assert( iter != NULL);
    for(i = 49; i >= 0; i--)
    {
//        printf("front = %d \t index i = %d \t value = %d \n",front[i], i, *LSQ_DereferenceIterator(iter));
        assert( *LSQ_DereferenceIterator(iter) == front[i] );
        assert( *LSQ_DereferenceIterator(iter) != MAX_ELEMENT_VALUE + 1 );
        LSQ_AdvanceOneElement(iter);
    }

    LSQ_SetPosition(iter, LSQ_GetSize(handle)-1);
    assert( iter != NULL);

//    print_LSQ(handle);    
//    printf("iter = %p \t node = %p \t value = %d \n", iter, iter->self, iter->self->value);

    for(i = 49; i >= 0; i--)
    {
//        printf("rear = %d \t index i = %d \t value = %d \n",rear[i], i, *LSQ_DereferenceIterator(iter));
        assert( *LSQ_DereferenceIterator(iter) == rear[i] );
        assert( *LSQ_DereferenceIterator(iter) != MAX_ELEMENT_VALUE + 1 );
        LSQ_RewindOneElement(iter);
    }

//    print_LSQ(handle);
    LSQ_DestroyIterator(iter);

}
예제 #8
0
/* Функция, добавляющая элемент в конец контейнера */
void LSQ_InsertRearElement(LSQ_HandleT handle, LSQ_BaseTypeT element){
	TypeIterator *iterator = ITR(LSQ_GetPastRearElement(handle));

	if(iterator != LSQ_HandleInvalid){
		LSQ_InsertElementBeforeGiven( iterator, element);
		LSQ_DestroyIterator(iterator);
	}
}
예제 #9
0
/* Функция, удаляющая последний элемент контейнера */
void LSQ_DeleteRearElement(LSQ_HandleT handle){
	TypeIterator *iterator = ITR(LSQ_GetPastRearElement(handle));
	if(iterator != LSQ_HandleInvalid){
		iterator->node = iterator->node->prev;
		LSQ_DeleteGivenElement(iterator);
		LSQ_DestroyIterator(iterator);
	}
}
예제 #10
0
파일: lsq_tests.c 프로젝트: Taller/Rhonda
/* Test before first and past rear */
void test3(void)
{
    LSQ_IteratorT iter = LSQ_GetFrontElement(handle);
    assert( iter != NULL);
    assert(LSQ_IsIteratorBeforeFirst(iter) != 1);
    LSQ_RewindOneElement(iter);
    assert(LSQ_IsIteratorBeforeFirst(iter) == 1);
    printf("LSQ_IsIteratorBeforeFirst\t --- \t OK \n");


    LSQ_IteratorT iter2 = LSQ_GetPastRearElement(handle);
    assert( iter2 != NULL);
    assert(LSQ_IsIteratorPastRear(iter2) == 1);
    LSQ_RewindOneElement(iter2);
    assert(LSQ_IsIteratorPastRear(iter2) != 1);
    printf("LSQ_IsIteratorPastRear\t\t --- \t OK \n");

    LSQ_DestroyIterator(iter);
    LSQ_DestroyIterator(iter2);
}	
예제 #11
0
파일: lsq_tests.c 프로젝트: Taller/Rhonda
/* Test moving on list with ShiftPosition */
void test6(void)
{
    int i, j;
    LSQ_IteratorT iter;
    srand ( time(NULL) );

//    print_LSQ(handleAll);
    printf("Testing ShiftPosition forward");
    for(i = 0; i < MAX_TEST_ATTEMPTS; i++)
    {
	iter = LSQ_GetFrontElement(handleAll);
        assert( iter != NULL);

        j = rand() % LSQ_GetSize(handleAll);
        LSQ_ShiftPosition(iter, j);
        assert(*LSQ_DereferenceIterator(iter) == all[j]);
        assert( *LSQ_DereferenceIterator(iter) != MAX_ELEMENT_VALUE + 1);

        LSQ_DestroyIterator(iter);
    }
    printf("\t\t ---\t OK \n");

    printf("Testing ShiftPosition backward");
    for(i = 0; i < MAX_TEST_ATTEMPTS; i++)
    {
        iter = LSQ_GetPastRearElement(handleAll);
        LSQ_RewindOneElement(iter);
        assert( iter != NULL);

        j = rand() % LSQ_GetSize(handleAll);
        LSQ_ShiftPosition(iter, -j);
        assert( *LSQ_DereferenceIterator(iter) == all[LSQ_GetSize(handleAll) - 1 - j]);
        assert( *LSQ_DereferenceIterator(iter) != MAX_ELEMENT_VALUE + 1);

        LSQ_DestroyIterator(iter);
//        printf("i = %d \t j = %d\n", i, j);

    }
    printf("\t\t ---\t OK \n");

}
예제 #12
0
파일: lsq_tests.c 프로젝트: Taller/Rhonda
/* Test IsIteratorDereferencable, DeleteGivenElement pastReaer, beforeFirst */
void test10(void)
{
    int i, j;

    printf("Testing IsIteratorDereferencable");
    LSQ_IteratorT iterator = LSQ_GetPastRearElement(handleAll);
    assert(LSQ_IsIteratorDereferencable(iterator) == 0);
    assert(LSQ_IsIteratorPastRear(iterator) == 1);
    LSQ_DeleteGivenElement(iterator);
    LSQ_DestroyIterator(iterator);
    printf("\t\t ---\t OK \n");
    
    iterator = LSQ_GetFrontElement(handleAll);
    LSQ_RewindOneElement(iterator);
    printf("Testing IsIteratorBeforeFirst");
    assert(LSQ_IsIteratorDereferencable(iterator) == 0);
    assert(LSQ_IsIteratorBeforeFirst(iterator) == 1);
    LSQ_DeleteGivenElement(iterator);
    LSQ_DestroyIterator(iterator);
    printf("\t\t ---\t OK \n");
}
예제 #13
0
파일: lsq_tests.c 프로젝트: Taller/Rhonda
/* Create and destroy sequence immediately */
void test1(void)
{
    printf("Testing create and destroy sequence immediately");
    LSQ_HandleT handle1 = LSQ_CreateSequence();
    assert( handle1 != NULL);
    LSQ_IteratorT iter = LSQ_GetFrontElement(handle1);
    assert( iter == NULL);
    /* попытка удаления из пустой очереди */
    LSQ_DeleteFrontElement(handle1);
    LSQ_DeleteRearElement(handle1); 

    int i;
    for(i = 0; i < MAX_handleALL_LEN; i++)
    {
        LSQ_InsertRearElement(handle1, all[i]);
    } 

    LSQ_DestroyIterator(iter); 
    LSQ_DestroySequence(handle1);
    printf("\t ---\t OK \n");
}
예제 #14
0
파일: lsq_tests.c 프로젝트: Taller/Rhonda
/* Test moving on list with GetElementByIndex */
void test7(void)
{
    int i, j;
    srand ( time(NULL) );

//    print_LSQ(handleAll);
    printf("Testing GetElementByIndex");
    for(i = 0; i < MAX_TEST_ATTEMPTS; i++)
    {
        j = rand() % LSQ_GetSize(handleAll);
//        printf("\ni = %d \t j = %d \t size = %d", i , j, LSQ_GetSize(handleAll));
        LSQ_IteratorT iter = LSQ_GetElementByIndex(handleAll, j);
        assert( iter != NULL);
//        printf("\nFound = %d \t Expecting = %d \t", *LSQ_DereferenceIterator(iter), all[j]);
        assert( *LSQ_DereferenceIterator(iter) == all[j]);
        assert( *LSQ_DereferenceIterator(iter) != MAX_ELEMENT_VALUE + 1);

        LSQ_DestroyIterator(iter);
    }
    printf("\t\t ---\t OK \n");

}
예제 #15
0
void LSQ_InsertFrontElement(LSQ_HandleT handle, LSQ_BaseTypeT element)
{
    _iterator *iter = LSQ_GetFrontElement(handle);
    LSQ_InsertElementBeforeGiven(iter, element);
    LSQ_DestroyIterator(iter);
}
예제 #16
0
void LSQ_DeleteRearElement(LSQ_HandleT handle)
{
    _iterator *iter = LSQ_GetElementByIndex(handle, LSQ_GetSize(handle) - 1);
    LSQ_DeleteGivenElement(iter);
    LSQ_DestroyIterator(iter);
}
예제 #17
0
extern void LSQ_DeleteFrontElement(LSQ_HandleT handle)
{
	IteratorT *iterator = (IteratorT *)LSQ_GetFrontElement(handle);
	LSQ_DeleteElement(handle, iterator->node->key);
	LSQ_DestroyIterator(iterator);
}
extern void LSQ_InsertFrontElement(LSQ_HandleT handle, LSQ_BaseTypeT element)
{
    LSQ_IteratorT iterator = LSQ_GetElementByIndex(handle, 0);
    LSQ_InsertElementBeforeGiven(iterator, element);
    LSQ_DestroyIterator(iterator);
}
extern void LSQ_InsertRearElement(LSQ_HandleT handle, LSQ_BaseTypeT element)
{
    LSQ_IteratorT iterator = LSQ_GetPastRearElement(handle);
    LSQ_InsertElementBeforeGiven(iterator, element);
    LSQ_DestroyIterator(iterator);
}
extern void LSQ_DeleteFrontElement(LSQ_HandleT handle)
{
	LSQ_IteratorT iterator = LSQ_GetFrontElement(handle);
	LSQ_DeleteGivenElement(iterator);
	LSQ_DestroyIterator(iterator);
}
예제 #21
0
void LSQ_DeleteFrontElement(LSQ_HandleT handle)
{
    _iterator *iter = LSQ_GetFrontElement(handle);
    LSQ_DeleteGivenElement(iter);
    LSQ_DestroyIterator(iter);
}