-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8d86f29
commit b0569f8
Showing
21 changed files
with
585 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,5 +18,6 @@ publishing.sh | |
|
||
local.* | ||
local/ | ||
**/*.local.* | ||
|
||
.kotlin/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
plugins { | ||
id "org.jetbrains.kotlin.multiplatform" | ||
id "org.jetbrains.kotlin.plugin.serialization" | ||
id "com.android.library" | ||
} | ||
|
||
project.version = "$version" | ||
project.group = "$group" | ||
|
||
kotlin { | ||
jvm { | ||
compilations.main { | ||
kotlinOptions { | ||
jvmTarget = "17" | ||
} | ||
} | ||
} | ||
js (IR) { | ||
browser() | ||
nodejs() | ||
} | ||
androidTarget { | ||
compilations.all { | ||
kotlinOptions { | ||
jvmTarget = "17" | ||
} | ||
} | ||
} | ||
linuxX64() | ||
mingwX64() | ||
linuxArm64() | ||
|
||
sourceSets { | ||
commonMain { | ||
dependencies { | ||
implementation kotlin('stdlib') | ||
api libs.kt.serialization | ||
api kotlin('test') | ||
api kotlin('test-annotations-common') | ||
api libs.kt.coroutines.test | ||
api project(":micro_utils.repos.common") | ||
} | ||
} | ||
|
||
jvmMain { | ||
dependencies { | ||
implementation kotlin('test-junit') | ||
} | ||
} | ||
jsMain { | ||
dependencies { | ||
implementation kotlin('test-js') | ||
} | ||
} | ||
nativeMain.dependsOn commonMain | ||
linuxX64Main.dependsOn nativeMain | ||
mingwX64Main.dependsOn nativeMain | ||
linuxArm64Main.dependsOn nativeMain | ||
|
||
androidMain.dependsOn jvmMain | ||
} | ||
} | ||
|
||
apply from: "$defaultAndroidSettingsPresetPath" | ||
|
||
java { | ||
sourceCompatibility = JavaVersion.VERSION_17 | ||
targetCompatibility = JavaVersion.VERSION_17 | ||
} |
76 changes: 76 additions & 0 deletions
76
repos/common/tests/src/commonMain/kotlin/CommonCRUDRepoTests.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import com.benasher44.uuid.uuid4 | ||
import dev.inmo.micro_utils.repos.CRUDRepo | ||
import dev.inmo.micro_utils.repos.create | ||
import dev.inmo.micro_utils.repos.deleteById | ||
import korlibs.time.seconds | ||
import kotlinx.coroutines.test.runTest | ||
import kotlin.test.* | ||
|
||
abstract class CommonCRUDRepoTests : CommonRepoTests<CRUDRepo<CommonCRUDRepoTests.Registered, String, CommonCRUDRepoTests.New>>() { | ||
data class New( | ||
val data: String | ||
) | ||
data class Registered( | ||
val id: String, | ||
val data: String | ||
) | ||
|
||
open fun creatingWorksProperly() = runTest(timeout = 120.seconds) { | ||
val crudRepo = repoCreator() | ||
val testData = (0 until testSequencesSize).map { | ||
("$it-" + uuid4().toString()) | ||
} | ||
val updatedTestData = (0 until 1000).map { | ||
("$it-" + uuid4().toString()) | ||
} | ||
|
||
val registereds = testData.map { | ||
val created = crudRepo.create(New(it)).first() | ||
assertEquals(it, created.data) | ||
assertEquals(crudRepo.getById(created.id), created) | ||
created | ||
} | ||
|
||
crudRepo.getAll().forEach { (id, value) -> | ||
assertTrue { | ||
registereds.first { | ||
it.id == id | ||
} == value | ||
} | ||
} | ||
val updatedRegistereds = registereds.mapIndexed { i, it -> | ||
val updated = crudRepo.update(it.id, New(updatedTestData[i])) ?: error("Unable to update data for $it") | ||
assertEquals(updatedTestData[i], updated.data) | ||
assertEquals(crudRepo.getById(updated.id), updated) | ||
updated | ||
} | ||
crudRepo.getAll().forEach { (id, value) -> | ||
assertTrue { | ||
updatedRegistereds.first { | ||
it.id == id | ||
} == value | ||
} | ||
} | ||
} | ||
@Test | ||
open fun removingWorksProperly() = runTest { | ||
val crudRepo = repoCreator() | ||
val testData = (0 until testSequencesSize).map { | ||
(it.toString() + uuid4().toString()) | ||
} | ||
val registereds = crudRepo.create(testData.map { New(it) }) | ||
|
||
registereds.forEach { | ||
val id = it.id | ||
assertTrue { | ||
crudRepo.getAll()[id] == it | ||
} | ||
|
||
crudRepo.deleteById(id) | ||
assertFalse { | ||
crudRepo.contains(id) | ||
} | ||
} | ||
assertEquals(0, crudRepo.count()) | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
repos/common/tests/src/commonMain/kotlin/CommonKeyValueRepoTests.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import com.benasher44.uuid.uuid4 | ||
import dev.inmo.micro_utils.repos.* | ||
import korlibs.time.seconds | ||
import kotlinx.coroutines.test.runTest | ||
import kotlin.test.assertEquals | ||
import kotlin.test.assertFalse | ||
import kotlin.test.assertTrue | ||
|
||
abstract class CommonKeyValueRepoTests : CommonRepoTests<KeyValueRepo<String, String>>() { | ||
open fun creatingWorksProperly() = runTest(timeout = 120.seconds) { | ||
val repo = repoCreator() | ||
val testData = (0 until testSequencesSize).associate { | ||
("$it-" + uuid4().toString()) to "$it-" + uuid4().toString() | ||
} | ||
val updatedTestData = testData.keys.associateWith { | ||
"$it-" + uuid4().toString() | ||
} | ||
|
||
testData.forEach { | ||
repo.set(it.key, it.value) | ||
assertEquals(it.value, repo.get(it.key)) | ||
} | ||
|
||
updatedTestData.forEach { | ||
repo.set(it.key, it.value) | ||
assertEquals(repo.get(it.key), it.value) | ||
} | ||
} | ||
open fun unsettingWorksProperly() = runTest { | ||
val repo = repoCreator() | ||
val testData = (0 until testSequencesSize).associate { | ||
(it.toString() + uuid4().toString()) to uuid4().toString() | ||
} | ||
|
||
repo.set(testData) | ||
|
||
testData.forEach { | ||
val id = it.key | ||
assertTrue { | ||
repo.getAll()[id] == it.value | ||
} | ||
|
||
repo.unset(id) | ||
assertFalse { | ||
repo.contains(id) | ||
} | ||
} | ||
assertEquals(0, repo.count()) | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
repos/common/tests/src/commonMain/kotlin/CommonKeyValuesRepoTests.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import com.benasher44.uuid.uuid4 | ||
import dev.inmo.micro_utils.repos.* | ||
import korlibs.time.seconds | ||
import kotlinx.coroutines.joinAll | ||
import kotlinx.coroutines.launch | ||
import kotlinx.coroutines.test.runTest | ||
import kotlin.test.* | ||
|
||
abstract class CommonKeyValuesRepoTests : CommonRepoTests<KeyValuesRepo<String, String>>() { | ||
open fun creatingWorksProperly() = runTest(timeout = 120.seconds) { | ||
val repo = repoCreator() | ||
val testData = (0 until testSequencesSize).associate { | ||
("$it-" + uuid4().toString()) to (0 until 1000).map { | ||
"$it-" + uuid4().toString() | ||
}.sorted() | ||
} | ||
val updatedTestData = testData.keys.associateWith { | ||
(0 until 1000).map { | ||
"$it-" + uuid4().toString() | ||
}.sorted() | ||
} | ||
val addedData = testData.keys.associateWith { | ||
"$it-" + uuid4().toString() | ||
} | ||
|
||
updatedTestData.map { | ||
launch { | ||
repo.set(it.key, it.value) | ||
assertContentEquals(it.value.sorted(), repo.getAll(it.key).sorted()) | ||
} | ||
}.joinAll() | ||
|
||
updatedTestData.map { | ||
launch { | ||
repo.set(it.key, it.value) | ||
val all = repo.getAll(it.key) | ||
assertContentEquals(it.value.sorted(), all.sorted()) | ||
} | ||
}.joinAll() | ||
|
||
addedData.forEach { | ||
repo.add(it.key, it.value) | ||
assertTrue(repo.contains(it.key, it.value)) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import dev.inmo.micro_utils.repos.CRUDRepo | ||
|
||
abstract class CommonRepoTests<T> { | ||
protected open val testSequencesSize = 1000 | ||
protected abstract val repoCreator: suspend () -> T | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.