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