circular buffer test init

This commit is contained in:
priyank-sriv 2020-06-15 01:18:22 +05:30
parent f2957bf7ea
commit 5263fbf070
1 changed files with 44 additions and 0 deletions

View File

@ -0,0 +1,44 @@
package com.baeldung.circularbuffer;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.Test;
public class CircularBufferUnitTest {
private final String[] shapes = { "Circle", "Triangle", "Rectangle", "Square", "Rhombus", "Trapezoid", "Pentagon", "Pentagram", "Hexagon", "Hexagram" };
@Test
public void givenCircularBuffer_WhenAnElementIsAddedAndRemoved_thenBufferIsEmpty() {
int capacity = 2;
CircularBuffer<String> buffer = new CircularBuffer<>(capacity);
assertEquals(capacity, buffer.capacity());
buffer.offer("Rectangle");
assertEquals(false, buffer.isEmpty());
assertEquals(1, buffer.size());
buffer.poll();
assertEquals(true, buffer.isEmpty());
}
@Test
public void givenCircularBuffer_WhenElementsAreAddedToCapacity_thenBufferIsFull() {
int capacity = shapes.length;
CircularBuffer<String> buffer = new CircularBuffer<>(capacity);
assertEquals(true, buffer.isEmpty());
for (String shape : shapes) {
buffer.offer(shape);
}
assertEquals(true, buffer.isFull());
}
}