From 99aa6cd9ed8eac2791c4a592065da08315deb147 Mon Sep 17 00:00:00 2001 From: michelou Date: Thu, 28 Jul 2005 09:59:44 +0000 Subject: *** empty log message *** --- test/files/run/boolexprs.check | 3 ++ test/files/run/boolexprs.scala | 63 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 test/files/run/boolexprs.check create mode 100644 test/files/run/boolexprs.scala (limited to 'test/files') 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(); + } +} + +//############################################################################ -- cgit v1.2.3