Reformat stdlib tests and samples
#KT-5558
This commit is contained in:
@@ -192,16 +192,16 @@ class CollectionJVMTest {
|
||||
}
|
||||
|
||||
@Test fun deserializeEmptyList() = testPersistedDeserialization(
|
||||
"ac ed 00 05 73 72 00 1c 6b 6f 74 6c 69 6e 2e 63 6f 6c 6c 65 63 74 69 6f 6e 73 2e 45 6d 70 74 79 4c 69 73 74 99 6f c7 d0 a7 e0 60 32 02 00 00 78 70",
|
||||
emptyList<Any>())
|
||||
"ac ed 00 05 73 72 00 1c 6b 6f 74 6c 69 6e 2e 63 6f 6c 6c 65 63 74 69 6f 6e 73 2e 45 6d 70 74 79 4c 69 73 74 99 6f c7 d0 a7 e0 60 32 02 00 00 78 70",
|
||||
emptyList<Any>())
|
||||
|
||||
@Test fun deserializeEmptySet() = testPersistedDeserialization(
|
||||
"ac ed 00 05 73 72 00 1b 6b 6f 74 6c 69 6e 2e 63 6f 6c 6c 65 63 74 69 6f 6e 73 2e 45 6d 70 74 79 53 65 74 2f 46 b0 15 76 d7 e2 f4 02 00 00 78 70",
|
||||
emptySet<Any>())
|
||||
"ac ed 00 05 73 72 00 1b 6b 6f 74 6c 69 6e 2e 63 6f 6c 6c 65 63 74 69 6f 6e 73 2e 45 6d 70 74 79 53 65 74 2f 46 b0 15 76 d7 e2 f4 02 00 00 78 70",
|
||||
emptySet<Any>())
|
||||
|
||||
@Test fun deserializeEmptyMap() = testPersistedDeserialization(
|
||||
"ac ed 00 05 73 72 00 1b 6b 6f 74 6c 69 6e 2e 63 6f 6c 6c 65 63 74 69 6f 6e 73 2e 45 6d 70 74 79 4d 61 70 72 72 37 71 cb 04 4c d2 02 00 00 78 70",
|
||||
emptyMap<Any, Any>())
|
||||
"ac ed 00 05 73 72 00 1b 6b 6f 74 6c 69 6e 2e 63 6f 6c 6c 65 63 74 69 6f 6e 73 2e 45 6d 70 74 79 4d 61 70 72 72 37 71 cb 04 4c d2 02 00 00 78 70",
|
||||
emptyMap<Any, Any>())
|
||||
|
||||
private fun testPersistedDeserialization(hexValue: String, expected: Any) {
|
||||
val actual = deserializeFromHex<Any>(hexValue)
|
||||
|
||||
@@ -7,5 +7,5 @@ package test.collections
|
||||
|
||||
import java.util.*
|
||||
|
||||
class LinkedListTest : OrderedIterableTests<LinkedList<String>>( { LinkedList(it.asList()) }, LinkedList<String>())
|
||||
class LinkedListTest : OrderedIterableTests<LinkedList<String>>({ LinkedList(it.asList()) }, LinkedList<String>())
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ class ThreadTest {
|
||||
assertEquals("v3", v.getOrSet { "v2" })
|
||||
|
||||
|
||||
val w = object: ThreadLocal<String>() {
|
||||
val w = object : ThreadLocal<String>() {
|
||||
override fun initialValue() = "default"
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
*/
|
||||
|
||||
@file:Suppress("INVISIBLE_REFERENCE", "INVISIBLE_MEMBER")
|
||||
|
||||
package test.io
|
||||
|
||||
import org.junit.Test
|
||||
|
||||
@@ -521,8 +521,7 @@ class FilesTest {
|
||||
}
|
||||
|
||||
var conflicts = 0
|
||||
src.copyRecursively(dst) {
|
||||
_: File, e: IOException ->
|
||||
src.copyRecursively(dst) { _: File, e: IOException ->
|
||||
if (e is FileAlreadyExistsException) {
|
||||
conflicts++
|
||||
OnErrorAction.SKIP
|
||||
@@ -536,8 +535,7 @@ class FilesTest {
|
||||
try {
|
||||
dst.deleteRecursively()
|
||||
var caught = false
|
||||
assertTrue(src.copyRecursively(dst) {
|
||||
_: File, e: IOException ->
|
||||
assertTrue(src.copyRecursively(dst) { _: File, e: IOException ->
|
||||
if (e is AccessDeniedException) {
|
||||
caught = true
|
||||
OnErrorAction.SKIP
|
||||
|
||||
@@ -36,7 +36,7 @@ class IOStreamsTest {
|
||||
val result = mutableListOf<Byte>()
|
||||
|
||||
x.inputStream().buffered().use { stream ->
|
||||
for(b in stream) {
|
||||
for (b in stream) {
|
||||
result += b
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,5 +87,5 @@ private fun hexToBytes(value: String): ByteArray = value.split(" ").map { Intege
|
||||
public fun <T> deserializeFromHex(value: String) = deserializeFromByteArray<T>(hexToBytes(value))
|
||||
|
||||
public fun <T> serializeToHex(value: T) =
|
||||
serializeToByteArray(value).joinToString(" ") { (it.toInt() and 0xFF).toString(16).padStart(2, '0') }
|
||||
serializeToByteArray(value).joinToString(" ") { (it.toInt() and 0xFF).toString(16).padStart(2, '0') }
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ class BigNumbersTest {
|
||||
assertEquals(BigInteger("-1"), -a shr 1)
|
||||
assertEquals(BigInteger("-1"), -a shr 2)
|
||||
|
||||
assertEquals(BigInteger("2"), 2.toBigInteger())
|
||||
assertEquals(BigInteger("2"), 2.toBigInteger())
|
||||
assertEquals(BigInteger("-3"), -3L.toBigInteger())
|
||||
|
||||
assertEquals(BigDecimal("2"), a.toBigDecimal())
|
||||
@@ -50,7 +50,6 @@ class BigNumbersTest {
|
||||
assertEquals(BigDecimal("3"), BigInteger("253").toBigDecimal(2, MathContext(1, RoundingMode.UP)))
|
||||
|
||||
|
||||
|
||||
var c = 2.toBigInteger()
|
||||
assertEquals(BigInteger("2"), c++)
|
||||
assertEquals(BigInteger("3"), c)
|
||||
@@ -79,10 +78,10 @@ class BigNumbersTest {
|
||||
assertEquals(BigDecimal("3"), a.inc())
|
||||
assertEquals(BigDecimal("1"), a.dec())
|
||||
|
||||
assertEquals(BigDecimal("2"), 2.toBigDecimal())
|
||||
assertEquals(BigDecimal("2"), 2.toBigDecimal())
|
||||
assertEquals(BigDecimal("-3"), -3L.toBigDecimal())
|
||||
assertEquals(BigDecimal("2.0"), 2f.toBigDecimal())
|
||||
assertEquals(BigDecimal("0.5"), 0.5.toBigDecimal())
|
||||
assertEquals(BigDecimal("0.5"), 0.5.toBigDecimal())
|
||||
|
||||
var c = "1.5".toBigDecimal()
|
||||
assertEquals(BigDecimal("1.5"), c++)
|
||||
|
||||
@@ -87,7 +87,7 @@ class LazyJVMTest {
|
||||
List(threads) { lazy(lock, initializer) }
|
||||
},
|
||||
access = { lazies, runnerIndex -> lazies[runnerIndex].value },
|
||||
validate = { result -> result.all { (id, initialized) -> initialized == (id != 1)} })
|
||||
validate = { result -> result.all { (id, initialized) -> initialized == (id != 1) } })
|
||||
}
|
||||
|
||||
@Test fun publishOnceLazy() {
|
||||
@@ -95,7 +95,9 @@ class LazyJVMTest {
|
||||
val initialized = AtomicBoolean(false)
|
||||
val threads = 3
|
||||
val values = Random().let { r -> List(threads) { 50 + r.nextInt(50) } }
|
||||
|
||||
data class Run(val value: Int, val initialized: Boolean)
|
||||
|
||||
val runs = ConcurrentLinkedQueue<Run>()
|
||||
|
||||
val initializer = {
|
||||
@@ -124,11 +126,11 @@ class LazyJVMTest {
|
||||
@Test fun publishOnceLazyRace() {
|
||||
racyTest(initialize = { lazy(LazyThreadSafetyMode.PUBLICATION) { Thread.currentThread().id } },
|
||||
access = { lazy, _ -> lazy.value },
|
||||
validate = { result -> result.all { v -> v == result[0] } } )
|
||||
validate = { result -> result.all { v -> v == result[0] } })
|
||||
}
|
||||
|
||||
@Test fun lazyInitializationForcedOnSerialization() {
|
||||
for(mode in listOf(LazyThreadSafetyMode.SYNCHRONIZED, LazyThreadSafetyMode.PUBLICATION, LazyThreadSafetyMode.NONE)) {
|
||||
for (mode in listOf(LazyThreadSafetyMode.SYNCHRONIZED, LazyThreadSafetyMode.PUBLICATION, LazyThreadSafetyMode.NONE)) {
|
||||
val lazy = lazy(mode) { "initialized" }
|
||||
assertFalse(lazy.isInitialized())
|
||||
val lazy2 = serializeAndDeserialize(lazy)
|
||||
@@ -139,10 +141,11 @@ class LazyJVMTest {
|
||||
}
|
||||
|
||||
private fun <TState : Any, TResult> racyTest(
|
||||
threads: Int = 3, runs: Int = 5000,
|
||||
initialize: () -> TState,
|
||||
access: (TState, runnerIndex: Int) -> TResult,
|
||||
validate: (List<TResult>) -> Boolean) {
|
||||
threads: Int = 3, runs: Int = 5000,
|
||||
initialize: () -> TState,
|
||||
access: (TState, runnerIndex: Int) -> TResult,
|
||||
validate: (List<TResult>) -> Boolean
|
||||
) {
|
||||
|
||||
val runResult = java.util.Collections.synchronizedList(mutableListOf<TResult>())
|
||||
val invalidResults = mutableListOf<Pair<Int, List<TResult>>>()
|
||||
@@ -159,13 +162,15 @@ class LazyJVMTest {
|
||||
runId += 1
|
||||
}
|
||||
|
||||
val runners = List(threads) { index -> thread {
|
||||
barrier.await()
|
||||
repeat(runs) {
|
||||
runResult += access(state, index)
|
||||
val runners = List(threads) { index ->
|
||||
thread {
|
||||
barrier.await()
|
||||
repeat(runs) {
|
||||
runResult += access(state, index)
|
||||
barrier.await()
|
||||
}
|
||||
}
|
||||
}}
|
||||
}
|
||||
|
||||
runners.forEach { it.join() }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user