Files
swift-mirror/test/Interpreter/classes.swift
Joe Groff 637c4e8171 Fold Interpreter and Interpreter/SIL tests.
There is only SIL. No reason to keep a subdirectory around.

Swift SVN r6029
2013-07-05 23:11:44 +00:00

61 lines
1.1 KiB
Swift

// RUN: %swift -i %s | FileCheck %s
class Interval {
var lo, hi : Int
constructor(lo:Int, hi:Int) {
this.lo = lo
this.hi = hi
}
func show() {
println("[\(lo), \(hi)]")
}
static func like(lo:Int, hi:Int) -> Interval {
return Interval(lo, hi)
}
}
class OpenInterval : Interval {
constructor(lo:Int, hi:Int) {
super.constructor(lo, hi)
}
func show() {
println("(\(lo), \(hi))")
}
static func like(lo:Int, hi:Int) -> Interval {
return OpenInterval(lo, hi)
}
}
func +(a:Interval, b:Interval) -> Interval {
return Interval(a.lo + b.lo, a.hi + b.hi)
}
func -(a:Interval, b:Interval) -> Interval {
return Interval(a.lo - b.hi, a.hi - b.lo)
}
func [prefix] -(a:Interval) -> Interval {
return typeof(a).like(-a.hi, -a.lo)
}
// CHECK: [-2, -1]
(-Interval(1,2)).show()
// CHECK: [4, 6]
(Interval(1,2) + Interval(3,4)).show()
// CHECK: [1, 3]
(Interval(3,4) - Interval(1,2)).show()
// CHECK: (-1, 1)
(OpenInterval(-1,1)).show()
// CHECK: (-3, 2)
(-OpenInterval(-2,3)).show()
// CHECK: false
println(Interval(1,2) is OpenInterval)
// CHECK: true
println((OpenInterval(1,2) as Interval) is OpenInterval)