static bool testListInsertBeforeCurrent() {
	ASSERT_TRUE(SP_LIST_NULL_ARGUMENT == spListInsertBeforeCurrent(NULL, NULL));
	SPListElement e1 = spListElementCreate(1, 1.0);
	SPListElement e2 = spListElementCreate(2, 2.0);
	SPListElement e3 = spListElementCreate(3, 3.0);
	SPListElement e4 = spListElementCreate(4, 4.0);
	SPList list2 = quickList(3, e2, e3, e4);
	ASSERT_TRUE(SP_LIST_NULL_ARGUMENT == spListInsertBeforeCurrent(list2,NULL));
	ASSERT_TRUE(
			SP_LIST_INVALID_CURRENT == spListInsertBeforeCurrent(list2, e1));
	ASSERT_TRUE(3 == spListGetSize(list2));
	spListGetFirst(list2);
	spListGetNext(list2);
	ASSERT_TRUE(SP_LIST_SUCCESS == spListInsertBeforeCurrent(list2, e1));
	ASSERT_TRUE(4 == spListGetSize(list2));
	ASSERT_TRUE(spListElementCompare(e2, spListGetFirst(list2))==0);
	ASSERT_TRUE(spListElementCompare(e1, spListGetNext(list2))==0);
	ASSERT_TRUE(spListElementCompare(e3, spListGetNext(list2))==0);
	ASSERT_TRUE(spListElementCompare(e4, spListGetNext(list2))==0);
	ASSERT_TRUE(spListGetNext(list2) == NULL);
	spListDestroy(list2);
	spListElementDestroy(e1);
	spListElementDestroy(e2);
	spListElementDestroy(e3);
	spListElementDestroy(e4);
	return true;
}
static bool testListCopy() {
	ASSERT_TRUE(spListCopy(NULL) == NULL);
	SPList list = spListCreate();
	SPList copy = spListCopy(list);
	ASSERT_TRUE(copy != NULL);
	ASSERT_TRUE(0 == spListGetSize(copy));
	SPListElement e1 = spListElementCreate(1, 1.0);
	SPListElement e2 = spListElementCreate(2, 2.0);
	SPListElement e3 = spListElementCreate(3, 3.0);
	SPListElement e4 = spListElementCreate(4, 4.0);
	spListInsertFirst(list, e1);
	ASSERT_TRUE(0 == spListGetSize(copy));
	SPList list2 = quickList(4, e1, e2, e3, e4);
	SPList copy2 = spListCopy(list2);
	ASSERT_TRUE(4 == spListGetSize(copy2));
	ASSERT_TRUE(spListElementCompare(e1, spListGetFirst(copy2)) == 0);
	ASSERT_TRUE(spListElementCompare(e2, spListGetNext(copy2)) == 0);
	ASSERT_TRUE(spListElementCompare(e3, spListGetNext(copy2)) == 0);
	ASSERT_TRUE(spListElementCompare(e4, spListGetNext(copy2)) == 0);
	ASSERT_TRUE(spListGetNext(copy2) == NULL);
	spListDestroy(list);
	spListDestroy(list2);
	spListDestroy(copy);
	spListDestroy(copy2);
	spListElementDestroy(e1);
	spListElementDestroy(e2);
	spListElementDestroy(e3);
	spListElementDestroy(e4);
	return true;
}
Example #3
0
bool spBPQueueIsEmpty(SPBPQueue source){
	assert(source);
	if (spListGetSize(source->list)<1){
		return true;
	}
	return false;
}
Example #4
0
SPListElement spListGetCurrent(SPList list) {
	if (list == NULL || spListGetSize(list) == 0 || list->current == NULL) {
		return NULL;
	} else {
		return list->current->data;
	}
}
Example #5
0
bool spBPQueueIsFull(SPBPQueue source){
	assert(source);
	if (spListGetSize(source->list) == spBPQueueGetMaxSize(source)){
		return true;
	}
	return false;
}
static bool testListGetSize() {
	SPList list = quickList(0);
	ASSERT_TRUE(0 == spListGetSize(list));
	SPListElement e1 = spListElementCreate(1, 1.0);
	spListInsertFirst(list, e1);
	ASSERT_TRUE(1 == spListGetSize(list));
	spListElementSetIndex(e1, 2);
	spListElementSetValue(e1, 2.0);
	spListInsertFirst(list, e1);
	ASSERT_TRUE(2 == spListGetSize(list));
	spListGetFirst(list);
	spListRemoveCurrent(list);
	ASSERT_TRUE(1 == spListGetSize(list));
	spListDestroy(list);
	spListElementDestroy(e1);
	return true;
}
Example #7
0
SPListElement spListGetFirst(SPList list) {
	if (list == NULL || spListGetSize(list) == 0) {
		return NULL;
	} else {
		list->current = list->head->next;
		return list->current->data;
	}
}
Example #8
0
SPListElement spListGetLast(SPList list){
	if (list == NULL || spListGetSize(list) == 0) {
		return NULL;
	} else {
		list->current = list->tail->previous;
		return list->current->data;
	}
}
static bool testListClear() {
	SPListElement e1 = spListElementCreate(1, 1.0);
	SPListElement e2 = spListElementCreate(2, 2.0);
	SPListElement e3 = spListElementCreate(3, 3.0);
	SPListElement e4 = spListElementCreate(4, 4.0);
	SPList list2 = quickList(4, e1, e2, e3, e4);
	ASSERT_TRUE(spListClear(list2) == SP_LIST_SUCCESS);
	ASSERT_TRUE(0 == spListGetSize(list2));
	SPList list = spListCreate();
	spListClear(list);
	ASSERT_TRUE(0 == spListGetSize(list));
	spListDestroy(list);
	spListDestroy(list2);
	spListElementDestroy(e1);
	spListElementDestroy(e2);
	spListElementDestroy(e3);
	spListElementDestroy(e4);
	return true;
}
Example #10
0
SP_BPQUEUE_MSG spBPQueueEnqueue(SPBPQueue source, SPListElement element){

	// variables declaration//
	int i;
	SPList source_list = source->list;
	SPListElement elem_to_comp;
	int list_size = spListGetSize(source_list);

	// check for bad arguments or allocation problems//
	if (!source || !element || !source_list){
		return SP_BPQUEUE_INVALID_ARGUMENT;
	}


	// insertion process//
	if (spBPQueueIsEmpty(source)){
		spListInsertFirst(source_list, element);
		return SP_BPQUEUE_SUCCESS;
	}
	else{
		elem_to_comp = spListGetFirst(source_list);

		/*starts from the bottom and loop for next source list element up until
		you find the one which is bigger than the inserted one and insert the element
		before that one. you will stop after you ran out of elements to look for */
        
        for(i=0; i<list_size; i++){
            if (spListElementGetValue(element) <= spListElementGetValue(elem_to_comp)){// element is smaller than next elem, insert before current
                if (spBPQueueIsFull(source)){
                    if (spListInsertBeforeCurrent(source_list, element) == SP_LIST_OUT_OF_MEMORY){
                        return SP_BPQUEUE_OUT_OF_MEMORY;
                    }
                    spListGetLast(source_list);
                    spListRemoveCurrent(source_list);
                    return SP_BPQUEUE_SUCCESS;
                }
                else{
                    if (spListInsertBeforeCurrent(source_list, element) == SP_LIST_OUT_OF_MEMORY){
                        return SP_BPQUEUE_OUT_OF_MEMORY;
                    }
                    return SP_BPQUEUE_SUCCESS;
                }
            }else{
                elem_to_comp = spListGetNext(source_list);
            }
        }
    }
    if (!spBPQueueIsFull(source)){//queue isn't full but this item is the biggest
        if (spListInsertLast(source_list, element)== SP_LIST_OUT_OF_MEMORY){
            return SP_BPQUEUE_OUT_OF_MEMORY;
        }
        return SP_BPQUEUE_SUCCESS;
    }
    return SP_BPQUEUE_SUCCESS; // the element is larger than all others
}
Example #11
0
SPListElement spListGetPrevious(SPList list) {
	if (list == NULL || spListGetSize(list) == 0 || list->current == NULL) {
		return NULL;
	} else {
		if (list->current->previous == list->head) {
			list->current = NULL;
			return NULL;
		} else {
			list->current = list->current->previous;
			return list->current->data;
		}
	}
}
Example #12
0
SPListElement spListGetNext(SPList list) {
	if (list == NULL || spListGetSize(list) == 0 || list->current == NULL) {
		return NULL;
	} else {
		if (list->current->next == list->tail) {
			list->current = NULL;
			return NULL;
		} else {
			list->current = list->current->next;
			return list->current->data;
		}
	}
}
Example #13
0
int spBPQueueSize(SPBPQueue source) {
	return source == NULL ? -1 : spListGetSize(source->innerList);
}
int spBPQueueSize(SPBPQueue source) {
	spMinimalVerifyArguments(source != NULL && source->queue != NULL,
			DEFAULT_INVALID_NUMBER);
	return spListGetSize(source->queue);
}
Example #15
0
int spBPQueueSize(SPBPQueue source){
	assert(source);
	return spListGetSize(source->list);
}