import junit.framework.TestCase; /** A JUnit test case class. * Every method starting with the word "test" will be called when running * the test with JUnit. */ public class BoolSimpTest extends TestCase { static String strForm1 = "(? T F false)"; // "false" is alternate syntax for "F" static String strForm2 = "(? true true true)"; // "true" is alternate syntax for "T" static String strForm3 = "(? X T T)"; static String strPOrNotP = "(? P T (? P F T))"; static IfForm simplify(IfForm f) { return f.apply(NormForm.ONLY).apply(EvalForm.ONLY); } /** A test method. * (Replace "X" with a name describing the test. You may write as * many "testSomething" methods in this class as you wish, and each * one will be called when running JUnit over this class.) */ public void testRead() throws java.io.IOException { IfForm f1 = new FormStream(strForm1).read(); IfForm f2 = new FormStream(strForm2).read(); IfForm f3 = new FormStream(strForm3).read(); IfForm f4 = new FormStream(strPOrNotP).read(); assertEquals(f2, new If(Constant.TRUE, Constant.TRUE, Constant.TRUE)); assertEquals(f1, new If(Constant.TRUE, Constant.FALSE, Constant.FALSE)); assertEquals(f3, new If(Variable.makeVariable("X"), Constant.TRUE, Constant.TRUE)); assertEquals(f4, new If(Variable.makeVariable("P"), Constant.TRUE, new If(Variable.makeVariable("P"), Constant.FALSE, Constant.TRUE))); assertEquals(simplify(f1), Constant.F); // F is synonymous with FALSE assertEquals(simplify(f2), Constant.TRUE); assertEquals(simplify(f3), Constant.T); // T is synonynous with TRUE assertEquals(simplify(f4), Constant.TRUE); } }