Skip to content

Commit

Permalink
Merge branch 'main' into arrow-2
Browse files Browse the repository at this point in the history
  • Loading branch information
serras committed Oct 24, 2023
2 parents 8bb1274 + a65a833 commit 6955d01
Show file tree
Hide file tree
Showing 24 changed files with 263 additions and 508 deletions.
9 changes: 2 additions & 7 deletions arrow-libs/core/arrow-annotations/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ spotless {
}
}

apply(from = property("ANIMALSNIFFER_MPP"))

kotlin {
sourceSets {
commonMain {
Expand All @@ -25,11 +27,6 @@ kotlin {
implementation(libs.kotlin.stdlib)
}
}
jvmTest {
dependencies {
runtimeOnly(libs.kotest.runnerJUnit5)
}
}
jsMain {
dependencies {
implementation(libs.kotlin.stdlibJS)
Expand All @@ -45,5 +42,3 @@ kotlin {
}
}
}

apply(from = property("ANIMALSNIFFER_MPP"))
27 changes: 2 additions & 25 deletions arrow-libs/core/arrow-atomic/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@

import org.jetbrains.kotlin.gradle.tasks.KotlinCompile


plugins {
id(libs.plugins.kotlin.multiplatform.get().pluginId)
alias(libs.plugins.arrowGradleConfig.kotlin)
alias(libs.plugins.arrowGradleConfig.publish)

alias(libs.plugins.kotest.multiplatform)
alias(libs.plugins.kotlinx.kover)
alias(libs.plugins.spotless)
}
Expand All @@ -32,15 +29,10 @@ kotlin {
commonTest {
dependencies {
implementation(projects.arrowFxCoroutines)
implementation(libs.kotest.frameworkEngine)
implementation(libs.kotlin.test)
implementation(libs.kotest.assertionsCore)
implementation(libs.kotest.property)
}
}

jvmTest {
dependencies {
runtimeOnly(libs.kotest.runnerJUnit5)
implementation(libs.coroutines.test)
}
}

Expand All @@ -55,21 +47,6 @@ kotlin {
implementation(libs.kotlin.stdlibJS)
}
}

commonTest {
dependencies {
implementation(projects.arrowFxCoroutines)
implementation(libs.kotest.frameworkEngine)
implementation(libs.kotest.assertionsCore)
implementation(libs.kotest.property)
}
}

jvmTest {
dependencies {
runtimeOnly(libs.kotest.runnerJUnit5)
}
}
}

jvm {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,53 +1,52 @@
package arrow.atomic

import arrow.fx.coroutines.parMap
import io.kotest.core.spec.style.StringSpec
import kotlin.test.Test
import kotlinx.coroutines.test.runTest
import io.kotest.matchers.shouldBe
import io.kotest.property.Arb
import io.kotest.property.arbitrary.boolean
import io.kotest.property.arbitrary.int
import io.kotest.property.arbitrary.long
import io.kotest.property.arbitrary.string
import io.kotest.property.checkAll
import kotlin.coroutines.Continuation
import kotlin.coroutines.EmptyCoroutineContext
import kotlin.coroutines.intrinsics.startCoroutineUninterceptedOrReturn

class AtomicBooleanTest : StringSpec({
class AtomicBooleanTest {

"set get - successful" {
@Test
fun setGetSuccessful() = runTest {
checkAll(Arb.boolean(), Arb.boolean()) { x, y ->
val r = AtomicBoolean(x)
r.value = y
r.value shouldBe y
}
}

"update get - successful" {
@Test
fun updateGetSuccessful() = runTest {
checkAll(Arb.boolean(), Arb.boolean()) { x, y ->
val r = AtomicBoolean(x)
r.update { y }
r.value shouldBe y
}
}

"getAndSet - successful" {
@Test
fun getAndSetSuccessful() = runTest {
checkAll(Arb.boolean(), Arb.boolean()) { x, y ->
val ref = AtomicBoolean(x)
ref.getAndSet(y) shouldBe x
ref.value shouldBe y
}
}

"getAndUpdate - successful" {
@Test
fun getAndUpdateSuccessful() = runTest {
checkAll(Arb.boolean(), Arb.boolean()) { x, y ->
val ref = AtomicBoolean(x)
ref.getAndUpdate { y } shouldBe x
ref.value shouldBe y
}
}

"updateAndGet - successful" {
@Test
fun updateAndGetSuccessful() = runTest {
checkAll(Arb.boolean(), Arb.boolean()) { x, y ->
val ref = AtomicBoolean(x)
ref.updateAndGet {
Expand All @@ -57,15 +56,17 @@ class AtomicBooleanTest : StringSpec({
}
}

"tryUpdate - modification occurs successfully" {
@Test
fun tryUpdateModificationOccursSuccessfully() = runTest {
checkAll(Arb.boolean()) { x ->
val ref = AtomicBoolean(x)
ref.tryUpdate { !it }
ref.value shouldBe !x
}
}

"tryUpdate - should fail to update if modification has occurred" {
@Test
fun tryUpdateShouldFailToUpdateIfModificationHasOccurred() = runTest {
checkAll(Arb.boolean()) { x ->
val ref = AtomicBoolean(x)
ref.tryUpdate {
Expand All @@ -75,7 +76,8 @@ class AtomicBooleanTest : StringSpec({
}
}

"consistent set update on strings" {
@Test
fun consistentSetUpdateOnStrings() = runTest {
checkAll(Arb.boolean(), Arb.boolean()) { x, y ->
val set = {
val r = AtomicBoolean(x)
Expand All @@ -92,4 +94,4 @@ class AtomicBooleanTest : StringSpec({
set() shouldBe update()
}
}
})
}
Original file line number Diff line number Diff line change
@@ -1,51 +1,53 @@
package arrow.atomic

import arrow.fx.coroutines.parMap
import io.kotest.core.spec.style.StringSpec
import kotlin.test.Test
import kotlinx.coroutines.test.runTest
import io.kotest.matchers.shouldBe
import io.kotest.property.Arb
import io.kotest.property.arbitrary.int
import io.kotest.property.arbitrary.string
import io.kotest.property.checkAll
import kotlin.coroutines.Continuation
import kotlin.coroutines.EmptyCoroutineContext
import kotlin.coroutines.intrinsics.startCoroutineUninterceptedOrReturn

class AtomicIntTest : StringSpec({
class AtomicIntTest {

"set get - successful" {
@Test
fun setGetSuccessful() = runTest {
checkAll(Arb.int(), Arb.int()) { x, y ->
val r = AtomicInt(x)
r.value = y
r.value shouldBe y
}
}

"update get - successful" {
@Test
fun updateGetSuccessful() = runTest {
checkAll(Arb.int(), Arb.int()) { x, y ->
val r = AtomicInt(x)
r.update { y }
r.value shouldBe y
}
}

"getAndSet - successful" {
@Test
fun getAndSetSuccessful() = runTest {
checkAll(Arb.int(), Arb.int()) { x, y ->
val ref = AtomicInt(x)
ref.getAndSet(y) shouldBe x
ref.value shouldBe y
}
}

"getAndUpdate - successful" {
@Test
fun getAndUpdateSuccessful() = runTest {
checkAll(Arb.int(), Arb.int()) { x, y ->
val ref = AtomicInt(x)
ref.getAndUpdate { y } shouldBe x
ref.value shouldBe y
}
}

"updateAndGet - successful" {
@Test
fun updateAndGetSuccessful() = runTest {
checkAll(Arb.int(), Arb.int()) { x, y ->
val ref = AtomicInt(x)
ref.updateAndGet {
Expand All @@ -55,15 +57,17 @@ class AtomicIntTest : StringSpec({
}
}

"tryUpdate - modification occurs successfully" {
@Test
fun tryUpdateModificationOccursSuccessfully() = runTest {
checkAll(Arb.int()) { x ->
val ref = AtomicInt(x)
ref.tryUpdate { it + 1 }
ref.value shouldBe x + 1
}
}

"tryUpdate - should fail to update if modification has occurred" {
@Test
fun tryUpdateShouldFailToUpdateIfModificationHasOccurred() = runTest {
checkAll(Arb.int()) { x ->
val ref = AtomicInt(x)
ref.tryUpdate {
Expand All @@ -73,7 +77,8 @@ class AtomicIntTest : StringSpec({
}
}

"consistent set update on strings" {
@Test
fun consistentSetUpdateOnStrings() = runTest {
checkAll(Arb.int(), Arb.int()) { x, y ->
val set = {
val r = AtomicInt(x)
Expand All @@ -91,11 +96,11 @@ class AtomicIntTest : StringSpec({
}
}

"concurrent modifications" {
val finalValue = 50_000
@Test
fun concurrentModifications() = runTestWithDelay {
val finalValue = stackSafeIteration()
val r = AtomicInt(0)
(0 until finalValue).parMap { r.update { it + 1 } }
r.value shouldBe finalValue
}
}
)
Loading

0 comments on commit 6955d01

Please sign in to comment.