|
|
@ -1,12 +1,13 @@
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include "src/list.h"
|
|
|
|
#include "src/list.h"
|
|
|
|
#include "pthread.h"
|
|
|
|
|
|
|
|
#include "string.h"
|
|
|
|
#include "string.h"
|
|
|
|
#include "assert.h"
|
|
|
|
#include "assert.h"
|
|
|
|
|
|
|
|
|
|
|
|
void printSuccess(const char method[]) {
|
|
|
|
void printSuccess(const char method[]) {
|
|
|
|
|
|
|
|
unsigned long strLength = 18 + strlen(method);
|
|
|
|
|
|
|
|
char message[strLength];
|
|
|
|
|
|
|
|
|
|
|
|
printf("\n------------------------------");
|
|
|
|
printf("\n------------------------------");
|
|
|
|
char message[100] = "\n";
|
|
|
|
strcpy(message, "\n");
|
|
|
|
strcat(message, method);
|
|
|
|
strcat(message, method);
|
|
|
|
strcat(message, " --> TEST PASSED");
|
|
|
|
strcat(message, " --> TEST PASSED");
|
|
|
|
printf("%s", message);
|
|
|
|
printf("%s", message);
|
|
|
@ -57,7 +58,7 @@ void shouldReturnSortedList() {
|
|
|
|
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
// Assert
|
|
|
|
assert(returnCode == 0);
|
|
|
|
assert(returnCode == 0);
|
|
|
|
for (int i = 0; i < 11; i++) {
|
|
|
|
for (int i = 0; i < List_length(list); i++) {
|
|
|
|
assert(List_get(list, i) == i);
|
|
|
|
assert(List_get(list, i) == i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
List_destroy(&list);
|
|
|
|
List_destroy(&list);
|
|
|
@ -65,39 +66,82 @@ void shouldReturnSortedList() {
|
|
|
|
printSuccess(__func__);
|
|
|
|
printSuccess(__func__);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct args {
|
|
|
|
void shouldClearList() {
|
|
|
|
List *list;
|
|
|
|
// Arrange
|
|
|
|
int elemToInsert;
|
|
|
|
List *list = List_new();
|
|
|
|
} Arguments;
|
|
|
|
List_append(list, 0);
|
|
|
|
|
|
|
|
List_append(list, 1);
|
|
|
|
|
|
|
|
List_append(list, 2);
|
|
|
|
|
|
|
|
List_append(list, 3);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Act
|
|
|
|
|
|
|
|
List_clear(list);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
|
|
|
|
assert(List_length(list) == 0);
|
|
|
|
|
|
|
|
List_destroy(&list);
|
|
|
|
|
|
|
|
|
|
|
|
void *append(void *arg) {
|
|
|
|
printSuccess(__func__);
|
|
|
|
Arguments *args = (Arguments *) arg;
|
|
|
|
|
|
|
|
List *list = args->list;
|
|
|
|
|
|
|
|
List_append(list, args->elemToInsert);
|
|
|
|
|
|
|
|
pthread_exit(NULL);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
void shouldReturnListMaxLengthTwenty() {
|
|
|
|
// shouldReturnListLengthZero();
|
|
|
|
// Arrange
|
|
|
|
// shouldReturnListLengthTwo();
|
|
|
|
List *list = List_new();
|
|
|
|
// shouldReturnSortedList();
|
|
|
|
List_append(list, 0);
|
|
|
|
|
|
|
|
List_append(list, 1);
|
|
|
|
|
|
|
|
List_append(list, 2);
|
|
|
|
|
|
|
|
List_append(list, 3);
|
|
|
|
|
|
|
|
List_append(list, 4);
|
|
|
|
|
|
|
|
List_append(list, 5);
|
|
|
|
|
|
|
|
List_append(list, 6);
|
|
|
|
|
|
|
|
List_append(list, 7);
|
|
|
|
|
|
|
|
List_append(list, 8);
|
|
|
|
|
|
|
|
List_append(list, 9);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Mid-Assert
|
|
|
|
|
|
|
|
assert(List_maxLength(list) == 10);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Act
|
|
|
|
|
|
|
|
List_append(list, 10);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
|
|
|
|
assert(List_maxLength(list) == 20);
|
|
|
|
|
|
|
|
List_destroy(&list);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
printSuccess(__func__);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void shouldCopyPopulatedList() {
|
|
|
|
|
|
|
|
// Arrange
|
|
|
|
List *list = List_new();
|
|
|
|
List *list = List_new();
|
|
|
|
|
|
|
|
List_append(list, 0);
|
|
|
|
|
|
|
|
List_append(list, 1);
|
|
|
|
|
|
|
|
List_append(list, 2);
|
|
|
|
|
|
|
|
List_append(list, 3);
|
|
|
|
|
|
|
|
List_append(list, 4);
|
|
|
|
|
|
|
|
|
|
|
|
pthread_t pthreads[2];
|
|
|
|
// Act
|
|
|
|
for (int i = 0; i < 2; i++) {
|
|
|
|
List *copiedList = List_copy(list);
|
|
|
|
printf("\nElement To Insert -> %i", i);
|
|
|
|
|
|
|
|
Arguments args = {list, i};
|
|
|
|
|
|
|
|
pthread_create(&pthreads[i], NULL, append, &args);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < 2; i++) {
|
|
|
|
// Assert
|
|
|
|
pthread_join(pthreads[i], NULL);
|
|
|
|
assert(List_length(copiedList) == List_length(list));
|
|
|
|
|
|
|
|
assert(List_maxLength(copiedList) == List_maxLength(list));
|
|
|
|
|
|
|
|
for (int i = 0; i < List_length(copiedList); i++) {
|
|
|
|
|
|
|
|
assert(List_get(list, i) == List_get(copiedList, i));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
List_destroy(&list);
|
|
|
|
|
|
|
|
List_destroy(&copiedList);
|
|
|
|
|
|
|
|
|
|
|
|
printf("\n\nList: \n");
|
|
|
|
printSuccess(__func__);
|
|
|
|
List_print(list);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
|
|
|
|
shouldReturnListLengthZero();
|
|
|
|
|
|
|
|
shouldReturnListLengthTwo();
|
|
|
|
|
|
|
|
shouldReturnSortedList();
|
|
|
|
|
|
|
|
shouldClearList();
|
|
|
|
|
|
|
|
shouldReturnListMaxLengthTwenty();
|
|
|
|
|
|
|
|
shouldCopyPopulatedList();
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|