Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aartdem committed May 5, 2024
1 parent 6b0cdc1 commit 329e07a
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
50 changes: 50 additions & 0 deletions work1/src/test/kotlin/stack/ConcurrentStackTests.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package stack

import org.jetbrains.kotlinx.lincheck.annotations.Operation
import org.jetbrains.kotlinx.lincheck.check
import org.jetbrains.kotlinx.lincheck.strategy.managed.modelchecking.ModelCheckingOptions
import org.jetbrains.kotlinx.lincheck.strategy.stress.StressOptions
import stack.common.ConcurrentStack
import stack.simple.ConcurrentTreiberStack
import kotlin.test.Test

abstract class ConcurrentStackTests(private val stack: ConcurrentStack<Int>) {
@Operation
fun push(value: Int) = stack.push(value)

@Operation
fun pop(): Int? = stack.pop()

@Operation
fun top(): Int? = stack.top()

@Test
fun stressTest() = StressOptions()
.sequentialSpecification(SequentialStack::class.java)
.check(this::class)

@Test
fun fourThreadsStressTest() = StressOptions()
.sequentialSpecification(SequentialStack::class.java)
.threads(4)
.iterations(50)
.invocationsPerIteration(1000)
.check(this::class)

@Test
fun modelCheckingTest() = ModelCheckingOptions()
.sequentialSpecification(SequentialStack::class.java)
.checkObstructionFreedom()
.check(this::class)

@Test
fun fourThreadsModelCheckingTest() = ModelCheckingOptions()
.sequentialSpecification(SequentialStack::class.java)
.checkObstructionFreedom()
.threads(4)
.iterations(50)
.invocationsPerIteration(1000)
.check(this::class)
}

class ConcurrentTreiberStackTests : ConcurrentStackTests(ConcurrentTreiberStack())
11 changes: 11 additions & 0 deletions work1/src/test/kotlin/stack/SequentialStack.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package stack

class SequentialStack {
private val deque = ArrayDeque<Int>()

fun push(x: Int) = deque.addLast(x)

fun pop(): Int? = deque.removeLastOrNull()

fun top(): Int? = deque.lastOrNull()
}

0 comments on commit 329e07a

Please sign in to comment.