-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
237 lines (214 loc) · 9.61 KB
/
main.c
File metadata and controls
237 lines (214 loc) · 9.61 KB
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
# include <stdio.h>
# include <strings.h>
# include <time.h>
# include <stdlib.h>
# include "library.h"
void find_test(){
printf("Printing empty list:\n\n");
print_list(0);
printf("\n");
struct song_node * playlist = insert_front(0 ,"radiohead", "street spirit (fade out)");
playlist = insert_front(playlist, "radiohead","paranoid android");
playlist = insert_front(playlist, "pink floyd","time");
playlist = insert_front(playlist, "pearl jam","yellow ledbetter");
playlist = insert_front(playlist, "pearl jam","even flow");
playlist = insert_front(playlist, "pearl jam","alive");
playlist = insert_front(playlist, "ac/dc", "thunderstruck");
printf("Testing find_node:\n\n");
print_list(playlist);
printf("\n");
printf("Looking for [pearl jam: even flow]\n\t");
print_song_node(find_node(playlist, "pearl jam", "even flow"));
printf("Looking for [pearl jam: daughter]\n\t");
print_song_node(find_node(playlist, "pearl jam", "daughter"));
printf("\n");
printf("=============================================\n");
printf("Testing find_artist:\n\n");
printf("Looking for [pink floyd]\n\t");
printf("%s\n", (find_artist(playlist,"pink floyd"))->name);
printf("Looking for [pearl jam]\n\t");
printf("%s\n", (find_artist(playlist, "pearl jam"))->name);
playlist = free_list(playlist);
}
void song_cmp_test(){
printf("Testing song_cmp:\n\t");
struct song_node * playlist = insert_front(0, "pearl jam", "even flow");
playlist = insert_front(playlist, "pearl jam", "even flow");
playlist = insert_front(playlist, "pearl jam", "alive");
playlist = insert_front(playlist, "pink floyd", "time");
printf("Comparing songs:\n\t");
print_song_node(playlist->next->next->next);
printf("\t");
print_song_node(playlist->next->next);
printf("\t\t%d\n", songcmp(playlist->next->next, playlist->next->next->next));
printf("\tComparing song:\n\t");
print_song_node(playlist->next->next);
printf("\t");
print_song_node(playlist->next);
printf("\t\t%d\n", songcmp(playlist->next->next, playlist->next));
printf("\tComparing song:\n\t");
print_song_node(playlist->next);
printf("\t");
print_song_node(playlist->next->next);
printf("\t\t%d\n", songcmp(playlist->next, playlist->next->next));
printf("\tComparing songs:\n\t");
print_song_node(playlist->next->next);
printf("\t");
print_song_node(playlist);
printf("\t\t%d\n", songcmp(playlist->next->next, playlist));
playlist = free_list(playlist);
print_list(playlist);
}
void random_node_test(){
struct song_node * playlist = insert_front(0 ,"radiohead", "street spirit (fade out)");
playlist = insert_front(playlist, "radiohead","paranoid android");
playlist = insert_front(playlist, "pink floyd","time");
playlist = insert_front(playlist, "pearl jam","yellow ledbetter");
playlist = insert_front(playlist, "pearl jam","even flow");
playlist = insert_front(playlist, "pearl jam","alive");
playlist = insert_front(playlist, "ac/dc", "thunderstruck");
printf("Testing random_node:\n\n");
print_list(playlist);
printf("\n");
print_song_node(random_node(playlist));
print_song_node(random_node(playlist));
print_song_node(random_node(playlist));
print_song_node(random_node(playlist));
playlist = free_list(playlist);
}
void remove_node_test(){
struct song_node * playlist = insert_front(0 ,"radiohead", "street spirit (fade out)");
playlist = insert_front(playlist, "radiohead","paranoid android");
playlist = insert_front(playlist, "pink floyd","time");
playlist = insert_front(playlist, "pearl jam","yellow ledbetter");
playlist = insert_front(playlist, "pearl jam","even flow");
playlist = insert_front(playlist, "pearl jam","alive");
playlist = insert_front(playlist, "ac/dc", "thunderstruck");
printf("Testing remove_node:\n\n");
print_list(playlist);
printf("\n");
printf("Removing [ac/dc: thunderstruck]\n\t");
playlist = remove_node(playlist, "AC/Dc", "thunderstruck");
print_list(playlist);
printf("Removing [radioHeAd: street sPirit (fade out)]\n\t");
playlist = (remove_node(playlist, "radioHeAd", "street sPirit (fade out)"));
print_list(playlist);
printf("Removing [pearl jam: yeLLOW ledbetter]\n\t");
playlist = (remove_node(playlist, "pearl JaM", "yeLLOW ledbetter"));
print_list(playlist);
printf("Removing [pearl jam: yeLLOW ledbetter]\n\t");
playlist = (remove_node(playlist, "pearl jAM", "yeLLOW ledbetter"));
print_list(playlist);
printf("\n");
playlist = free_list(playlist);
print_list(playlist);
}
void ordered_insert_test(){
struct song_node * playlist = insert_front(0, "a", "r");
printf("Testing ordered_insert\n\n");
print_list(playlist);
playlist = ordered_insert(playlist, "a", "t");
printf("\nInserting {a, t}\n\t");
print_list(playlist);
playlist = ordered_insert(playlist, "/a", "s");
printf("Inserting {/a, s}\n\t");
print_list(playlist);
playlist = ordered_insert(playlist, "a", "t");
printf("Inserting {a, t}\n\t");
print_list(playlist);
playlist = ordered_insert(playlist, "b", "a");
printf("Inserting {b, a}\n\t");
print_list(playlist);
playlist = ordered_insert(playlist, "~b", "b");
printf("Inserting {~b, b}\n\t");
print_list(playlist);
playlist = ordered_insert(playlist, "a", "t");
printf("Inserting {a, t}\n\t");
print_list(playlist);
playlist = ordered_insert(playlist, "a", "a");
printf("Inserting {a, a}\n\t");
print_list(playlist);
}
void lib_tests(){
struct song_node * a1 = insert_front(0, "ac/dc", "thunderstruck");
struct song_node * a2 = insert_front(0, "pearl jam", "alive");
struct song_node * a3 = insert_front(0, "pearl jam", "even flow");
struct song_node * a4 = insert_front(0, "pearl jam", "yellow ledbetter");
struct song_node * a5 = insert_front(0, "pink floyd", "time");
struct song_node * a6 = insert_front(0, "presidents of the united states of america", "peaches");
struct song_node * a7 = insert_front(0, "radiohead", "street spirit (fade out)");
struct song_node * a8 = insert_front(0, "radiohead", "paranoid android");
struct song_node ** lib = make_lib();
printf("=============================================\n");
printf("MUSIC LIBRARY TESTS\n");
printf("=============================================\n");
printf("Testing print_by_letter (p) on empty list: \n");
print_by_letter(lib, 'p');
printf("=============================================\n");
printf("Testing print_library on empty library\n");
print_lib(lib);
printf("\n=============================================\n");
printf("Testing print_library after add_list\n");
lib = add_list(lib, a1);
lib = add_list(lib, a2);
lib = add_list(lib, a3);
lib = add_list(lib, a4);
lib = add_list(lib, a5);
lib = add_list(lib, a6);
lib = add_list(lib, a7);
lib = add_list(lib, a8);
print_lib(lib);
printf("=============================================\n");
printf("Testing print_by_letter (p): \n");
print_by_letter(lib, 'p');
printf("=============================================\n");
printf("Testing search_song: \nlooking for [pearl jam, alive]\n\t");
print_song_node(search_song(lib, "pearl jam", "alive"));
printf("Testing search_song: \nlooking for [leonard cohen, hallelujah]\n\t");
print_song_node(search_song(lib, "leonard cohen", "hallelujah"));
printf("=============================================\n");
printf("Testing search_artist: \nlooking for [pearl jam]\n\t");
print_song_node(search_artist(lib, "pearl jam"));
printf("Testing search_artist: \nlooking for [pink floyd]\n\t");
print_song_node(search_artist(lib, "pink floyd"));
printf("Testing search_artist: \nlooking for [bob dylan]\n\t");
print_song_node(search_artist(lib, "bob dylan"));
printf("=============================================\n");
printf("Testing delete_song: \ndeleting [pearl jam: alive]\n");
lib = delete_song(lib, "pearl jam", "alive");
print_lib(lib);
printf("=============================================\n");
printf("Testing print_by_artist: \nPrinting [pearl jam]\n");
print_by_artist(lib, "pearl jam");
printf("=============================================\n");
printf("Testing print_by_letter: \nPrinting r\n");
print_by_letter(lib, 'r');
printf("=============================================\n");
printf("Testing print_shuffle: \n");
print_shuffle(lib);
printf("=============================================\n");
printf("Testing clear_library: \n");
lib = clear_lib(lib);
printf("Library after clear: \n");
print_lib(lib);
}
void list_tests() {
printf("=============================================\nLINKED LIST TESTS\n=============================================\n");
printf("=============================================\n");
find_test();
printf("=============================================\n");
remove_node_test();
srand(time(NULL));
printf("=============================================\n");
random_node_test();
printf("=============================================\n");
song_cmp_test();
printf("=============================================\n");
ordered_insert_test();
}
int main(){
srand(time(NULL));
list_tests();
lib_tests();
return 0;
}