Reformat stdlib tests and samples
#KT-5558
This commit is contained in:
@@ -40,9 +40,9 @@ class Arrays {
|
||||
@Sample
|
||||
fun flattenArray() {
|
||||
val deepArray = arrayOf(
|
||||
arrayOf(1),
|
||||
arrayOf(2, 3),
|
||||
arrayOf(4, 5, 6)
|
||||
arrayOf(1),
|
||||
arrayOf(2, 3),
|
||||
arrayOf(4, 5, 6)
|
||||
)
|
||||
|
||||
assertPrints(deepArray.flatten(), "[1, 2, 3, 4, 5, 6]")
|
||||
@@ -67,9 +67,9 @@ class Arrays {
|
||||
@Sample
|
||||
fun contentDeepToString() {
|
||||
val matrix = arrayOf(
|
||||
intArrayOf(3, 7, 9),
|
||||
intArrayOf(0, 1, 0),
|
||||
intArrayOf(2, 4, 8)
|
||||
intArrayOf(3, 7, 9),
|
||||
intArrayOf(0, 1, 0),
|
||||
intArrayOf(2, 4, 8)
|
||||
)
|
||||
|
||||
assertPrints(matrix.contentDeepToString(), "[[3, 7, 9], [0, 1, 0], [2, 4, 8]]")
|
||||
|
||||
@@ -40,8 +40,8 @@ class Sequences {
|
||||
class LinkedValue<T>(val value: T, val next: LinkedValue<T>? = null)
|
||||
|
||||
fun <T> LinkedValue<T>?.asSequence(): Sequence<LinkedValue<T>> = generateSequence(
|
||||
seedFunction = { this },
|
||||
nextFunction = { it.next }
|
||||
seedFunction = { this },
|
||||
nextFunction = { it.next }
|
||||
)
|
||||
|
||||
fun <T> LinkedValue<T>?.valueSequence(): Sequence<T> = asSequence().map { it.value }
|
||||
@@ -116,7 +116,7 @@ class Sequences {
|
||||
var terms = Pair(0, 1)
|
||||
|
||||
// this sequence is infinite
|
||||
while(true) {
|
||||
while (true) {
|
||||
yield(terms.first)
|
||||
terms = Pair(terms.second, terms.first + terms.second)
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ class Comparisons {
|
||||
@Sample
|
||||
fun compareValuesByWithSingleSelector() {
|
||||
fun compareLength(a: String, b: String): Int =
|
||||
compareValuesBy(a, b) { it.length }
|
||||
compareValuesBy(a, b) { it.length }
|
||||
|
||||
assertTrue(compareLength("a", "b") == 0)
|
||||
assertTrue(compareLength("bb", "a") > 0)
|
||||
@@ -33,7 +33,7 @@ class Comparisons {
|
||||
@Sample
|
||||
fun compareValuesByWithSelectors() {
|
||||
fun compareLengthThenString(a: String, b: String): Int =
|
||||
compareValuesBy(a, b, { it.length }, { it })
|
||||
compareValuesBy(a, b, { it.length }, { it })
|
||||
|
||||
assertTrue(compareLengthThenString("b", "aa") < 0)
|
||||
|
||||
@@ -45,7 +45,7 @@ class Comparisons {
|
||||
@Sample
|
||||
fun compareValuesByWithComparator() {
|
||||
fun compareInsensitiveOrder(a: Char, b: Char): Int =
|
||||
compareValuesBy(a, b, String.CASE_INSENSITIVE_ORDER, { c -> c.toString() })
|
||||
compareValuesBy(a, b, String.CASE_INSENSITIVE_ORDER, { c -> c.toString() })
|
||||
|
||||
assertTrue(compareInsensitiveOrder('a', 'a') == 0)
|
||||
assertTrue(compareInsensitiveOrder('a', 'A') == 0)
|
||||
@@ -77,8 +77,8 @@ class Comparisons {
|
||||
val list = listOf("aa", "b", "bb", "a")
|
||||
|
||||
val sorted = list.sortedWith(compareBy(
|
||||
{ it.length },
|
||||
{ it }
|
||||
{ it.length },
|
||||
{ it }
|
||||
))
|
||||
|
||||
assertPrints(sorted, "[a, b, aa, bb]")
|
||||
@@ -89,7 +89,7 @@ class Comparisons {
|
||||
val list = listOf('B', 'a', 'A', 'b')
|
||||
|
||||
val sorted = list.sortedWith(
|
||||
compareBy(String.CASE_INSENSITIVE_ORDER) { v -> v.toString() }
|
||||
compareBy(String.CASE_INSENSITIVE_ORDER) { v -> v.toString() }
|
||||
)
|
||||
|
||||
assertPrints(sorted, "[a, A, B, b]")
|
||||
@@ -109,7 +109,7 @@ class Comparisons {
|
||||
val list = listOf('B', 'a', 'A', 'b')
|
||||
|
||||
val sorted = list.sortedWith(
|
||||
compareByDescending(String.CASE_INSENSITIVE_ORDER) { v -> v.toString() }
|
||||
compareByDescending(String.CASE_INSENSITIVE_ORDER) { v -> v.toString() }
|
||||
)
|
||||
|
||||
assertPrints(sorted, "[B, b, a, A]")
|
||||
@@ -134,7 +134,7 @@ class Comparisons {
|
||||
assertPrints(list.sortedWith(lengthComparator), "[A, b, a, aa, bb]")
|
||||
|
||||
val lengthThenCaseInsensitive = lengthComparator
|
||||
.thenBy(String.CASE_INSENSITIVE_ORDER) { it }
|
||||
.thenBy(String.CASE_INSENSITIVE_ORDER) { it }
|
||||
assertPrints(list.sortedWith(lengthThenCaseInsensitive), "[A, a, b, aa, bb]")
|
||||
}
|
||||
|
||||
@@ -157,7 +157,7 @@ class Comparisons {
|
||||
assertPrints(list.sortedWith(lengthComparator), "[A, b, a, aa, bb]")
|
||||
|
||||
val lengthThenCaseInsensitive = lengthComparator
|
||||
.thenByDescending(String.CASE_INSENSITIVE_ORDER) { it }
|
||||
.thenByDescending(String.CASE_INSENSITIVE_ORDER) { it }
|
||||
assertPrints(list.sortedWith(lengthThenCaseInsensitive), "[b, A, a, bb, aa]")
|
||||
}
|
||||
|
||||
@@ -170,7 +170,7 @@ class Comparisons {
|
||||
assertPrints(map1, "{d=0, null=0, c=1, a=1, b=2}")
|
||||
|
||||
val valueThenKeyComparator = valueComparator
|
||||
.thenComparator({ a, b -> compareValues(a.first, b.first) })
|
||||
.thenComparator({ a, b -> compareValues(a.first, b.first) })
|
||||
val map2 = list.sortedWith(valueThenKeyComparator).toMap()
|
||||
assertPrints(map2, "{null=0, d=0, a=1, c=1, b=2}")
|
||||
}
|
||||
@@ -180,7 +180,7 @@ class Comparisons {
|
||||
val list = listOf("A", "aa", "b", "bb", "a")
|
||||
|
||||
val lengthThenCaseInsensitive = compareBy<String> { it.length }
|
||||
.then(String.CASE_INSENSITIVE_ORDER)
|
||||
.then(String.CASE_INSENSITIVE_ORDER)
|
||||
|
||||
val sorted = list.sortedWith(lengthThenCaseInsensitive)
|
||||
|
||||
@@ -192,7 +192,7 @@ class Comparisons {
|
||||
val list = listOf("A", "aa", "b", "bb", "a")
|
||||
|
||||
val lengthThenCaseInsensitive = compareBy<String> { it.length }
|
||||
.thenDescending(String.CASE_INSENSITIVE_ORDER)
|
||||
.thenDescending(String.CASE_INSENSITIVE_ORDER)
|
||||
|
||||
val sorted = list.sortedWith(lengthThenCaseInsensitive)
|
||||
|
||||
@@ -226,7 +226,7 @@ class Comparisons {
|
||||
val list = listOf("aa", "b", "bb", "a")
|
||||
|
||||
val lengthThenNatural = compareBy<String> { it.length }
|
||||
.then(naturalOrder())
|
||||
.then(naturalOrder())
|
||||
|
||||
val sorted = list.sortedWith(lengthThenNatural)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user