samples/apifest1/day2/welltestedsolution/test/org/netbeans/apifest/boolcircuit/RealTest.java
changeset 154 0fd5e9c500b9
parent 153 b5cbb797ec0a
     1.1 --- a/samples/apifest1/day2/welltestedsolution/test/org/netbeans/apifest/boolcircuit/RealTest.java	Sat Jun 14 09:58:08 2008 +0200
     1.2 +++ b/samples/apifest1/day2/welltestedsolution/test/org/netbeans/apifest/boolcircuit/RealTest.java	Sat Jun 14 09:58:11 2008 +0200
     1.3 @@ -1,37 +1,12 @@
     1.4 -/*
     1.5 - * The contents of this file are subject to the terms of the Common Development
     1.6 - * and Distribution License (the License). You may not use this file except in
     1.7 - * compliance with the License.
     1.8 - *
     1.9 - * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
    1.10 - * or http://www.netbeans.org/cddl.txt.
    1.11 - *
    1.12 - * When distributing Covered Code, include this CDDL Header Notice in each file
    1.13 - * and include the License file at http://www.netbeans.org/cddl.txt.
    1.14 - * If applicable, add the following below the CDDL Header, with the fields
    1.15 - * enclosed by brackets [] replaced by your own identifying information:
    1.16 - * "Portions Copyrighted [year] [name of copyright owner]"
    1.17 - *
    1.18 - * The Original Software is NetBeans. The Initial Developer of the Original
    1.19 - * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
    1.20 - * Microsystems, Inc. All Rights Reserved.
    1.21 - */
    1.22 -
    1.23  package org.netbeans.apifest.boolcircuit;
    1.24  
    1.25 -import java.security.CodeSource;
    1.26 -import java.security.Permission;
    1.27 -import java.security.PermissionCollection;
    1.28 -import java.security.Policy;
    1.29 -import java.util.Collection;
    1.30 -import java.util.Collections;
    1.31 -import java.util.Enumeration;
    1.32  import junit.framework.TestCase;
    1.33  import junit.framework.*;
    1.34  import org.netbeans.apifest.custom.Gte;
    1.35  
    1.36  /** This file contains the APIFest quest for day 2. Simply, turn the 
    1.37 - * boolean circuit into circuit that can compute with double values from 0 to 1.
    1.38 + * boolean circuit into circuit that can compute with double 
    1.39 + * values from 0 to 1.
    1.40   * <p>
    1.41   * This means that where ever a boolean was used to represent input or 
    1.42   * output values, one can now use any double number from >= 0 and <= 1.
    1.43 @@ -42,17 +17,15 @@
    1.44   * The basic elements has to be modified to work on doubles in the following
    1.45   * way:
    1.46   * <ul>
    1.47 - *   <li>negation - neg(x) = 1 - x, this is correct extension as neg(false)=neg(0)=1-0=1=true
    1.48 - *   <li>and - and(x,y) = x * y, again this is fine as and(true,true)=1*1=true and also
    1.49 - *             and(false,true)=0*1=0=false
    1.50 - *   <li>or - or(x,y) = 1 - (1 - x) * (1 - y) and this is also ok as
    1.51 - *             or(false,false) = 1 - (1 - 0) * (1 - 0) = 1 - 1 = 0 = false
    1.52 - *             or(true,false) = 1 - (1 - 1) * (1 - 0) = 1 - 0 * 1 = 1 = true
    1.53 + *   <li>negation - neg(x) = 1 - x
    1.54 + *   <li>and - and(x,y) = x * y
    1.55 + *   <li>or - or(x,y) = 1 - (1 - x) * (1 - y)
    1.56   * </ul>
    1.57   * <p>
    1.58 - * However as the circuits with doubles are more rich than plain boolean circuits,
    1.59 - * there is additional requirement to allow any user of your API to write its 
    1.60 - * own "element" type. This is all going to be exercise in the tests bellow
    1.61 + * However as the circuits with doubles are more rich than plain 
    1.62 + * boolean circuits, there is additional requirement to allow any user 
    1.63 + * of your API to write its own "element" type. This is all going to 
    1.64 + * be exercise in the tests bellow
    1.65   * which you are supposed to implement.
    1.66   */
    1.67  // BEGIN: apifest.day2.welltestedsolution.RealTest
    1.68 @@ -78,30 +51,33 @@
    1.69       *
    1.70       * Feed this circuit with x1=true, x2=false, assert result is false
    1.71       *
    1.72 -     * Feed the same circuit with x1=false, x2=true, assert result is true
    1.73 +     * Feed the same circuit with x1=false, x2=true, assert result is 
    1.74 +     * true
    1.75       *
    1.76       * Feed the same circuit with x1=0.0, x2=1.0, assert result is 1.0
    1.77       *
    1.78       * Feed the same circuit with x1=0.5, x2=0.5, assert result is 0.625
    1.79       *
    1.80 -     * Feed the same circuit with x1=0.0, x2=2.0, make sure it throws an exception
    1.81 +     * Feed the same circuit with x1=0.0, x2=2.0
    1.82 +     * , make sure it throws an exception
    1.83       */
    1.84      public void testX1andX2orNotX1() {
    1.85          Circuit c = Circuit.createOrCircuit(
    1.86 -                Circuit.createAndCircuit(Circuit.input(0), Circuit.input(1)),
    1.87 -                Circuit.createNotCircuit(Circuit.input(0))
    1.88 -                );
    1.89 +            Circuit.createAndCircuit(Circuit.input(0), 
    1.90 +            Circuit.input(1)),
    1.91 +            Circuit.createNotCircuit(Circuit.input(0))
    1.92 +        );
    1.93          assertFalse("true, false", c.evaluate(true, false));
    1.94          assertTrue("false, true", c.evaluate(false, true));
    1.95          assertEquals("0.0, 1.0", 1.0, c.evaluateFuzzy(0.0, 1.0), 0.0);
    1.96      }
    1.97      
    1.98 -    /** Ensure that one variable cannot be filled with two different values.
    1.99 -     * Create a circuit for x1 and x1. Make sure that for any usage of your
   1.100 -     * API that would not lead to x1 * x1 result, an exception is thrown.
   1.101 -     * For example if there was a way to feed the circuit with two different 
   1.102 -     * values 0.3 and 0.5 an exception is thrown indicating that this is 
   1.103 -     * improper use of the circuit.
   1.104 +    /** Ensure that one variable cannot be filled with two different 
   1.105 +     * values. Create a circuit for x1 and x1. Make sure that for any 
   1.106 +     * usage of your API that would not lead to x1 * x1 result, an 
   1.107 +     * exception is thrown. For example if there was a way to feed the 
   1.108 +     * circuit with two different values 0.3 and 0.5 an exception is 
   1.109 +     * thrown indicating that this is improper use of the circuit.
   1.110       */
   1.111      public void testImproperUseOfTheCircuit() {
   1.112          // does not apply
   1.113 @@ -130,7 +106,8 @@
   1.114          }
   1.115      }
   1.116      
   1.117 -    /** Write your own element type called "gte" that will have two inputs and one output.
   1.118 +    /** Write your own element type called "gte" that 
   1.119 +     * will have two inputs and one output.
   1.120       * The output value will be 1 if x1 >= x2 and 0 otherwise. 
   1.121       * 
   1.122       * Create 
   1.123 @@ -144,10 +121,10 @@
   1.124       */
   1.125      public void testGreaterThanEqualElement() {
   1.126          Circuit gte = new Gte(Circuit.createAndCircuit(
   1.127 -                                  Circuit.input(0),
   1.128 -                                  Circuit.createNotCircuit(Circuit.input(0))),
   1.129 -                              Circuit.input(0)
   1.130 -                          );
   1.131 +            Circuit.input(0),
   1.132 +            Circuit.createNotCircuit(Circuit.input(0))),
   1.133 +            Circuit.input(0)
   1.134 +        );
   1.135          assertEquals("0.5", 0.0, gte.evaluateFuzzy(0.5), 0.0);
   1.136          assertEquals("1.0", 0.0, gte.evaluateFuzzy(1.0), 0.0);
   1.137          assertEquals("0.0", 1.0, gte.evaluateFuzzy(0.0), 0.0);
   1.138 @@ -157,11 +134,11 @@
   1.139      public void testSilly() {
   1.140          // (x1 and not x2) or x3
   1.141          Circuit c = Circuit.createOrCircuit(
   1.142 -                              Circuit.createAndCircuit(
   1.143 -                                  null,
   1.144 -                                  Circuit.createNotCircuit(null)),
   1.145 -                              null
   1.146 -                          );
   1.147 +            Circuit.createAndCircuit(
   1.148 +            null,
   1.149 +            Circuit.createNotCircuit(null)),
   1.150 +            null
   1.151 +        );
   1.152          assertEquals("1 1 1", 1.0, c.evaluateFuzzy(1.0, 1.0, 1.0), 0.0);
   1.153          assertEquals("1 1 0", 0.0, c.evaluateFuzzy(1.0, 1.0, 0.0), 0.0);
   1.154          assertEquals("1 0 1", 1.0, c.evaluateFuzzy(1.0, 0.0, 1.0), 0.0);