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@132
|
8 |
* boolean circuit into circuit that can compute with double
|
jtulach@132
|
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@132
|
17 |
* The basic elements has to be modified to work on doubles
|
jtulach@132
|
18 |
* in the following way:
|
jtulach@53
|
19 |
* <ul>
|
jtulach@132
|
20 |
* <li>negation - neg(x) = 1 - x, this is correct extension as
|
jtulach@132
|
21 |
* neg(false)=neg(0)=1-0=1=true
|
jtulach@132
|
22 |
* <li>and - and(x,y) = x * y, again this is fine as
|
jtulach@132
|
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@132
|
26 |
* or(false,false) = 1 - (1 - 0) * (1 - 0) = 1 - 1 = 0 = false
|
jtulach@132
|
27 |
* or(true,false) = 1 - (1 - 1) * (1 - 0) = 1 - 0 * 1 = 1 = true
|
jtulach@53
|
28 |
* </ul>
|
jtulach@53
|
29 |
* <p>
|
jtulach@132
|
30 |
* However as the circuits with doubles are more rich than plain boolean
|
jtulach@132
|
31 |
* circuits, there is additional requirement to allow any user of your API
|
jtulach@132
|
32 |
* to write its own "element" type. This is all going to be exercise in
|
jtulach@132
|
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@53
|
51 |
* Feed the same circuit with x1=false, x2=true, assert result is true
|
jtulach@53
|
52 |
*
|
jtulach@53
|
53 |
* Feed the same circuit with x1=0.0, x2=1.0, assert result is 1.0
|
jtulach@53
|
54 |
*
|
jtulach@53
|
55 |
* Feed the same circuit with x1=0.5, x2=0.5, assert result is 0.625
|
jtulach@53
|
56 |
*
|
jtulach@132
|
57 |
* Feed the same circuit with x1=0.0, x2=2.0, make sure it
|
jtulach@132
|
58 |
* throws an exception
|
jtulach@53
|
59 |
*/
|
jtulach@53
|
60 |
public void testX1andX2orNotX1() {
|
jtulach@53
|
61 |
fail("testX1andX2orNotX1");
|
jtulach@53
|
62 |
}
|
jtulach@53
|
63 |
|
jtulach@53
|
64 |
/** Ensure that one variable cannot be filled with two different values.
|
jtulach@53
|
65 |
* Create a circuit for x1 and x1. Make sure that for any usage of your
|
jtulach@53
|
66 |
* API that would not lead to x1 * x1 result, an exception is thrown.
|
jtulach@53
|
67 |
* For example if there was a way to feed the circuit with two different
|
jtulach@53
|
68 |
* values 0.3 and 0.5 an exception is thrown indicating that this is
|
jtulach@53
|
69 |
* improper use of the circuit.
|
jtulach@53
|
70 |
*/
|
jtulach@53
|
71 |
public void testImproperUseOfTheCircuit() {
|
jtulach@53
|
72 |
fail("testImproperUseOfTheCircuit");
|
jtulach@53
|
73 |
}
|
jtulach@53
|
74 |
|
jtulach@132
|
75 |
/** Write your own element type called "gte" that will have two
|
jtulach@132
|
76 |
* inputs and one output.
|
jtulach@53
|
77 |
* The output value will be 1 if x1 >= x2 and 0 otherwise.
|
jtulach@53
|
78 |
*
|
jtulach@53
|
79 |
* Create
|
jtulach@53
|
80 |
* circuit for following expression: (x1 and not(x1)) gte x1
|
jtulach@53
|
81 |
*
|
jtulach@53
|
82 |
* Feed the circuit with 0.5 and verify the result is 0
|
jtulach@53
|
83 |
*
|
jtulach@53
|
84 |
* Feed the same circuit with 1 and verify the result is 0
|
jtulach@53
|
85 |
*
|
jtulach@53
|
86 |
* Feed the same circuit with 0 and verify the result is 1
|
jtulach@53
|
87 |
*/
|
jtulach@53
|
88 |
public void testGreaterThanEqualElement() {
|
jtulach@53
|
89 |
fail("testGreaterThanEqualElement");
|
jtulach@53
|
90 |
}
|
jtulach@53
|
91 |
}
|
jtulach@53
|
92 |
// END: apitest.day2.RealTest
|
jtulach@53
|
93 |
|