samples/apifest1/day2/RealTest.java
author Jaroslav Tulach <jtulach@netbeans.org>
Sat, 14 Jun 2008 09:56:12 +0200
changeset 132 3bc4c54f4bcc
parent 53 a0b47629aad8
child 133 50bf1b976c0d
permissions -rw-r--r--
Truncating all examples to 80 characters per line
     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 true
    52      *
    53      * Feed the same circuit with x1=0.0, x2=1.0, assert result is 1.0
    54      *
    55      * Feed the same circuit with x1=0.5, x2=0.5, assert result is 0.625
    56      *
    57      * Feed the same circuit with x1=0.0, x2=2.0, make sure it 
    58      * throws an exception
    59      */
    60     public void testX1andX2orNotX1() {
    61         fail("testX1andX2orNotX1");
    62     }
    63     
    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.
    70      */
    71     public void testImproperUseOfTheCircuit() {
    72         fail("testImproperUseOfTheCircuit");
    73     }
    74     
    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. 
    78      * 
    79      * Create 
    80      * circuit for following expression: (x1 and not(x1)) gte x1
    81      *
    82      * Feed the circuit with 0.5 and verify the result is 0
    83      *
    84      * Feed the same circuit with 1 and verify the result is 0
    85      *
    86      * Feed the same circuit with 0 and verify the result is 1
    87      */
    88     public void testGreaterThanEqualElement() {
    89         fail("testGreaterThanEqualElement");
    90     }
    91 }
    92 // END: apitest.day2.RealTest
    93