Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add tests for ring_peek

  • Loading branch information...
commit 86d5c36ed488ee89a333ee670518eff499c4af5e 1 parent 7ec3885
@jordansissel jordansissel authored
Showing with 9 additions and 1 deletion.
  1. +9 −1 test_ring.c
View
10 test_ring.c
@@ -6,16 +6,24 @@ int main(void) {
struct ring *ring;
ring = ring_new_size(4);
+ char *val;
insist(ring_is_empty(ring), "A new ring must be empty");
insist(ring_push(ring, "Hello world 1") == RING_OK, "Pushing 1 into a 4-slot ring must be OK");
+ ring_peek(ring, 0, (void **)&val);
+ insist(strcmp(val, "Hello world 1") == 0, "ring_peek(0) failed");
insist(ring_push(ring, "Hello world 2") == RING_OK, "Pushing 2 into a 4-slot ring must be OK");
+ ring_peek(ring, 1, (void **)&val);
+ insist(strcmp(val, "Hello world 2") == 0, "ring_peek(1) failed");
insist(ring_push(ring, "Hello world 3") == RING_OK, "Pushing 3 into a 4-slot ring must be OK");
+ ring_peek(ring, 2, (void **)&val);
+ insist(strcmp(val, "Hello world 3") == 0, "ring_peek(2) failed");
insist(ring_push(ring, "Hello world 4") == RING_OK, "Pushing 4 into a 4-slot ring must be OK");
+ ring_peek(ring, 3, (void **)&val);
+ insist(strcmp(val, "Hello world 4") == 0, "ring_peek(3) failed");
insist(ring_push(ring, "Hello world 5") == RING_IS_FULL, "Pushing 5 into a 4-slot ring must fail ");
insist(ring_is_full(ring), "The ring must be full at this point");
insist(!ring_is_empty(ring), "Ring must not be empty at this point");
- char *val;
insist(ring_pop(ring, (void **)&val) == RING_OK, "Popping from a full ring must succeed");
insist(strcmp(val, "Hello world 1") == 0, "Got the wrong string?");
insist(ring_pop(ring, (void **)&val) == RING_OK, "Popping on a non-empty ring must succeed");
Please sign in to comment.
Something went wrong with that request. Please try again.