PrioQueueClear(&intQ);
}
-static void push()
+static void simple_push()
{
int val = 1;
START_TEST(test_priority_queue_push)
{
- push();
+ simple_push();
+ PrioQueueClear(&intQ);
+
+ int val = 3;
+ PrioQueuePush(&intQ, &val, 1);
+ ck_assert_int_eq(*(int *)intQ.head->data, 3);
+ ck_assert_int_eq(*(int *)intQ.tail->data, 3);
+ ck_assert_int_eq(intQ.head->priority, 1);
+ ck_assert_int_eq(intQ.tail->priority, 1);
+
+ val=4;
+ PrioQueuePush(&intQ, &val, 5);
+ ck_assert_int_eq(*(int *)intQ.head->data, 4);
+ ck_assert_int_eq(*(int *)intQ.tail->data, 3);
+ ck_assert_int_eq(intQ.head->priority, 5);
+ ck_assert_int_eq(intQ.tail->priority, 1);
+
+ val = 10;
+ PrioQueuePush(&intQ, &val, 6);
+ ck_assert_int_eq(*(int *)intQ.head->data, 10);
+ ck_assert_int_eq(*(int *)intQ.tail->data, 3);
+ ck_assert_int_eq(intQ.head->priority, 6);
+ ck_assert_int_eq(intQ.tail->priority, 1);
+
+ val = 11;
+ PrioQueuePush(&intQ, &val, 4);
+ ck_assert_int_eq(*(int *)intQ.head->data, 10);
+ ck_assert_int_eq(*(int *)intQ.tail->data, 3);
+ ck_assert_int_eq(intQ.head->priority, 6);
+ ck_assert_int_eq(intQ.tail->priority, 1);
+
+ val = 21;
+ PrioQueuePush(&intQ, &val, 0);
+ ck_assert_int_eq(*(int *)intQ.head->data, 10);
+ ck_assert_int_eq(*(int *)intQ.tail->data, 21);
+ ck_assert_int_eq(intQ.head->priority, 6);
+ ck_assert_int_eq(intQ.tail->priority, 0);
+
+ // verifying the expected order is
+ // 10, 4, 11, 3, 21
+ PrioQueuePrint(&intQ);
+
+
+ PrioQueuePeek(&intQ, &val);
+ ck_assert_int_eq(val, 10);
+ PrioQueuePop(&intQ, &val);
+ ck_assert_int_eq(val, 10);
+
+ PrioQueuePeek(&intQ, &val);
+ ck_assert_int_eq(val, 4);
+ PrioQueuePop(&intQ, &val);
+ ck_assert_int_eq(val, 4);
+
+ PrioQueuePeek(&intQ, &val);
+ ck_assert_int_eq(val, 11);
+ PrioQueuePop(&intQ, &val);
+ ck_assert_int_eq(val, 11);
+
+ PrioQueuePeek(&intQ, &val);
+ ck_assert_int_eq(val, 3);
+ PrioQueuePop(&intQ, &val);
+ ck_assert_int_eq(val, 3);
+
+ PrioQueuePeek(&intQ, &val);
+ ck_assert_int_eq(val, 21);
+ PrioQueuePop(&intQ, &val);
+ ck_assert_int_eq(val, 21);
}
END_TEST
START_TEST(test_priority_queue_pop)
{
- push();
+ simple_push();
int data = 0;
PrioQueuePop(&intQ, &data);
START_TEST(test_priority_queue_clear)
{
- push();
+ simple_push();
PrioQueueClear(&intQ);
ck_assert_ptr_null(intQ.head);
ck_assert_ptr_null(intQ.tail);
START_TEST(test_priority_queue_peek)
{
int i = 0;
- push();
+ simple_push();
PrioQueuePeek(&intQ, &i);
ck_assert_int_eq(i, 1);
}