Skip to content

Commit

Permalink
fixup! core/lib/cib: add several new peek functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Enoch247 committed Mar 14, 2024
1 parent 2533211 commit f76d013
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions tests/unittests/tests-core/tests-core-cib.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down

0 comments on commit f76d013

Please sign in to comment.