diff options
author | Chandra Pratap <chandrapratap3519@gmail.com> | 2024-01-21 19:28:45 (GMT) |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2024-01-22 18:55:01 (GMT) |
commit | 808b77e5d47094ac8178b08d4c20e4893485bfca (patch) | |
tree | a3b0d157014efb3c55869a4307cb3bc25ff64ee0 /t/helper/test-prio-queue.c | |
parent | 186b115d3062e6230ee296d1ddaa0c4b72a464b5 (diff) | |
download | git-808b77e5d47094ac8178b08d4c20e4893485bfca.zip git-808b77e5d47094ac8178b08d4c20e4893485bfca.tar.gz git-808b77e5d47094ac8178b08d4c20e4893485bfca.tar.bz2 |
tests: move t0009-prio-queue.sh to the new unit testing framework
t/t0009-prio-queue.sh along with t/helper/test-prio-queue.c unit
tests Git's implementation of a priority queue. Migrate the
test over to the new unit testing framework to simplify debugging
and reduce test run-time. Refactor the required logic and add
a new test case in addition to porting over the original ones in
shell.
Signed-off-by: Chandra Pratap <chandrapratap3519@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 't/helper/test-prio-queue.c')
-rw-r--r-- | t/helper/test-prio-queue.c | 51 |
1 files changed, 0 insertions, 51 deletions
diff --git a/t/helper/test-prio-queue.c b/t/helper/test-prio-queue.c deleted file mode 100644 index f0bf255..0000000 --- a/t/helper/test-prio-queue.c +++ /dev/null @@ -1,51 +0,0 @@ -#include "test-tool.h" -#include "prio-queue.h" - -static int intcmp(const void *va, const void *vb, void *data UNUSED) -{ - const int *a = va, *b = vb; - return *a - *b; -} - -static void show(int *v) -{ - if (!v) - printf("NULL\n"); - else - printf("%d\n", *v); - free(v); -} - -int cmd__prio_queue(int argc UNUSED, const char **argv) -{ - struct prio_queue pq = { intcmp }; - - while (*++argv) { - if (!strcmp(*argv, "get")) { - void *peek = prio_queue_peek(&pq); - void *get = prio_queue_get(&pq); - if (peek != get) - BUG("peek and get results do not match"); - show(get); - } else if (!strcmp(*argv, "dump")) { - void *peek; - void *get; - while ((peek = prio_queue_peek(&pq))) { - get = prio_queue_get(&pq); - if (peek != get) - BUG("peek and get results do not match"); - show(get); - } - } else if (!strcmp(*argv, "stack")) { - pq.compare = NULL; - } else { - int *v = xmalloc(sizeof(*v)); - *v = atoi(*argv); - prio_queue_put(&pq, v); - } - } - - clear_prio_queue(&pq); - - return 0; -} |