Created
November 26, 2016 17:50
-
-
Save xfbs/fcd4185680667d0bdf86d246ad93771e to your computer and use it in GitHub Desktop.
tests for spp linked list
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include "list.h" | |
| #include <assert.h> | |
| #include <stdlib.h> | |
| char *mystring = "my string"; | |
| char *otherstring = "other string"; | |
| int main(int argc, char *argv[]) | |
| { | |
| LinkedList *lista, *listb; | |
| lista = LinkedList_create(); | |
| listb = LinkedList_create(); | |
| assert(lista != listb); | |
| assert(lista != NULL); | |
| assert(listb != NULL); | |
| // getFirst, getLast | |
| assert(LinkedList_getFirst(lista) == NULL); | |
| assert(LinkedList_getLast(listb) == NULL); | |
| // append | |
| LinkedList_append(lista, mystring); | |
| assert(LinkedList_getFirst(lista) != NULL); | |
| assert(LinkedList_getLast(lista) != NULL); | |
| // getData | |
| assert(LinkedList_getData(LinkedList_getFirst(lista)) == mystring); | |
| assert(LinkedList_getData(LinkedList_getLast(lista)) == mystring); | |
| // getNext, getPrevious | |
| assert(LinkedList_getNext(LinkedList_getFirst(lista)) == NULL); | |
| assert(LinkedList_getPrevious(LinkedList_getFirst(lista)) == NULL); | |
| LinkedList_append(lista, otherstring); | |
| assert(LinkedList_getNext(LinkedList_getFirst(lista)) != NULL); | |
| assert(LinkedList_getPrevious(LinkedList_getLast(lista)) != NULL); | |
| assert(LinkedList_getData(LinkedList_getNext(LinkedList_getFirst(lista))) == otherstring); | |
| assert(LinkedList_getData(LinkedList_getPrevious(LinkedList_getLast(lista))) == mystring); | |
| // delete | |
| LinkedList_append(listb, malloc(5)); | |
| LinkedList_append(listb, malloc(10)); | |
| LinkedList_delete(listb); | |
| // getSize | |
| listb = LinkedList_create(); | |
| assert(LinkedList_getSize(listb) == 0); | |
| LinkedList_append(listb, malloc(4)); | |
| assert(LinkedList_getSize(listb) == 1); | |
| LinkedList_append(listb, malloc(4)); | |
| assert(LinkedList_getSize(listb) == 2); | |
| LinkedList_append(listb, malloc(4)); | |
| assert(LinkedList_getSize(listb) == 3); | |
| // getDataAt | |
| assert(LinkedList_getDataAt(listb, 0) != NULL); | |
| assert(LinkedList_getDataAt(listb, 1) != NULL); | |
| assert(LinkedList_getDataAt(listb, 2) != NULL); | |
| assert(LinkedList_getDataAt(listb, 3) == NULL); | |
| assert(LinkedList_getDataAt(lista, 0) == mystring); | |
| assert(LinkedList_getDataAt(lista, 1) == otherstring); | |
| assert(LinkedList_getDataAt(lista, 2) == NULL); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment