refactor tests

This commit is contained in:
Raffaele Mignone 2019-03-12 21:30:10 +01:00
parent 8df221cd1b
commit 96b22b95da
Signed by: norangebit
GPG Key ID: F5255658CB220573
2 changed files with 16 additions and 37 deletions

View File

@ -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<Int>()
@Before
fun makeQueue() {
queue = ResizingArrayQueue()
}
@Test
fun testEnqueue() {
val queue = ResizingArrayQueue<Int>()
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<Int>()
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<Int>()
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<Int>()
(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<Int>()
queue.enqueue(1)
queue.enqueue(2)
queue.enqueue(3)
@ -86,8 +84,6 @@ class ResizingArrayQueueTest {
@Test
fun testDecreaseSize() {
val queue = ResizingArrayQueue<Int>()
queue.enqueue(1)
queue.enqueue(2)
queue.enqueue(3)
@ -103,15 +99,13 @@ class ResizingArrayQueueTest {
@Test
fun testMap() {
val queue = ResizingArrayQueue<Int>()
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<Int>()
queue.enqueue(1)
queue.enqueue(2)
queue.enqueue(3)
@ -139,8 +131,6 @@ class ResizingArrayQueueTest {
@Test
fun testClean() {
val queue = ResizingArrayQueue<Int>()
queue.enqueue(1)
queue.enqueue(2)
queue.clean()

View File

@ -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<Int>()
@Before
fun makeStack() {
stack = ResizingArrayStack()
}
@Test
fun testPush() {
val stack = ResizingArrayStack<Int>()
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<Int>()
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<Int>()
(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<Int>()
(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<Int>()
stack.push(1)
stack.push(2)
stack.push(3)
@ -83,8 +80,6 @@ class ResizingArrayStackTest {
@Test
fun testDecreaseSize() {
val stack = ResizingArrayStack<Int>()
stack.push(1)
stack.push(2)
stack.push(3)
@ -100,15 +95,13 @@ class ResizingArrayStackTest {
@Test
fun testMap() {
val stack = ResizingArrayStack<Int>()
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<Int>()
stack.push(1)
stack.push(2)
stack.push(3)
@ -136,8 +127,6 @@ class ResizingArrayStackTest {
@Test
fun testClean() {
val stack = ResizingArrayStack<Int>()
stack.push(1)
stack.push(2)
stack.clean()