import org.junit.Test; import static org.junit.Assert.assertEquals; /** * The test class StudentTest -- it tests the Student class * * @author Phill Conrad, and (insert your name here) * @version lab04 for CS56, Winter 2011 * @see Student */ public class BooleanExpressionTest { /** tests for boolean literals TODO split into multiple tests */ @Test public void testBooleanLiteral() { // set up a student with the constructor, and // then make sure that the getters retrieve the // values that we expect the new object to have BooleanLiteral blt = new BooleanLiteral(true); assertEquals(true,blt.getValue()); assertEquals("T",blt.toString()); BooleanLiteral blf = new BooleanLiteral(false); assertEquals(false,blf.getValue()); assertEquals("F",blt.toString()); } @Test public void testBooleanVariable01() { BooleanVariable bvp = new BooleanVariable('p',true); assertEquals(true,bvp.getValue()); assertEquals("p",bvp.toString()); } @Test public void testBooleanVariableDefaultTrue() { // Test that the default value of a new variable is true BooleanVariable bvp = new BooleanVariable('q'); assertEquals(true,bvp.getValue()); assertEquals("q",bvp.toString()); } @Test public void testBooleanVariableSecondReferenceIsSameAsFirst() { // Test that the default value of a new variable is true BooleanVariable r1 = new BooleanVariable('r',true); BooleanVariable r2 = new BooleanVariable('r'); assertEquals(true,r1.getValue()); assertEquals(true,r2.getValue()); assertEquals("r",r1.toString()); assertEquals("r",r2.toString()); } @Test public void testNegatedBooleanExpression() { // Test that the default value of a new variable is true BooleanVariable s = new BooleanVariable('s',true); BooleanExpression notS = new NegatedBooleanExpression(s); BooleanExpression notNotS = new NegatedBooleanExpression(notS); assertEquals(true,s.getValue()); assertEquals(false,notS.getValue()); assertEquals(true,notNotS.getValue()); assertEquals("s",s.toString()); assertEquals("!(s)",notS.toString()); assertEquals("!(!(s))",notNotS.toString()); } @Test public void testBinaryBooleanExpression() { // Test that the default value of a new variable is true BooleanVariable a = new BooleanVariable('a',true); BooleanVariable b = new BooleanVariable('b',false); BooleanExpression aAndB = new BinaryBooleanExpression(a,'^',b); BooleanExpression aOrB = new BinaryBooleanExpression(a,'v',b); BooleanExpression aAndBImplies_aOrB = new BinaryBooleanExpression(aAndB,'>',aOrB); // @@@ TODO Make asserts for the proper values assertEquals("((a ^ b) > (a v b))",aAndBImplies_aOrB.toString()); } }