jtulach@52: /* jtulach@52: * The contents of this file are subject to the terms of the Common Development jtulach@52: * and Distribution License (the License). You may not use this file except in jtulach@52: * compliance with the License. jtulach@52: * jtulach@52: * You can obtain a copy of the License at http://www.netbeans.org/cddl.html jtulach@52: * or http://www.netbeans.org/cddl.txt. jtulach@52: * jtulach@52: * When distributing Covered Code, include this CDDL Header Notice in each file jtulach@52: * and include the License file at http://www.netbeans.org/cddl.txt. jtulach@52: * If applicable, add the following below the CDDL Header, with the fields jtulach@52: * enclosed by brackets [] replaced by your own identifying information: jtulach@52: * "Portions Copyrighted [year] [name of copyright owner]" jtulach@52: * jtulach@52: * The Original Software is NetBeans. The Initial Developer of the Original jtulach@52: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun jtulach@52: * Microsystems, Inc. All Rights Reserved. jtulach@52: */ jtulach@52: jtulach@52: package org.netbeans.apifest.boolcircuit; jtulach@52: jtulach@52: import junit.framework.TestCase; jtulach@52: import junit.framework.*; jtulach@52: jtulach@52: /** The initial quest for this APIFest is to create an API for boolean jtulach@52: * circuits. Such API shall be able to compose a boolean circuit from jtulach@52: * basic elements and evaluate the result given initial values for jtulach@52: * input variables. jtulach@52: *

jtulach@52: * The basic elements include: jtulach@52: *

jtulach@52: * jtulach@52: *

jtulach@52: * The boolean circuit can be used to represent boolean formulas and compute jtulach@52: * the results for certain values of its inputs. The individual tasks described jtulach@52: * as tests bellow. jtulach@52: * jtulach@52: *

jtulach@52: * Links of interest: jtulach@52: *

jtulach@52: */ jtulach@52: public class CircuitTest extends TestCase { jtulach@52: static { jtulach@52: // your code shall run without any permissions jtulach@52: } jtulach@52: jtulach@52: Input inTrue; jtulach@52: Input inFalse; jtulach@52: public CircuitTest(String testName) { jtulach@52: super(testName); jtulach@52: } jtulach@52: jtulach@52: jtulach@52: /** jtulach@52: * Create a circuit to evaluate x1 and x2 and then jtulach@52: * verify that its result is false for input (false, true) and jtulach@52: * it is true for input (true, true). jtulach@52: */ jtulach@52: public void testX1andX2() { jtulach@52: inTrue = Factory.createSimpleBooleanInput(true); jtulach@52: inFalse = Factory.createSimpleBooleanInput(false); jtulach@52: Operation op1 = Factory.createAndOperation(inFalse, inTrue); jtulach@52: assertFalse(Circuit.evaluateBooleanOperation(op1)); jtulach@52: Operation op2 = Factory.createAndOperation(inTrue, inTrue); jtulach@52: assertTrue(Circuit.evaluateBooleanOperation(op2)); jtulach@52: } jtulach@52: jtulach@52: /** jtulach@52: * Create a circuit to evaluate (x1 and x2) or x3 and then jtulach@52: * verify that its result is false for input (false, true, false) and jtulach@52: * it is true for input (false, false, true). jtulach@52: */ jtulach@52: public void testX1andX2orX3() { jtulach@52: inTrue = Factory.createSimpleBooleanInput(true); jtulach@52: inFalse = Factory.createSimpleBooleanInput(false); jtulach@52: Operation op1 = Factory.createAndOperation(inFalse, inTrue); jtulach@132: Operation op2 = Factory.createOrOperation( jtulach@132: Factory.createOperationBasedBooleanInput(op1), inFalse jtulach@132: ); jtulach@52: assertFalse(Circuit.evaluateBooleanOperation(op2)); jtulach@52: jtulach@52: op1 = Factory.createAndOperation(inFalse, inFalse); jtulach@132: op2 = Factory.createOrOperation( jtulach@132: Factory.createOperationBasedBooleanInput(op1), inTrue jtulach@132: ); jtulach@52: assertTrue(Circuit.evaluateBooleanOperation(op2)); jtulach@52: } jtulach@52: /** jtulach@52: * Create a circuit to evaluate (x1 or not(x1)) and then jtulach@52: * verify that its result is true for all values of x1. jtulach@52: */ jtulach@52: public void testAlwaysTrue() { jtulach@52: inTrue = Factory.createSimpleBooleanInput(true); jtulach@52: inFalse = Factory.createSimpleBooleanInput(false); jtulach@52: Operation not = Factory.createNotOperation(inTrue); jtulach@132: Operation or = Factory.createOrOperation( jtulach@132: Factory.createOperationBasedBooleanInput(not), inTrue jtulach@132: ); jtulach@52: assertTrue(Circuit.evaluateBooleanOperation(or)); jtulach@52: not = Factory.createNotOperation(inFalse); jtulach@132: or = Factory.createOrOperation( jtulach@132: Factory.createOperationBasedBooleanInput(not), inFalse jtulach@132: ); jtulach@52: assertTrue(Circuit.evaluateBooleanOperation(or)); jtulach@52: } jtulach@52: jtulach@52: }