-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_xorlinkedlist.c
79 lines (65 loc) · 1.88 KB
/
test_xorlinkedlist.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include "test_common.h"
#include "xorlinkedlist.h"
#include <stdio.h>
#include <stdbool.h>
#include <assert.h>
#include <stdlib.h>
void testCreateLinkedList ()
{
LinkedList* underTest = createNode(999);
assert(underTest);
assert(999 == underTest->value);
}
void testPrevNextInLinkedList ()
{
LinkedList* first = createNode(0);
LinkedList* second = createNode(0);
// initially we should get NULL for
// nextNode and prevNode, right?
assert(NULL == nextNode(first));
assert(NULL == prevNode(first));
// now we should have something like:
// NULL <-> first <-> second <-> NULL
insertNodeEnd(first, second);
//assert(NULL == prevNode(first));
//assert(NULL == nextNode(second));
//assert(second == nextNode(first));
//assert(first == prevNode(second));
}
void testInsertNodeEnd ()
{
LinkedList* first = createNode(0);
LinkedList* second = createNode(0);
// when we insert we expect the
// the following first <-> second
insertNodeEnd(first, second);
assert(nextNode(first) == second);
assert(prevNode(second) == first);
}
void testInsertNodeFront ()
{
LinkedList* first = createNode(0);
LinkedList* second = createNode(0);
// when we insert we expect the
// the following first <-> second
insertNodeFront(second, first);
assert(nextNode(first) == second);
assert(prevNode(second) == first);
}
void testHelperFunctionBitwiseXOR ()
{
assert(0b00 == (intptr_t) XOR((LinkedList*) 0b00, (LinkedList*) 0b00));
assert(0b00 == (intptr_t) XOR((LinkedList*) 0b11, (LinkedList*) 0b11));
assert(0b10 == (intptr_t) XOR((LinkedList*) 0b10, (LinkedList*) 0b00));
assert(0b01 == (intptr_t) XOR((LinkedList*) 0b11, (LinkedList*) 0b10));
}
int main ()
{
printf("Running tests now... \n");
runTestCase(testCreateLinkedList);
runTestCase(testPrevNextInLinkedList);
runTestCase(testInsertNodeEnd);
runTestCase(testInsertNodeFront);
runTestCase(testHelperFunctionBitwiseXOR);
return 0;
}