1 package org.netbeans.apifest.boolcircuit;
3 import junit.framework.TestCase;
4 import junit.framework.*;
6 // BEGIN: apitest.day2.RealTest
7 /** This file contains the APIFest quest for day 2. Simply, turn the
8 * boolean circuit into circuit that can compute with double
11 * This means that where ever a boolean was used to represent input or
12 * output values, one can now use any double number from >= 0 and <= 1.
13 * Still, to support backward compatibility, the operations with booleans
14 * has to be kept available and have to work. In fact False shall be
15 * treated as 0 and True as 1.
17 * The basic elements has to be modified to work on doubles
18 * in the following way:
20 * <li>negation - neg(x) = 1 - x, this is correct extension as
21 * neg(false)=neg(0)=1-0=1=true
22 * <li>and - and(x,y) = x * y, again this is fine as
23 * and(true,true)=1*1=true and also
24 * and(false,true)=0*1=0=false
25 * <li>or - or(x,y) = 1 - (1 - x) * (1 - y) and this is also ok as
26 * or(false,false) = 1 - (1 - 0) * (1 - 0) = 1 - 1 = 0 = false
27 * or(true,false) = 1 - (1 - 1) * (1 - 0) = 1 - 0 * 1 = 1 = true
30 * However as the circuits with doubles are more rich than plain boolean
31 * circuits, there is additional requirement to allow any user of your API
32 * to write its own "element" type. This is all going to be exercise in
33 * the tests bellow which you are supposed to implement.
35 public class RealTest extends TestCase {
37 // your code shall run without any permissions
40 public RealTest(String testName) {
45 /** First of all create a circuit which will evaluate
46 * expression (X1 and X2) or not(x1). Hold the circuit
49 * Feed this circuit with x1=true, x2=false, assert result is false
51 * Feed the same circuit with x1=false, x2=true, assert result is true
53 * Feed the same circuit with x1=0.0, x2=1.0, assert result is 1.0
55 * Feed the same circuit with x1=0.5, x2=0.5, assert result is 0.625
57 * Feed the same circuit with x1=0.0, x2=2.0, make sure it
60 public void testX1andX2orNotX1() {
61 fail("testX1andX2orNotX1");
64 /** Ensure that one variable cannot be filled with two different values.
65 * Create a circuit for x1 and x1. Make sure that for any usage of your
66 * API that would not lead to x1 * x1 result, an exception is thrown.
67 * For example if there was a way to feed the circuit with two different
68 * values 0.3 and 0.5 an exception is thrown indicating that this is
69 * improper use of the circuit.
71 public void testImproperUseOfTheCircuit() {
72 fail("testImproperUseOfTheCircuit");
75 /** Write your own element type called "gte" that will have two
76 * inputs and one output.
77 * The output value will be 1 if x1 >= x2 and 0 otherwise.
80 * circuit for following expression: (x1 and not(x1)) gte x1
82 * Feed the circuit with 0.5 and verify the result is 0
84 * Feed the same circuit with 1 and verify the result is 0
86 * Feed the same circuit with 0 and verify the result is 1
88 public void testGreaterThanEqualElement() {
89 fail("testGreaterThanEqualElement");
92 // END: apitest.day2.RealTest