samples/apifest1/day2/RealTest.java
author Jaroslav Tulach <jtulach@netbeans.org>
Sat, 14 Jun 2008 09:58:11 +0200
changeset 154 0fd5e9c500b9
parent 153 b5cbb797ec0a
permissions -rw-r--r--
Merge: Geertjan's changs up to 2000
     1 package org.netbeans.apifest.boolcircuit;
     2 
     3 import junit.framework.TestCase;
     4 import junit.framework.*;
     5 
     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 
     9  * values from 0 to 1.
    10  * <p>
    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.
    16  * <p>
    17  * The basic elements has to be modified to work on doubles
    18  * in the following way:
    19  * <ul>
    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
    28  * </ul>
    29  * <p>
    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.
    34  */
    35 public class RealTest extends TestCase {
    36     static {
    37         // your code shall run without any permissions
    38     }
    39     
    40     public RealTest(String testName) {
    41         super(testName);
    42     }
    43 
    44     
    45     /** First of all create a circuit which will evaluate
    46      * expression (X1 and X2) or not(x1). Hold the circuit
    47      * in some variable.
    48      *
    49      * Feed this circuit with x1=true, x2=false, assert result is false
    50      *
    51      * Feed the same circuit with x1=false, x2=true, assert result is 
    52      * true
    53      *
    54      * Feed the same circuit with x1=0.0, x2=1.0, assert result is 1.0
    55      *
    56      * Feed the same circuit with x1=0.5, x2=0.5, assert result is 0.625
    57      *
    58      * Feed the same circuit with x1=0.0, x2=2.0, make sure it 
    59      * throws an exception
    60      */
    61     public void testX1andX2orNotX1() {
    62         fail("testX1andX2orNotX1");
    63     }
    64     
    65     /** Ensure that one variable cannot be filled with two different 
    66      * values. Create a circuit for x1 and x1. Make sure that for any 
    67      * usage of your API that would not lead to x1 * x1 result, an 
    68      * exception is thrown. For example if there was a way to feed the 
    69      * circuit with two different values 0.3 and 0.5 an exception is 
    70      * thrown indicating that this is improper use of the circuit.
    71      */
    72     public void testImproperUseOfTheCircuit() {
    73         fail("testImproperUseOfTheCircuit");
    74     }
    75     
    76     /** Write your own element type called "gte" that will have two 
    77      * inputs and one output.
    78      * The output value will be 1 if x1 >= x2 and 0 otherwise. 
    79      * 
    80      * Create 
    81      * circuit for following expression: (x1 and not(x1)) gte x1
    82      *
    83      * Feed the circuit with 0.5 and verify the result is 0
    84      *
    85      * Feed the same circuit with 1 and verify the result is 0
    86      *
    87      * Feed the same circuit with 0 and verify the result is 1
    88      */
    89     public void testGreaterThanEqualElement() {
    90         fail("testGreaterThanEqualElement");
    91     }
    92 }
    93 // END: apitest.day2.RealTest
    94