Add more tests in uncommonCases folder

1) dataClass.kt - test with data class
2) receiver.kt - test with Int extension receiver
3) delegation.kt - test with implementation by delegation
This commit is contained in:
Ivan Cilcic
2019-08-28 16:42:15 +03:00
committed by Mikhail Glukhikh
parent b8ef09a157
commit 262f57d938
8 changed files with 198 additions and 0 deletions
@@ -0,0 +1,14 @@
data class Vector(val x: Int, val y: Int) {
fun plus(other: Vector): Vector = Vector(x + other.x, y + other.y)
}
fun main() {
val a = Vector(1, 2)
val b = Vector(-1, 10)
println("a = $a, b = ${b.toString()}")
println("a + b = " + (a + b))
println("a hash - ${a.hashCode()}")
println("a is equal to b ${a.equals(b)}")
}
@@ -0,0 +1,19 @@
interface Base {
fun printMessage()
fun printMessageLine()
}
class BaseImpl(val x: Int) : Base {
override fun printMessage() { print(x) }
override fun printMessageLine() { println(x) }
}
class Derived(b: Base) : Base by b {
override fun printMessage() { print("abc") }
}
fun main() {
val b = BaseImpl(10)
Derived(b).printMessage()
Derived(b).printMessageLine()
}
@@ -0,0 +1,12 @@
fun Int.addOne(): Int {
return this + 1
}
val Int.repeat: Int
get() = this
fun main() {
val i = 2
i.addOne()
val p = i.repeat * 2
}