Skip to content

Commit a500338

Browse files
kotlin-samples-pusher-botdkrasnoff
authored andcommitted
test(samples): add new samples
1 parent 178af80 commit a500338

File tree

308 files changed

+1080
-188
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

308 files changed

+1080
-188
lines changed

src/test/kotlin/com/compiler/server/ResourceE2ECompileTest.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ private fun File.isInconsistentOutput(): Boolean {
134134
" measureTime {",
135135
" measureTimedValue {",
136136
"LocalDate.now()",
137+
"Clock.System.now()"
137138
).any { code.contains(it) }
138139
}
139140

src/test/resources/test-compile-data/jvm/kotlin-by-example/01_delegationPattern/d260a1f6a0ee99a60978712f417ce764.1.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@ interface SoundBehavior {
22
fun makeSound()
33
}
44

5-
class ScreamBehavior(val n:String): SoundBehavior { // 2
5+
class ScreamBehavior(val n: String): SoundBehavior { // 2
66
override fun makeSound() = println("${n.uppercase()} !!!")
77
}
88

9-
class RockAndRollBehavior(val n:String): SoundBehavior { // 2
9+
class RockAndRollBehavior(val n: String): SoundBehavior { // 2
1010
override fun makeSound() = println("I'm The King of Rock 'N' Roll: $n")
1111
}
1212

1313
// Tom Araya is the "singer" of Slayer
14-
class TomAraya(n:String): SoundBehavior by ScreamBehavior(n) // 3
14+
class TomAraya(n: String): SoundBehavior by ScreamBehavior(n) // 3
1515

1616
// You should know ;)
17-
class ElvisPresley(n:String): SoundBehavior by RockAndRollBehavior(n) // 3
17+
class ElvisPresley(n: String): SoundBehavior by RockAndRollBehavior(n) // 3
1818

1919
fun main() {
2020
val tomAraya = TomAraya("Thrash Metal")
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
fun main() {
22
//sampleStart
3-
val numbers = listOf("one", "two", "three", "four")
4-
println(numbers.shuffled())
3+
val numbers = listOf("one", "two", "three", "four")
4+
val reversedNumbers = numbers.asReversed()
5+
println(reversedNumbers)
56
//sampleEnd
67
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
fun main() {
2+
//sampleStart
3+
val numbers = mutableListOf("one", "two", "three", "four")
4+
val reversedNumbers = numbers.asReversed()
5+
println(reversedNumbers)
6+
numbers.add("five")
7+
println(reversedNumbers)
8+
//sampleEnd
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
fun main() {
2+
//sampleStart
3+
val numbers = listOf("one", "two", "three", "four")
4+
println(numbers.shuffled())
5+
//sampleEnd
6+
}
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
fun main() {
22
//sampleStart
3-
val numbers = listOf("one", "two", "three", "four")
3+
val sortedStrings = listOf("aaa", "bb", "c", "b", "a", "aa", "ccc")
4+
.sortedWith { a, b ->
5+
when (val compareLengths = a.length.compareTo(b.length)) {
6+
0 -> a.compareTo(b)
7+
else -> compareLengths
8+
}
9+
}
410

5-
println("Sorted ascending: ${numbers.sorted()}")
6-
println("Sorted descending: ${numbers.sortedDescending()}")
11+
println(sortedStrings)
12+
// [a, b, c, aa, bb, aaa, ccc]
713
//sampleEnd
814
}
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
fun main() {
22
//sampleStart
3-
val numbers = listOf("one", "two", "three", "four")
3+
val sortedStrings = listOf("aaa", "bb", "c", "b", "a", "aa", "ccc")
4+
.sortedWith(compareBy<String> { it.length }.thenBy { it })
45

5-
val sortedNumbers = numbers.sortedBy { it.length }
6-
println("Sorted by length ascending: $sortedNumbers")
7-
val sortedByLast = numbers.sortedByDescending { it.last() }
8-
println("Sorted by the last letter descending: $sortedByLast")
6+
println(sortedStrings)
7+
// [a, b, c, aa, bb, aaa, ccc]
98
//sampleEnd
109
}
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
fun main() {
22
//sampleStart
33
val numbers = listOf("one", "two", "three", "four")
4-
println("Sorted by length ascending: ${numbers.sortedWith(compareBy { it.length })}")
4+
5+
println("Sorted ascending: ${numbers.sorted()}")
6+
println("Sorted descending: ${numbers.sortedDescending()}")
57
//sampleEnd
68
}
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
fun main() {
22
//sampleStart
33
val numbers = listOf("one", "two", "three", "four")
4-
println(numbers.reversed())
4+
5+
val sortedNumbers = numbers.sortedBy { it.length }
6+
println("Sorted by length ascending: $sortedNumbers")
7+
val sortedByLast = numbers.sortedByDescending { it.last() }
8+
println("Sorted by the last letter descending: $sortedByLast")
59
//sampleEnd
610
}
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
fun main() {
22
//sampleStart
33
val numbers = listOf("one", "two", "three", "four")
4-
val reversedNumbers = numbers.asReversed()
5-
println(reversedNumbers)
4+
println("Sorted by length ascending: ${numbers.sortedWith(compareBy { it.length })}")
65
//sampleEnd
76
}

0 commit comments

Comments
 (0)