fixed samples test
This commit is contained in:
1 parent
a0ecbfd334
commit
dc9885c218
4 files changed
+134
-14
No files matched your search
@@ -1,23 +1,23 @@
|
||||
// Sample: Operator Overloading in Lyng
|
||||
|
||||
class Vector(val x, val y) {
|
||||
class Vector<T>(val x: T, val y: T) {
|
||||
// Overload +
|
||||
fun plus(other) = Vector(x + other.x, y + other.y)
|
||||
fun plus(other: Vector<U>) = Vector(x + other.x, y + other.y)
|
||||
|
||||
// Overload -
|
||||
fun minus(other) = Vector(x - other.x, y - other.y)
|
||||
fun minus(other: Vector<U>) = Vector(x - other.x, y - other.y)
|
||||
|
||||
// Overload unary -
|
||||
fun negate() = Vector(-x, -y)
|
||||
|
||||
// Overload ==
|
||||
fun equals(other) {
|
||||
if (other is Vector) x == other.x && y == other.y
|
||||
if (other is Vector<U>) x == other.x && y == other.y
|
||||
else false
|
||||
}
|
||||
|
||||
// Overload * (scalar multiplication)
|
||||
fun mul(scalar) = Vector(x * scalar, y * scalar)
|
||||
fun mul(scalar: Int | Real) = Vector(x * scalar, y * scalar)
|
||||
|
||||
override fun toString() = "Vector(${x}, ${y})"
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@ fun findSumLimit(f) {
|
||||
println("limit reached after "+n+" rounds")
|
||||
break sum
|
||||
}
|
||||
n++
|
||||
}
|
||||
else {
|
||||
println("limit not reached")
|
||||
|
||||
Reference in new issue
Block a user