Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Module02;
- import org.junit.jupiter.api.BeforeEach;
- import org.junit.jupiter.api.Test;
- import static org.hamcrest.MatcherAssert.assertThat;
- import static org.hamcrest.CoreMatchers.equalTo;
- import static org.hamcrest.CoreMatchers.is;
- import static org.junit.jupiter.api.Assertions.*;
- class GenericStackTest {
- private GenericStack genericStack;
- @BeforeEach
- void setUp() {
- genericStack = new GenericStack(100);
- }
- @Test
- void sizeMethodShouldReturnCorrectSizeOfArray() {
- GenericStack<String> gsString = new GenericStack<>(100);
- gsString.push("Java");
- gsString.push("er");
- gsString.push("morsomt! :D");
- assertThat(gsString.size(), is(equalTo(3)));
- }
- @Test
- void peekMethodShouldReturnLastElementInArray() {
- GenericStack<String> gsString = new GenericStack<>(100);
- gsString.push("First");
- gsString.push("Second");
- gsString.push("Last");
- assertThat(gsString.peek(), is(equalTo("Last")));
- }
- @Test
- void pushMethodShouldDoubleSizeOfArrayIfArrayIsFullWhenPushing() {
- GenericStack<String> gsString = new GenericStack<>(100);
- for (int i = 0; i < 100; i++) {
- gsString.push("foo");
- }
- gsString.push("Fighters");
- assertThat(gsString.size(), is(equalTo(100 * 2)));
- }
- @Test
- void toStringMethodPrintsCorrectlyWithInteger() {
- GenericStack<Integer> gsInteger = new GenericStack<>(100);
- gsInteger.push(1);
- gsInteger.push(2);
- gsInteger.push(3);
- assertThat(gsInteger.toString(), is(equalTo("[1, 2, 3]")));
- }
- @Test
- void toStringMethodPrintsCorrectlyWithStrings() {
- GenericStack<String> gsString = new GenericStack<>(100);
- gsString.push("One");
- gsString.push("Two");
- gsString.push("Three");
- assertThat(gsString.toString(), is(equalTo("[One, Two, Three]")));
- }
- @Test
- void isEmptyMethodShouldReturnTrueIfElementsIsEmpty() {
- assertTrue(genericStack.isEmpty());
- }
- /*@Test
- void popMethodShouldRemoveLastElementInElements() {
- GenericStack<Integer> gsString = new GenericStack<>(100);
- gsString.push(1);
- gsString.push(2);
- gsString.push(3);
- gsString.push(4);
- gsString.push(5);
- gsString.pop();
- }*/
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement