diff --git a/tests/unittests/tests-core/tests-core-cib.c b/tests/unittests/tests-core/tests-core-cib.c index 69b1824988eaf..7c5d70ddbfe93 100644 --- a/tests/unittests/tests-core/tests-core-cib.c +++ b/tests/unittests/tests-core/tests-core-cib.c @@ -74,46 +74,78 @@ static void test_cib_peek__overflow(void) static void test_cib_peek_at(void) { + /* Peeking an empty cib should give an error */ TEST_ASSERT_EQUAL_INT(-1, cib_peek_at(&cib, 0)); + /* Put 1 item in cib and check that we can peek it */ TEST_ASSERT_EQUAL_INT( 0, cib_put(&cib)); + TEST_ASSERT_EQUAL_INT( 0, cib_peek(&cib)); TEST_ASSERT_EQUAL_INT( 0, cib_peek_at(&cib, 0)); + + /* Peek past the end should give an error. */ TEST_ASSERT_EQUAL_INT(-1, cib_peek_at(&cib, 1)); + /* Put another item in cib. */ TEST_ASSERT_EQUAL_INT( 1, cib_put(&cib)); + + /* cib should now hold the indices { 0, 1 }. Test this. */ + TEST_ASSERT_EQUAL_INT( 0, cib_peek(&cib)); TEST_ASSERT_EQUAL_INT( 0, cib_peek_at(&cib, 0)); TEST_ASSERT_EQUAL_INT( 1, cib_peek_at(&cib, 1)); TEST_ASSERT_EQUAL_INT(-1, cib_peek_at(&cib, 2)); + /* Put another item in cib. */ TEST_ASSERT_EQUAL_INT( 2, cib_put(&cib)); + + /* cib should now hold the indices { 0, 1, 2 }. Test this. */ + TEST_ASSERT_EQUAL_INT( 0, cib_peek(&cib)); TEST_ASSERT_EQUAL_INT( 0, cib_peek_at(&cib, 0)); TEST_ASSERT_EQUAL_INT( 1, cib_peek_at(&cib, 1)); TEST_ASSERT_EQUAL_INT( 2, cib_peek_at(&cib, 2)); TEST_ASSERT_EQUAL_INT(-1, cib_peek_at(&cib, 3)); + /* Put another item in cib. */ TEST_ASSERT_EQUAL_INT( 3, cib_put(&cib)); + + /* cib should now hold the indices { 0, 1, 2, 3 }. Test this. */ + TEST_ASSERT_EQUAL_INT( 0, cib_peek(&cib)); TEST_ASSERT_EQUAL_INT( 0, cib_peek_at(&cib, 0)); TEST_ASSERT_EQUAL_INT( 1, cib_peek_at(&cib, 1)); TEST_ASSERT_EQUAL_INT( 2, cib_peek_at(&cib, 2)); TEST_ASSERT_EQUAL_INT( 3, cib_peek_at(&cib, 3)); TEST_ASSERT_EQUAL_INT(-1, cib_peek_at(&cib, 4)); + /* Remove an item from cib. */ TEST_ASSERT_EQUAL_INT( 0, cib_get(&cib)); + + /* cib should now hold the indices { 1, 2, 3 }. Test this. */ + TEST_ASSERT_EQUAL_INT( 1, cib_peek(&cib)); TEST_ASSERT_EQUAL_INT( 1, cib_peek_at(&cib, 0)); TEST_ASSERT_EQUAL_INT( 2, cib_peek_at(&cib, 1)); TEST_ASSERT_EQUAL_INT( 3, cib_peek_at(&cib, 2)); TEST_ASSERT_EQUAL_INT(-1, cib_peek_at(&cib, 3)); + /* Remove another item from cib. */ TEST_ASSERT_EQUAL_INT( 1, cib_get(&cib)); + + /* cib should now hold the indices { 2, 3 }. Test this. */ + TEST_ASSERT_EQUAL_INT( 2, cib_peek(&cib)); TEST_ASSERT_EQUAL_INT( 2, cib_peek_at(&cib, 0)); TEST_ASSERT_EQUAL_INT( 3, cib_peek_at(&cib, 1)); TEST_ASSERT_EQUAL_INT(-1, cib_peek_at(&cib, 2)); + /* Remove another item from cib. */ TEST_ASSERT_EQUAL_INT( 2, cib_get(&cib)); + + /* cib should now hold the indices { 3 }. Test this. */ + TEST_ASSERT_EQUAL_INT( 3, cib_peek(&cib)); TEST_ASSERT_EQUAL_INT( 3, cib_peek_at(&cib, 0)); TEST_ASSERT_EQUAL_INT(-1, cib_peek_at(&cib, 1)); + /* Remove last item from cib. */ TEST_ASSERT_EQUAL_INT( 3, cib_get(&cib)); + + /* Peeking an empty cib should give an error */ TEST_ASSERT_EQUAL_INT(-1, cib_peek_at(&cib, 0)); }