Skip to content

Commit

Permalink
quicksort tested
Browse files Browse the repository at this point in the history
  • Loading branch information
brunoczim committed Nov 6, 2020
1 parent e71ac19 commit 200b458
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 9 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ TEST_TAGS_TABLE_OBJS = $(OBJ_DIR)/error.o \
$(OBJ_DIR)/csv.o \
$(OBJ_DIR)/csv/tag.o \
$(OBJ_DIR)/prime.o \
$(OBJ_DIR)/tags/movies.o \
$(OBJ_DIR)/tags.o \
$(OBJ_DIR)/test/tags_table.o

Expand Down
84 changes: 75 additions & 9 deletions src/test/tags_table.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ int main(int argc, char const *argv[])
assert(table.length == 0);
assert(table.capacity == 5);

insert(&table, "good", 123, &error);
insert(&table, "good", 90, &error);
assert(error.code == error_none);
assert(table.length == 1);
assert(table.capacity == 5);
Expand All @@ -59,12 +59,12 @@ int main(int argc, char const *argv[])
assert(tag != NULL);
assert(strcmp(tag->name, "good") == 0);

insert(&table, "bad", 456, &error);
insert(&table, "bad", 92, &error);
assert(error.code == error_none);
assert(table.length == 2);
assert(table.capacity == 5);

insert(&table, "average", 789, &error);
insert(&table, "average", 88, &error);
assert(error.code == error_none);
assert(table.length == 3);
assert(table.capacity == 11);
Expand All @@ -77,12 +77,12 @@ int main(int argc, char const *argv[])
assert(tag != NULL);
assert(strcmp(tag->name, "bad") == 0);

insert(&table, "good", 456, &error);
insert(&table, "good", 92, &error);
assert(error.code == error_none);
assert(table.length == 3);
assert(table.capacity == 11);

insert(&table, "good", 789, &error);
insert(&table, "good", 88, &error);
assert(error.code == error_none);
assert(table.length == 3);
assert(table.capacity == 11);
Expand All @@ -91,15 +91,81 @@ int main(int argc, char const *argv[])
assert(tag != NULL);
assert(strcmp(tag->name, "bad") == 0);
assert(tag->movies.length == 1);
assert(tag->movies.entries[0] == 456);
assert(tag->movies.entries[0] == 92);

tag = tags_search(&table, "good");
assert(tag != NULL);
assert(strcmp(tag->name, "good") == 0);
assert(tag->movies.length == 3);
assert(tag->movies.entries[0] == 123);
assert(tag->movies.entries[1] == 456);
assert(tag->movies.entries[2] == 789);
assert(tag->movies.entries[0] == 90);
assert(tag->movies.entries[1] == 92);
assert(tag->movies.entries[2] == 88);

insert(&table, "good", 96, &error);
assert(error.code == error_none);
insert(&table, "good", 89, &error);
assert(error.code == error_none);
insert(&table, "good", 83, &error);
assert(error.code == error_none);
insert(&table, "good", 158, &error);
assert(error.code == error_none);
insert(&table, "good", 87, &error);
assert(error.code == error_none);
insert(&table, "good", 0, &error);
assert(error.code == error_none);
insert(&table, "good", 957, &error);
assert(error.code == error_none);
assert(error.code == error_none);
insert(&table, "good", 2, &error);
assert(error.code == error_none);
insert(&table, "good", 3, &error);
assert(error.code == error_none);
insert(&table, "good", 4, &error);
assert(error.code == error_none);
insert(&table, "good", 5, &error);
assert(error.code == error_none);
insert(&table, "good", 6, &error);
assert(error.code == error_none);
insert(&table, "good", 7, &error);
assert(error.code == error_none);
insert(&table, "good", 8, &error);
assert(error.code == error_none);
insert(&table, "good", 9, &error);
assert(error.code == error_none);
insert(&table, "good", 1, &error);
assert(error.code == error_none);

tag = tags_search(&table, "good");
assert(tag != NULL);
assert(strcmp(tag->name, "good") == 0);
assert(tag->movies.length == 19);

tags_sort_movies(&table, &error);
assert(error.code == error_none);

tag = tags_search(&table, "good");
assert(tag != NULL);
assert(strcmp(tag->name, "good") == 0);
assert(tag->movies.length == 19);
assert(tag->movies.entries[0] == 0);
assert(tag->movies.entries[1] == 1);
assert(tag->movies.entries[2] == 2);
assert(tag->movies.entries[3] == 3);
assert(tag->movies.entries[4] == 4);
assert(tag->movies.entries[5] == 5);
assert(tag->movies.entries[6] == 6);
assert(tag->movies.entries[7] == 7);
assert(tag->movies.entries[8] == 8);
assert(tag->movies.entries[9] == 9);
assert(tag->movies.entries[10] == 83);
assert(tag->movies.entries[11] == 87);
assert(tag->movies.entries[12] == 88);
assert(tag->movies.entries[13] == 89);
assert(tag->movies.entries[14] == 90);
assert(tag->movies.entries[15] == 92);
assert(tag->movies.entries[16] == 96);
assert(tag->movies.entries[17] == 158);
assert(tag->movies.entries[18] == 957);

tags_destroy(&table);
error_destroy(&error);
Expand Down

0 comments on commit 200b458

Please sign in to comment.