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: public CircuitTest(String testName) { jtulach@52: super(testName); jtulach@52: } jtulach@52: jtulach@52: // BEGIN: apifest.day1.pinbasedsolution.CircuitTest 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() throws Exception { jtulach@52: Circuit c = Circuit.construct( jtulach@52: Element.createAnd( jtulach@52: Element.createInput(0), jtulach@52: Element.createInput(1) jtulach@52: ) jtulach@52: ); jtulach@52: jtulach@52: assertFalse ("false AND true is false", c.evaluate(false, true)); jtulach@52: assertTrue ("true AND true is true", c.evaluate(true, true)); 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() throws Exception { jtulach@52: Circuit c = Circuit.construct( jtulach@52: Element.createOr( jtulach@52: Element.createAnd( jtulach@52: Element.createInput(0), jtulach@52: Element.createInput(1) jtulach@52: ), jtulach@52: Element.createInput(2) jtulach@52: ) jtulach@52: ); jtulach@52: jtulach@132: assertFalse ( jtulach@132: "(false AND true) OR false is false", jtulach@132: c.evaluate(false, true, false) jtulach@132: ); jtulach@132: assertTrue ( jtulach@132: "(false AND false) OR true is true", jtulach@132: c.evaluate(false, false, true) jtulach@132: ); jtulach@52: } 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() throws Exception { jtulach@52: Circuit c = Circuit.construct( jtulach@52: Element.createOr( jtulach@52: Element.createInput(0), jtulach@52: Element.createNot(Element.createInput(0)) jtulach@52: ) jtulach@52: ); jtulach@52: jtulach@52: assertTrue ("tautology is true", c.evaluate(false)); jtulach@52: assertTrue ("tautology is true", c.evaluate(true)); jtulach@52: } jtulach@52: // END: apifest.day1.pinbasedsolution.CircuitTest jtulach@52: }