diff --git a/src/test/kotlin/it/norangeb/algorithms/datastructures/queue/ResizingArrayQueueTest.kt b/src/test/kotlin/it/norangeb/algorithms/datastructures/queue/ResizingArrayQueueTest.kt index be0bfdc..0c99afd 100644 --- a/src/test/kotlin/it/norangeb/algorithms/datastructures/queue/ResizingArrayQueueTest.kt +++ b/src/test/kotlin/it/norangeb/algorithms/datastructures/queue/ResizingArrayQueueTest.kt @@ -29,13 +29,19 @@ import arrow.core.None import arrow.core.Some import arrow.core.getOrElse import org.amshove.kluent.`should be equal to` +import org.junit.Before import org.junit.jupiter.api.Test class ResizingArrayQueueTest { + private var queue = ResizingArrayQueue() + + @Before + fun makeQueue() { + queue = ResizingArrayQueue() + } @Test fun testEnqueue() { - val queue = ResizingArrayQueue() queue.size() `should be equal to` 0 queue.enqueue(1) queue.size() `should be equal to` 1 @@ -45,8 +51,6 @@ class ResizingArrayQueueTest { @Test fun testIsEmpty() { - val queue = ResizingArrayQueue() - queue.isEmpty() `should be equal to` true queue.enqueue(1) queue.isEmpty() `should be equal to` false @@ -54,8 +58,6 @@ class ResizingArrayQueueTest { @Test fun testDequeue() { - val queue = ResizingArrayQueue() - queue.size() `should be equal to` 0 (queue.dequeue() is None) `should be equal to` true queue.enqueue(1) @@ -65,8 +67,6 @@ class ResizingArrayQueueTest { @Test fun testPeek() { - val queue = ResizingArrayQueue() - (queue.peek() is None) `should be equal to` true queue.enqueue(1) (queue.peek() is Some) `should be equal to` true @@ -75,8 +75,6 @@ class ResizingArrayQueueTest { @Test fun testIncreaseSize() { - val queue = ResizingArrayQueue() - queue.enqueue(1) queue.enqueue(2) queue.enqueue(3) @@ -86,8 +84,6 @@ class ResizingArrayQueueTest { @Test fun testDecreaseSize() { - val queue = ResizingArrayQueue() - queue.enqueue(1) queue.enqueue(2) queue.enqueue(3) @@ -103,15 +99,13 @@ class ResizingArrayQueueTest { @Test fun testMap() { - val queue = ResizingArrayQueue() - queue.enqueue(1) queue.enqueue(2) queue.enqueue(3) queue.enqueue(4) queue.enqueue(5) - val newQueue = queue.map { it * 2 } as ResizingArrayQueue + val newQueue = queue.map { it * 2 } newQueue.size() `should be equal to` 5 newQueue.dequeue().getOrElse { 0 } `should be equal to` 2 @@ -123,8 +117,6 @@ class ResizingArrayQueueTest { @Test fun testForEach() { - val queue = ResizingArrayQueue() - queue.enqueue(1) queue.enqueue(2) queue.enqueue(3) @@ -139,8 +131,6 @@ class ResizingArrayQueueTest { @Test fun testClean() { - val queue = ResizingArrayQueue() - queue.enqueue(1) queue.enqueue(2) queue.clean() diff --git a/src/test/kotlin/it/norangeb/algorithms/datastructures/stack/ResizingArrayStackTest.kt b/src/test/kotlin/it/norangeb/algorithms/datastructures/stack/ResizingArrayStackTest.kt index 9ea7669..216dd09 100644 --- a/src/test/kotlin/it/norangeb/algorithms/datastructures/stack/ResizingArrayStackTest.kt +++ b/src/test/kotlin/it/norangeb/algorithms/datastructures/stack/ResizingArrayStackTest.kt @@ -28,14 +28,19 @@ package it.norangeb.algorithms.datastructures.stack import arrow.core.None import arrow.core.getOrElse import org.amshove.kluent.`should be equal to` +import org.junit.Before import org.junit.jupiter.api.Test class ResizingArrayStackTest { + private var stack = ResizingArrayStack() + + @Before + fun makeStack() { + stack = ResizingArrayStack() + } @Test fun testPush() { - val stack = ResizingArrayStack() - stack.size() `should be equal to` 0 stack.push(1) stack.size() `should be equal to` 1 @@ -43,8 +48,6 @@ class ResizingArrayStackTest { @Test fun testIsEmpty() { - val stack = ResizingArrayStack() - stack.isEmpty() `should be equal to` true stack.push(1) stack.isEmpty() `should be equal to` false @@ -52,8 +55,6 @@ class ResizingArrayStackTest { @Test fun testPeek() { - val stack = ResizingArrayStack() - (stack.peek() is None) `should be equal to` true stack.push(1) (stack.peek().getOrElse { 0 }) `should be equal to` 1 @@ -62,8 +63,6 @@ class ResizingArrayStackTest { @Test fun testPop() { - val stack = ResizingArrayStack() - (stack.pop() is None) `should be equal to` true stack.push(1) (stack.pop().getOrElse { 0 }) `should be equal to` 1 @@ -72,8 +71,6 @@ class ResizingArrayStackTest { @Test fun testIncreaseSize() { - val stack = ResizingArrayStack() - stack.push(1) stack.push(2) stack.push(3) @@ -83,8 +80,6 @@ class ResizingArrayStackTest { @Test fun testDecreaseSize() { - val stack = ResizingArrayStack() - stack.push(1) stack.push(2) stack.push(3) @@ -100,15 +95,13 @@ class ResizingArrayStackTest { @Test fun testMap() { - val stack = ResizingArrayStack() - stack.push(1) stack.push(2) stack.push(3) stack.push(4) stack.push(5) - val newStack = stack.map { it * 2 } as ResizingArrayStack + val newStack = stack.map { it * 2 } newStack.size() `should be equal to` 5 newStack.pop().getOrElse { 0 } `should be equal to` 10 @@ -120,8 +113,6 @@ class ResizingArrayStackTest { @Test fun testForEach() { - val stack = ResizingArrayStack() - stack.push(1) stack.push(2) stack.push(3) @@ -136,8 +127,6 @@ class ResizingArrayStackTest { @Test fun testClean() { - val stack = ResizingArrayStack() - stack.push(1) stack.push(2) stack.clean()