refactor tests
This commit is contained in:
parent
8df221cd1b
commit
96b22b95da
@ -29,13 +29,19 @@ import arrow.core.None
|
|||||||
import arrow.core.Some
|
import arrow.core.Some
|
||||||
import arrow.core.getOrElse
|
import arrow.core.getOrElse
|
||||||
import org.amshove.kluent.`should be equal to`
|
import org.amshove.kluent.`should be equal to`
|
||||||
|
import org.junit.Before
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
|
|
||||||
class ResizingArrayQueueTest {
|
class ResizingArrayQueueTest {
|
||||||
|
private var queue = ResizingArrayQueue<Int>()
|
||||||
|
|
||||||
|
@Before
|
||||||
|
fun makeQueue() {
|
||||||
|
queue = ResizingArrayQueue()
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testEnqueue() {
|
fun testEnqueue() {
|
||||||
val queue = ResizingArrayQueue<Int>()
|
|
||||||
queue.size() `should be equal to` 0
|
queue.size() `should be equal to` 0
|
||||||
queue.enqueue(1)
|
queue.enqueue(1)
|
||||||
queue.size() `should be equal to` 1
|
queue.size() `should be equal to` 1
|
||||||
@ -45,8 +51,6 @@ class ResizingArrayQueueTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testIsEmpty() {
|
fun testIsEmpty() {
|
||||||
val queue = ResizingArrayQueue<Int>()
|
|
||||||
|
|
||||||
queue.isEmpty() `should be equal to` true
|
queue.isEmpty() `should be equal to` true
|
||||||
queue.enqueue(1)
|
queue.enqueue(1)
|
||||||
queue.isEmpty() `should be equal to` false
|
queue.isEmpty() `should be equal to` false
|
||||||
@ -54,8 +58,6 @@ class ResizingArrayQueueTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testDequeue() {
|
fun testDequeue() {
|
||||||
val queue = ResizingArrayQueue<Int>()
|
|
||||||
|
|
||||||
queue.size() `should be equal to` 0
|
queue.size() `should be equal to` 0
|
||||||
(queue.dequeue() is None) `should be equal to` true
|
(queue.dequeue() is None) `should be equal to` true
|
||||||
queue.enqueue(1)
|
queue.enqueue(1)
|
||||||
@ -65,8 +67,6 @@ class ResizingArrayQueueTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testPeek() {
|
fun testPeek() {
|
||||||
val queue = ResizingArrayQueue<Int>()
|
|
||||||
|
|
||||||
(queue.peek() is None) `should be equal to` true
|
(queue.peek() is None) `should be equal to` true
|
||||||
queue.enqueue(1)
|
queue.enqueue(1)
|
||||||
(queue.peek() is Some) `should be equal to` true
|
(queue.peek() is Some) `should be equal to` true
|
||||||
@ -75,8 +75,6 @@ class ResizingArrayQueueTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testIncreaseSize() {
|
fun testIncreaseSize() {
|
||||||
val queue = ResizingArrayQueue<Int>()
|
|
||||||
|
|
||||||
queue.enqueue(1)
|
queue.enqueue(1)
|
||||||
queue.enqueue(2)
|
queue.enqueue(2)
|
||||||
queue.enqueue(3)
|
queue.enqueue(3)
|
||||||
@ -86,8 +84,6 @@ class ResizingArrayQueueTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testDecreaseSize() {
|
fun testDecreaseSize() {
|
||||||
val queue = ResizingArrayQueue<Int>()
|
|
||||||
|
|
||||||
queue.enqueue(1)
|
queue.enqueue(1)
|
||||||
queue.enqueue(2)
|
queue.enqueue(2)
|
||||||
queue.enqueue(3)
|
queue.enqueue(3)
|
||||||
@ -103,15 +99,13 @@ class ResizingArrayQueueTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testMap() {
|
fun testMap() {
|
||||||
val queue = ResizingArrayQueue<Int>()
|
|
||||||
|
|
||||||
queue.enqueue(1)
|
queue.enqueue(1)
|
||||||
queue.enqueue(2)
|
queue.enqueue(2)
|
||||||
queue.enqueue(3)
|
queue.enqueue(3)
|
||||||
queue.enqueue(4)
|
queue.enqueue(4)
|
||||||
queue.enqueue(5)
|
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.size() `should be equal to` 5
|
||||||
newQueue.dequeue().getOrElse { 0 } `should be equal to` 2
|
newQueue.dequeue().getOrElse { 0 } `should be equal to` 2
|
||||||
@ -123,8 +117,6 @@ class ResizingArrayQueueTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testForEach() {
|
fun testForEach() {
|
||||||
val queue = ResizingArrayQueue<Int>()
|
|
||||||
|
|
||||||
queue.enqueue(1)
|
queue.enqueue(1)
|
||||||
queue.enqueue(2)
|
queue.enqueue(2)
|
||||||
queue.enqueue(3)
|
queue.enqueue(3)
|
||||||
@ -139,8 +131,6 @@ class ResizingArrayQueueTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testClean() {
|
fun testClean() {
|
||||||
val queue = ResizingArrayQueue<Int>()
|
|
||||||
|
|
||||||
queue.enqueue(1)
|
queue.enqueue(1)
|
||||||
queue.enqueue(2)
|
queue.enqueue(2)
|
||||||
queue.clean()
|
queue.clean()
|
||||||
|
@ -28,14 +28,19 @@ package it.norangeb.algorithms.datastructures.stack
|
|||||||
import arrow.core.None
|
import arrow.core.None
|
||||||
import arrow.core.getOrElse
|
import arrow.core.getOrElse
|
||||||
import org.amshove.kluent.`should be equal to`
|
import org.amshove.kluent.`should be equal to`
|
||||||
|
import org.junit.Before
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
|
|
||||||
class ResizingArrayStackTest {
|
class ResizingArrayStackTest {
|
||||||
|
private var stack = ResizingArrayStack<Int>()
|
||||||
|
|
||||||
|
@Before
|
||||||
|
fun makeStack() {
|
||||||
|
stack = ResizingArrayStack()
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testPush() {
|
fun testPush() {
|
||||||
val stack = ResizingArrayStack<Int>()
|
|
||||||
|
|
||||||
stack.size() `should be equal to` 0
|
stack.size() `should be equal to` 0
|
||||||
stack.push(1)
|
stack.push(1)
|
||||||
stack.size() `should be equal to` 1
|
stack.size() `should be equal to` 1
|
||||||
@ -43,8 +48,6 @@ class ResizingArrayStackTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testIsEmpty() {
|
fun testIsEmpty() {
|
||||||
val stack = ResizingArrayStack<Int>()
|
|
||||||
|
|
||||||
stack.isEmpty() `should be equal to` true
|
stack.isEmpty() `should be equal to` true
|
||||||
stack.push(1)
|
stack.push(1)
|
||||||
stack.isEmpty() `should be equal to` false
|
stack.isEmpty() `should be equal to` false
|
||||||
@ -52,8 +55,6 @@ class ResizingArrayStackTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testPeek() {
|
fun testPeek() {
|
||||||
val stack = ResizingArrayStack<Int>()
|
|
||||||
|
|
||||||
(stack.peek() is None) `should be equal to` true
|
(stack.peek() is None) `should be equal to` true
|
||||||
stack.push(1)
|
stack.push(1)
|
||||||
(stack.peek().getOrElse { 0 }) `should be equal to` 1
|
(stack.peek().getOrElse { 0 }) `should be equal to` 1
|
||||||
@ -62,8 +63,6 @@ class ResizingArrayStackTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testPop() {
|
fun testPop() {
|
||||||
val stack = ResizingArrayStack<Int>()
|
|
||||||
|
|
||||||
(stack.pop() is None) `should be equal to` true
|
(stack.pop() is None) `should be equal to` true
|
||||||
stack.push(1)
|
stack.push(1)
|
||||||
(stack.pop().getOrElse { 0 }) `should be equal to` 1
|
(stack.pop().getOrElse { 0 }) `should be equal to` 1
|
||||||
@ -72,8 +71,6 @@ class ResizingArrayStackTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testIncreaseSize() {
|
fun testIncreaseSize() {
|
||||||
val stack = ResizingArrayStack<Int>()
|
|
||||||
|
|
||||||
stack.push(1)
|
stack.push(1)
|
||||||
stack.push(2)
|
stack.push(2)
|
||||||
stack.push(3)
|
stack.push(3)
|
||||||
@ -83,8 +80,6 @@ class ResizingArrayStackTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testDecreaseSize() {
|
fun testDecreaseSize() {
|
||||||
val stack = ResizingArrayStack<Int>()
|
|
||||||
|
|
||||||
stack.push(1)
|
stack.push(1)
|
||||||
stack.push(2)
|
stack.push(2)
|
||||||
stack.push(3)
|
stack.push(3)
|
||||||
@ -100,15 +95,13 @@ class ResizingArrayStackTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testMap() {
|
fun testMap() {
|
||||||
val stack = ResizingArrayStack<Int>()
|
|
||||||
|
|
||||||
stack.push(1)
|
stack.push(1)
|
||||||
stack.push(2)
|
stack.push(2)
|
||||||
stack.push(3)
|
stack.push(3)
|
||||||
stack.push(4)
|
stack.push(4)
|
||||||
stack.push(5)
|
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.size() `should be equal to` 5
|
||||||
newStack.pop().getOrElse { 0 } `should be equal to` 10
|
newStack.pop().getOrElse { 0 } `should be equal to` 10
|
||||||
@ -120,8 +113,6 @@ class ResizingArrayStackTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testForEach() {
|
fun testForEach() {
|
||||||
val stack = ResizingArrayStack<Int>()
|
|
||||||
|
|
||||||
stack.push(1)
|
stack.push(1)
|
||||||
stack.push(2)
|
stack.push(2)
|
||||||
stack.push(3)
|
stack.push(3)
|
||||||
@ -136,8 +127,6 @@ class ResizingArrayStackTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testClean() {
|
fun testClean() {
|
||||||
val stack = ResizingArrayStack<Int>()
|
|
||||||
|
|
||||||
stack.push(1)
|
stack.push(1)
|
||||||
stack.push(2)
|
stack.push(2)
|
||||||
stack.clean()
|
stack.clean()
|
||||||
|
Loading…
Reference in New Issue
Block a user