diff options
author | michelou <michelou@epfl.ch> | 2005-07-28 09:59:44 +0000 |
---|---|---|
committer | michelou <michelou@epfl.ch> | 2005-07-28 09:59:44 +0000 |
commit | 99aa6cd9ed8eac2791c4a592065da08315deb147 (patch) | |
tree | 183d1008a280af1472f7d2273df28bf511a4d8f5 /test | |
parent | 5f5d61e408722103bd87b90df67ad8a51e843efc (diff) | |
download | scala-99aa6cd9ed8eac2791c4a592065da08315deb147.tar.gz scala-99aa6cd9ed8eac2791c4a592065da08315deb147.tar.bz2 scala-99aa6cd9ed8eac2791c4a592065da08315deb147.zip |
*** empty log message ***
Diffstat (limited to 'test')
-rw-r--r-- | test/files/run/boolexprs.check | 3 | ||||
-rw-r--r-- | test/files/run/boolexprs.scala | 63 |
2 files changed, 66 insertions, 0 deletions
diff --git a/test/files/run/boolexprs.check b/test/files/run/boolexprs.check new file mode 100644 index 0000000000..cd2c735894 --- /dev/null +++ b/test/files/run/boolexprs.check @@ -0,0 +1,3 @@ +test Test1 was successful +test Test2 was successful + diff --git a/test/files/run/boolexprs.scala b/test/files/run/boolexprs.scala new file mode 100644 index 0000000000..b5bc5f7787 --- /dev/null +++ b/test/files/run/boolexprs.scala @@ -0,0 +1,63 @@ +//############################################################################ +// Boolean Expressions +//############################################################################ +// $Id$ + +class Counter { + private var n: Int = 0; + def incrThen(b: Boolean) = if (b) n = n + 1; + def value = n; +} + +object Test1 { + var flag = false; + def flip: boolean = { val tmp = flag; flag = !flag; tmp } + def run: Int = { + val c = new Counter; + c.incrThen(flip || flip); + c.value + } +} + +object Test2 { + val a = Array(false); + + def run: Int = { + val c = new Counter; + c.incrThen(true && a(0)); + c.incrThen(false || Nil.length > 0); + c.value + } +} + +//############################################################################ +// Test code + +object Test { + import java.lang.System; + + def check_success(name: String, closure: => Int, expected: Int): Unit = { + System.out.print("test " + name); + try { + val actual: Int = closure; + if (actual == expected) { + System.out.print(" was successful"); + } else { + System.out.print(" failed: expected "+ expected +", found "+ actual); + } + } catch { + case exception: Throwable => { + System.out.print(" raised exception " + exception); + } + } + System.out.println(); + } + + def main(args: Array[String]): Unit = { + check_success("Test1", Test1.run, 1); + check_success("Test2", Test2.run, 0); + System.out.println(); + } +} + +//############################################################################ |