void test_starcode_6 (void) // Test 'pad_useq()' and 'unpad_useq()' { gstack_t * useqS = new_gstack(); test_assert_critical(useqS != NULL); useq_t *u1 = new_useq(1, "L@[ohztp{2@V(u(x7fLt&x80", NULL); useq_t *u2 = new_useq(2, "$Ee6xkB+.Q;Nk)|w[KQ;", NULL); test_assert_critical(u1 != NULL); test_assert_critical(u2 != NULL); push(u1, &useqS); push(u2, &useqS); test_assert(useqS->nitems == 2); int med; pad_useq(useqS, &med); test_assert(strcmp(u2->seq, " $Ee6xkB+.Q;Nk)|w[KQ;") == 0); test_assert(med == 20); useq_t *u3 = new_useq(23, "0sdfd:'!'@{1$Ee6xkB+.Q;[Nk)|w[KQ;", NULL); test_assert_critical(u3 != NULL); push(u3, &useqS); test_assert(useqS->nitems == 3); pad_useq(useqS, &med); test_assert(strcmp(u1->seq, " L@[ohztp{2@V(u(x7fLt&x80") == 0); test_assert(strcmp(u2->seq, " $Ee6xkB+.Q;Nk)|w[KQ;") == 0); test_assert(med == 24); unpad_useq(useqS); test_assert(strcmp(u1->seq, "L@[ohztp{2@V(u(x7fLt&x80") == 0); test_assert(strcmp(u2->seq, "$Ee6xkB+.Q;Nk)|w[KQ;") == 0); test_assert(strcmp(u3->seq, "0sdfd:'!'@{1$Ee6xkB+.Q;[Nk)|w[KQ;") == 0); destroy_useq(u1); destroy_useq(u2); destroy_useq(u3); free(useqS); }
vm_blocker_t blocker_new() { return new_gstack(sizeof(thread_t)); }
void test_seqsort (void) { gstack_t * useqS = new_gstack(); // Basic cases. for (int i = 0 ; i < 9 ; i++) { push(new_useq(1, "A", NULL), &useqS); } test_assert(useqS->nitems == 9); test_assert(seqsort((useq_t **) useqS->items, 9, 1) == 1); test_assert_critical(useqS->items[0] != NULL); useq_t *u = useqS->items[0]; test_assert(strcmp(u->seq, "A") == 0); test_assert(u->count == 9); test_assert(u->canonical == NULL); for (int i = 1 ; i < 9 ; i++) { test_assert(useqS->items[i] == NULL); } destroy_useq(useqS->items[0]); useqS->nitems = 0; for (int i = 0 ; i < 9 ; i++) { push(new_useq(1, i % 2 ? "A":"B", NULL), &useqS); } test_assert(useqS->nitems == 9); test_assert(seqsort((useq_t **) useqS->items, 9, 1) == 2); test_assert_critical(useqS->items[0] != NULL); test_assert_critical(useqS->items[1] != NULL); for (int i = 2 ; i < 9 ; i++) { test_assert(useqS->items[i] == NULL); } u = useqS->items[0]; test_assert(strcmp(u->seq, "A") == 0); test_assert(u->count == 4); test_assert(u->canonical == NULL); u = useqS->items[1]; test_assert(strcmp(u->seq, "B") == 0); test_assert(u->count == 5); test_assert(u->canonical == NULL); destroy_useq(useqS->items[0]); destroy_useq(useqS->items[1]); // Case 1 (no repeat). char *sequences_1[10] = { "IRrLv<'*3S?UU<JF4S<,", "tcKvz5JTm!h*X0mSTg", "tW:0K&Mvtax<PP/qY6er", "hcU+f!=`.Xs6[a,C7XpN", ":3ILp'w?)f]4(a;mf%A9", "RlEF',$6[}ouJQyWqqT#", "U Ct`3w8(#KAE+z;vh,", "[S^jXvNS VP' cwg~_iq", ".*/@*Q/]]}32kNB#`qqv", "#`Hwp(&,z|bN~07CSID'", }; const char *sorted_1[10] = { "tcKvz5JTm!h*X0mSTg", "U Ct`3w8(#KAE+z;vh,", "#`Hwp(&,z|bN~07CSID'", ".*/@*Q/]]}32kNB#`qqv", ":3ILp'w?)f]4(a;mf%A9", "IRrLv<'*3S?UU<JF4S<,", "RlEF',$6[}ouJQyWqqT#", "[S^jXvNS VP' cwg~_iq", "hcU+f!=`.Xs6[a,C7XpN", "tW:0K&Mvtax<PP/qY6er", }; useq_t *to_sort_1[10]; for (int i = 0 ; i < 10 ; i++) { to_sort_1[i] = new_useq(1, sequences_1[i], NULL); } test_assert(seqsort(to_sort_1, 10, 1) == 10); for (int i = 0 ; i < 10 ; i++) { test_assert(strcmp(to_sort_1[i]->seq, sorted_1[i]) == 0); test_assert(to_sort_1[i]->count == 1); destroy_useq(to_sort_1[i]); } // Case 2 (different lengths). char *sequences_2[10] = { "IRr", "tcKvz5JTm!h*X0mSTg", "tW:0K&Mvtax<PP/qY6er", "hcU+f!=`.Xs6[a,C7XpNwoi~OWe88", "z3ILp'w?)f]4(a;mf9", "RlEFWqqT#", "U Ct`3w8(#Kz;vh,", "aS^jXvNS VP' cwg~_iq", ".*/@*Q/]]}32#`", "(&,z|bN~07CSID'", }; const char *sorted_2[10] = { "IRr", "RlEFWqqT#", ".*/@*Q/]]}32#`", "(&,z|bN~07CSID'", "U Ct`3w8(#Kz;vh,", "tcKvz5JTm!h*X0mSTg", "z3ILp'w?)f]4(a;mf9", "aS^jXvNS VP' cwg~_iq", "tW:0K&Mvtax<PP/qY6er", "hcU+f!=`.Xs6[a,C7XpNwoi~OWe88", }; useq_t *to_sort_2[10]; for (int i = 0 ; i < 10 ; i++) { to_sort_2[i] = new_useq(1, sequences_2[i], NULL); } test_assert(seqsort(to_sort_2, 10, 1) == 10); for (int i = 0 ; i < 10 ; i++) { test_assert(strcmp(to_sort_2[i]->seq, sorted_2[i]) == 0); test_assert(to_sort_2[i]->count == 1); destroy_useq(to_sort_2[i]); } // Case 3 (repeats). char *sequences_3[6] = { "repeat", "repeat", "repeat", "repeat", "repeat", "xyz" }; char *sorted_3[6] = { "xyz", "repeat", NULL, NULL, NULL, NULL, }; int counts[2] = {1,5}; useq_t *to_sort_3[6]; for (int i = 0 ; i < 6 ; i++) { to_sort_3[i] = new_useq(1, sequences_3[i], NULL); } test_assert(seqsort(to_sort_3, 6, 1) == 2); for (int i = 0 ; i < 2 ; i++) { test_assert(strcmp(to_sort_3[i]->seq, sorted_3[i]) == 0); test_assert(to_sort_3[i]->count == counts[i]); destroy_useq(to_sort_3[i]); } for (int i = 2 ; i < 6 ; i++) { test_assert(to_sort_3[i] == NULL); } // Case 4 (realistic). char *seq[35] = { "AGGGCTTACAAGTATAGGCC", "TGCGCCAAGTACGATTTCCG", "CCTCATTATTTGTCGCAATG", "AGGGCTTACAAGTATAGGCC", "AGGGCTTACAAGTATAGGCC", "GGGAGCCCACAGTAAGCGAA", "GGGAGCCCACAGTAAGCGAA", "TAGCCTGGTGCGACTGTCAT", "TAGCCTGGTGCGACTGTCAT", "GGAAGCCCACAGCAAGCGAA", "TGCGCCAAGTACGATTTCCG", "GGGAGCCCACAGTAAGCGAA", "AGGGGTTACAAGTCTAGGCC", "CCTCATTATTTGTCGCAATG", "GGGAGCCCACAGTAAGCGAA", "TAGCCTGGTGCGACTGTCAT", "AGGGCTTACAAGTATAGGCC", "TGCGCCAAGTACGATTTCCG", "CCTCATTATTTGTCGCAATG", "AGGGCTTACAAGTATAGGCC", "TAGCCTGGTGCGACTGTCAT", "AGGGCTTACAAGTATAGGCC", "TGCGCCAAGTAAGAATTCCG", "GGGAGCCCACAGTAAGCGAA", "GGGAGCCCACAGTAAGCGAA", "TGCGCCAAGTACGATTTCCG", "CCTCATTATTTGTCGCAATG", "TAGCCTGGTGCGACTGTCAT", "TGCGCCAAGTACGATTTCCG", "CCTCATTATTTGTCGCAATG", "CCTCATTATTTGTCGCAATG", "CCTCATTATTTACCGCAATG", "TAGCCTGGTGCGACTGTCAT", "TGCGCCAAGTACGATTTCCG", "TAACCTGGTGCGACTGTTAT", }; char *sorted_4[10] = { "AGGGCTTACAAGTATAGGCC", "AGGGGTTACAAGTCTAGGCC", "CCTCATTATTTACCGCAATG", "CCTCATTATTTGTCGCAATG", "GGAAGCCCACAGCAAGCGAA", "GGGAGCCCACAGTAAGCGAA", "TAACCTGGTGCGACTGTTAT", "TAGCCTGGTGCGACTGTCAT", "TGCGCCAAGTAAGAATTCCG", "TGCGCCAAGTACGATTTCCG", }; int counts_4[10] = {6,1,1,6,1,6,1,6,1,6}; // Test 'seqsort()' with 1 to 8 threads. for (int t = 1 ; t < 9 ; t++) { useqS->nitems = 0; for (int i = 0 ; i < 35 ; i++) { push(new_useq(1, seq[i], NULL), &useqS); } test_assert(seqsort((useq_t **) useqS->items, 35, t) == 10); for (int i = 0 ; i < 10 ; i++) { test_assert_critical(useqS->items[i] != NULL); u = useqS->items[i]; test_assert(strcmp(u->seq, sorted_4[i]) == 0); test_assert(u->count == counts_4[i]); test_assert(u->canonical == NULL); destroy_useq(u); } for (int i = 10 ; i < 35 ; i++) { test_assert(useqS->items[i] == NULL); } } free(useqS); }