From: Matthew Owens <matthew@owens.tech>
Date: Sun, 26 Dec 2021 15:09:41 +0000 (+0000)
Subject: added checks
X-Git-Url: https://git.owens.tech/assets/112-editable-focus.html/assets/112-editable-focus.html/git?a=commitdiff_plain;h=80049b39ba4267edb6a05d666983bb38037ac4ea;p=AbyssalThistle%2Fpriority-queue-test.git

added checks
---

diff --git a/check_priority_queue.c b/check_priority_queue.c
index 4876292..c10275a 100644
--- a/check_priority_queue.c
+++ b/check_priority_queue.c
@@ -1,17 +1,103 @@
 #include "check_priority_queue.h"
 #include "priority_queue.h"
 #include <check.h>
+#include <stdio.h>
+
+PrioQueue intQ;
 
 static void setup()
 {
+	PrioQueueInit(&intQ, sizeof(int));
 }
 
 static void teardown()
 {
+	PrioQueueClear(&intQ);
+}
+
+static void push()
+{
+	int val = 1;
+
+	printf("inserting '%d' with prio 3\n", val);
+	PrioQueuePush(&intQ, &val, 3);
+	ck_assert_int_eq(*(int *)intQ.head->data, 1);
+	ck_assert_int_eq(*(int *)intQ.tail->data, 1);
+	val++;
+
+	printf("inserting '%d' with prio 2\n", val);
+	PrioQueuePush(&intQ, &val, 2);
+	ck_assert_int_eq(*(int *)intQ.head->data, 1);
+	ck_assert_int_eq(*(int *)intQ.tail->data, 2);
+	val++;
+
+	printf("inserting '%d' with prio 1\n", val);
+	PrioQueuePush(&intQ, &val, 1);
+	ck_assert_int_eq(*(int *)intQ.head->data, 1);
+	ck_assert_int_eq(*(int *)intQ.tail->data, 3);
+	val++;
+	printf("done\n");
+}
+
+START_TEST(test_priority_queue_push)
+{
+	push();
+}
+END_TEST
+
+START_TEST(test_priority_queue_pop)
+{
+	push();
+	int data = 0;
+
+	PrioQueuePop(&intQ, &data);
+	ck_assert_int_eq(data, 1);
+	ck_assert_ptr_nonnull(intQ.head);
+	ck_assert_ptr_nonnull(intQ.tail);
+
+	PrioQueuePop(&intQ, &data);
+	ck_assert_int_eq(data, 2);
+	ck_assert_ptr_nonnull(intQ.head);
+	ck_assert_ptr_nonnull(intQ.tail);
+
+	PrioQueuePop(&intQ, &data);
+	ck_assert_int_eq(data, 3);
+	ck_assert_ptr_null(intQ.head);
+	ck_assert_ptr_null(intQ.tail);
+	ck_assert_int_eq(intQ.memSize, sizeof(int));
+}
+END_TEST
+
+START_TEST(test_priority_queue_init)
+{
+	ck_assert_ptr_null(intQ.tail);
+	ck_assert_ptr_null(intQ.head);
+	ck_assert_int_eq(sizeof(int), intQ.memSize);
 }
+END_TEST
+
+START_TEST(test_priority_queue_clear)
+{
+	push();
+	PrioQueueClear(&intQ);
+	ck_assert_ptr_null(intQ.head);
+	ck_assert_ptr_null(intQ.tail);
+	ck_assert_int_eq(0, intQ.memSize);
+}
+END_TEST
+
+START_TEST(test_priority_queue_peek)
+{
+	int i = 0;
+	push();
+	PrioQueuePeek(&intQ, &i);
+	ck_assert_int_eq(i, 1);
+}
+END_TEST
 
-START_TEST(test_priority_queue)
+START_TEST(test_priority_queue_get_size)
 {
+	ck_assert_int_eq(intQ.memSize, sizeof(int));
 }
 END_TEST
 
@@ -20,11 +106,15 @@ Suite *priority_queue_suite(void)
 	Suite *s;
 	TCase *tc;
 
-	s = suite_create("priority_queue suite");
-	tc = tcase_create("priority_queue");
+	s = suite_create("priority queue suite");
+	tc = tcase_create("priority queue");
 
-	tcase_add_unchecked_fixture(tc, setup, teardown);
-	tcase_add_test(tc, test_priority_queue);
+	tcase_add_checked_fixture(tc, setup, teardown);
+	tcase_add_test(tc, test_priority_queue_init);
+	tcase_add_test(tc, test_priority_queue_push);
+	tcase_add_test(tc, test_priority_queue_pop);
+	tcase_add_test(tc, test_priority_queue_peek);
+	tcase_add_test(tc, test_priority_queue_get_size);
 
 	suite_add_tcase(s, tc);
 	return s;