001package simplebdd.test;
002
003import simplebdd.bool.BoolPred;
004
005public class TestBool {
006        public static void main (String[] args) {
007                new TestBool().run ();
008        }
009
010        final BoolPred x;
011        final BoolPred y;
012        final BoolPred z;
013        TestBool () {
014                this.x = BoolPred.factory.buildVar ("x");
015                this.y = BoolPred.factory.buildVar ("y");
016                this.z = BoolPred.factory.buildVar ("z");
017        }
018
019        void runtest (String s, BoolPred p, boolean expectedValue) {
020                String trueString  = (expectedValue? "Good. " : "BAD!! ");
021                String falseString = (expectedValue? "BAD!! " : "Good. ");
022                if (p == BoolPred.T) {
023                        System.out.println
024                        (trueString + s + " is always true");
025                } else {
026                        System.out.println
027                        (falseString + s + " is sometimes false");
028                }
029        }
030
031        public void run () {
032                System.out.println (BoolPred.T);
033                System.out.println (BoolPred.functions.toGraphString(BoolPred.T));
034                System.out.println (x);
035                System.out.println (BoolPred.functions.toGraphString(x));
036                System.out.println (x.not());
037                System.out.println (BoolPred.functions.toGraphString(x.not()));
038                System.out.println (x.ite(y,z));
039                System.out.println (BoolPred.functions.toGraphString(x.ite(y,z)));
040                System.out.println ("(y ? z : x)");
041                System.out.println (BoolPred.functions.toGraphString(y.ite(z,x)));
042
043                System.out.println ("x xor y xor z");
044                System.out.println (BoolPred.functions.toGraphString(x.xor (y).xor (z)));
045                System.out.println ("x and x");
046                System.out.println (BoolPred.functions.toGraphString(x.and (x)));
047                System.out.println ("x or y");
048                System.out.println (BoolPred.functions.toGraphString(x.or (y)));
049                System.out.println ("y or x");
050                System.out.println (BoolPred.functions.toGraphString(y.or (x)));
051
052                runtest (x.and (y) + "iff" + y.and (x),
053                                x.and (y).iff (y.and (x)), true);
054                runtest ("", x.and (BoolPred.T).iff (x), true);
055                runtest ("", x.xor (y.xor (z)).iff (x.xor (y).xor (z)), true);
056        }
057
058}