| 1 |
(******************************************************************************* |
|---|
| 2 |
Copyright 2008 Sun Microsystems, Inc., |
|---|
| 3 |
4150 Network Circle, Santa Clara, California 95054, U.S.A. |
|---|
| 4 |
All rights reserved. |
|---|
| 5 |
|
|---|
| 6 |
U.S. Government Rights - Commercial software. |
|---|
| 7 |
Government users are subject to the Sun Microsystems, Inc. standard |
|---|
| 8 |
license agreement and applicable provisions of the FAR and its supplements. |
|---|
| 9 |
|
|---|
| 10 |
Use is subject to license terms. |
|---|
| 11 |
|
|---|
| 12 |
This distribution may include materials developed by third parties. |
|---|
| 13 |
|
|---|
| 14 |
Sun, Sun Microsystems, the Sun logo and Java are trademarks or registered |
|---|
| 15 |
trademarks of Sun Microsystems, Inc. in the U.S. and other countries. |
|---|
| 16 |
******************************************************************************) |
|---|
| 17 |
|
|---|
| 18 |
component BooleanOps |
|---|
| 19 |
export Executable |
|---|
| 20 |
|
|---|
| 21 |
asseq(s:String,a:Boolean,b:Boolean,x:Boolean,y:Boolean): () = |
|---|
| 22 |
if a then |
|---|
| 23 |
if b then |
|---|
| 24 |
() |
|---|
| 25 |
else |
|---|
| 26 |
println("FAIL: " x s y " expected " a " got " b) |
|---|
| 27 |
end |
|---|
| 28 |
else |
|---|
| 29 |
if b then |
|---|
| 30 |
println("FAIL: " x s y " expected " a " got " b) |
|---|
| 31 |
else |
|---|
| 32 |
() |
|---|
| 33 |
end |
|---|
| 34 |
end |
|---|
| 35 |
|
|---|
| 36 |
binop(op:(Boolean,Boolean)->Boolean, |
|---|
| 37 |
s:String,tt:Boolean,tf:Boolean,ft:Boolean,ff:Boolean): () = do |
|---|
| 38 |
tt' = op(true, true) |
|---|
| 39 |
asseq(s,tt,tt',true,true) |
|---|
| 40 |
tf' = op(true, false) |
|---|
| 41 |
asseq(s,tf,tf',true,false) |
|---|
| 42 |
ft' = op(false, true) |
|---|
| 43 |
asseq(s,ft,ft',false,true) |
|---|
| 44 |
ff' = op(false, false) |
|---|
| 45 |
asseq(s,ff,ff',false,false) |
|---|
| 46 |
end |
|---|
| 47 |
|
|---|
| 48 |
run(args:String...):() = do |
|---|
| 49 |
binop(fn (a,b) => (a SEQV b)," SEQV ",true,false,false,true) |
|---|
| 50 |
binop(fn (a,b) => (a=b),"=",true,false,false,true) |
|---|
| 51 |
binop(fn (a,b) => (a<->b),"<->",true,false,false,true) |
|---|
| 52 |
binop(fn (a,b) => (a AND b)," AND ",true,false,false,false) |
|---|
| 53 |
binop(fn (a,b) => (a OR b)," OR ",true,true,true,false) |
|---|
| 54 |
binop(fn (a,b) => (a->b),"->",true,false,true,true) |
|---|
| 55 |
binop(fn (a,b) => (a<b),"<",false,false,true,false) |
|---|
| 56 |
binop(fn (a,b) => (a<=b),"<=",true,false,true,true) |
|---|
| 57 |
binop(fn (a,b) => (a>b),">",false,true,false,false) |
|---|
| 58 |
binop(fn (a,b) => (a>=b),">=",true,true,false,true) |
|---|
| 59 |
asseq("NOT",true,NOT false,true,false) |
|---|
| 60 |
asseq("NOT",false,NOT true,false,true) |
|---|
| 61 |
end |
|---|
| 62 |
|
|---|
| 63 |
end |
|---|