char *test_bubble_sort() { list_t *words = create_words(); // should work on a list that needs sorting int rc = list_bubble_sort(words, (list_compare)strcmp); mu_assert(rc == 0, "Bubble sort failed."); mu_assert(is_sorted(words), "Words are not sorted after bubble sort."); // should work on a already sorted list rc = list_bubble_sort(words, (list_compare)strcmp); mu_assert(rc == 0, "Bubble sort of already sorted failed."); mu_assert(is_sorted(words), "Words are not sorted if already bubble sorted."); list_destroy(&words); // should work on an empty list. words = create_words(); rc = list_bubble_sort(words, (list_compare)strcmp); mu_assert(rc == 0, "Bubble sort of on empty list."); mu_assert(is_sorted(words), "Words should be sorted if empty."); list_destroy(&words); return NULL; }
char *test_add_and_sort() { DArray *words = create_words(); mu_assert(!is_sorted(words), "Words should start not sorted"); int rc = DArray_add_sort(words, "next_element", qusort, (DArray_compare)testcmp); mu_assert(rc == 0, "sort failed."); mu_assert(is_sorted(words), "didn't sort it"); DArray_destroy(words); return NULL; }
char *run_sort_test_choose_sort_type(DArray_sort_type sort_type) { DArray *words = create_words(); mu_assert(!is_sorted(words), "Words should start not sorted"); int rc = DArray_sort(words, sort_type, (DArray_compare)testcmp); mu_assert(rc == 0, "sort failed."); mu_assert(is_sorted(words), "didn't sort it"); DArray_destroy(words); return NULL; }
char *run_sort_test(int (*func)(DArray *, DArray_compare), const char *name) { DArray *words = create_words(); mu_assert(!is_sorted(words), "Words should not start out sorted"); debug("---- Testing %s sorting algorithm", name); int rc = func(words, (DArray_compare)testcmp); mu_assert(rc == 0, "sort failed"); mu_assert(is_sorted(words), "Words should be sorted"); DArray_destroy(words); return NULL; }
char *run_sort_test(int (*func)(DArray *, DArray_compare), const char *name) { DArray *words = create_words(); mu_assert(!is_sorted(words), "Words should start not sorted."); debug("--- Testing %s sorting algorithm...", name); int rc = func(words, (DArray_compare)testcmp); mu_assert(rc == 0, "sort anounced failure"); mu_assert(is_sorted(words), "didn't sort it"); DArray_destroy(words); return NULL; }
char *test_find() { DArray *words = create_words(); DArray_qsort(words, (DArray_compare)testcmp); int res = DArray_find(words, "werwar", (DArray_compare)strcmp); mu_assert(res == 3, "Element is not there, but should be."); res = DArray_find(words, "wasderwar", (DArray_compare)strcmp); mu_assert(res == -1, "Element is there, but shouldn't be."); DArray_destroy(words); return NULL; }
/** * irc_context_run_command: * @self: Context to run on * @command: Command to run */ void irc_context_run_command (IrcContext *self, const char *command) { //g_return_if_fail (command && *command); g_return_if_fail (IRC_IS_CONTEXT(self)); gboolean handled; g_auto(GStrv) words; GStrv words_eol; // TODO: Parse commands similar to hexchat handling quotes create_words (command, &words, &words_eol); g_signal_emit (self, signals[SIGNAL_COMMAND], g_quark_from_string (words[0]), words, words_eol, &handled); }
char *test_sort_add() { DArray *words = create_words(); DArray_qsort(words, (DArray_compare)testcmp); char *words2[] = {"twiggy", "pwnod", "asd13234", "kukareku", "9_("}; int i = 0; for(i = 0; i < 5; i++) { DArray_sort_add(words, words2[i], (DArray_compare)testcmp); mu_assert(is_sorted(words), "Words should be sorted."); } DArray_destroy(words); return NULL; }
char *test_merge_sort() { List *words = create_words(); // should work on a list that needs sorting List *res = List_merge_sort(words, (List_compare)strcmp); mu_assert(is_sorted(res), "Words are not sorted after merge sort"); List *res2 = List_merge_sort(res, (List_compare)strcmp); mu_assert(is_sorted(res2), "should still be sort after merge sort"); List_destroy(res2); List_destroy(res); List_destroy(words); return NULL; }
char *test_merge_sort() { list_t *words = create_words(); // should work on a list that needs sorting list_t *res = list_merge_sort(words, (list_compare)strcmp); mu_assert(is_sorted(res), "Words are not sorted after merge sort."); list_t *res2 = list_merge_sort(res, (list_compare)strcmp); mu_assert(is_sorted(res2), "Should still be sorted after merge sort."); list_destroy(&res2); list_destroy(&res); list_destroy(&words); return NULL; }
char *test_daaray_find() { DArray *words = create_words(); mu_assert(!is_sorted(words), "Words should start not sorted"); // sort it first int rc = DArray_add_sort(words, "next_element", qusort, (DArray_compare)testcmp); mu_assert(rc == 0, "sort failed."); mu_assert(is_sorted(words), "didn't sort it"); int result = DArray_find(words, "asdfasfd", (DArray_compare)testcmp); // 0 is with numbers, 1 the similar but shorted word and 2 is correct mu_assert(result == 2, "Error with finding: should have found, but returned wrong index"); result = DArray_find(words, "wtf", (DArray_compare)testcmp); mu_assert(result == -1, "Error with finding: should not have found, but returned index"); return NULL; }
char *test_bubble_sort() { List *words = create_words(); // should work on a list that needs sorting int rc = List_bubble_sort(words, (List_compare)strcmp); mu_assert(rc == 0, "Bubble sort failed"); mu_assert(is_sorted(words), "Words are not sorted after bubble sort"); // should work on a list that already sorted rc = List_bubble_sort(words, (List_compare)strcmp); mu_assert(rc == 0, "Bubble sort of already sorted failed"); mu_assert(is_sorted(words), "Words should be sort if already bubble sorted"); // should work on empty list List_destroy(words); words = List_create(); rc = List_bubble_sort(words, (List_compare)strcmp); mu_assert(rc == 0, "Bubble sort failed on empty list"); mu_assert(is_sorted(words), "Words should be sorted if empty"); List_destroy(words); return NULL; }