# HG changeset patch # User Jaroslav Tulach # Date 1213429967 -7200 # Node ID a0b47629aad8729da5f8944693ed073dd5bcea07 # Parent 4257f4cf226bee6df7e49776f9865481f35a7a05 Including solutions till day 2 diff -r 4257f4cf226b -r a0b47629aad8 samples/apifest1/day1/alwayscreatenewcircuit/nbproject/project.xml --- a/samples/apifest1/day1/alwayscreatenewcircuit/nbproject/project.xml Sat Jun 14 09:52:45 2008 +0200 +++ b/samples/apifest1/day1/alwayscreatenewcircuit/nbproject/project.xml Sat Jun 14 09:52:47 2008 +0200 @@ -3,7 +3,7 @@ org.netbeans.modules.java.j2seproject - alwayscreatenewcircuit + alwayscreatenewcircuit - day1 1.6.5 diff -r 4257f4cf226b -r a0b47629aad8 samples/apifest1/day1/elementbasedsolution/nbproject/build-impl.xml --- a/samples/apifest1/day1/elementbasedsolution/nbproject/build-impl.xml Sat Jun 14 09:52:45 2008 +0200 +++ b/samples/apifest1/day1/elementbasedsolution/nbproject/build-impl.xml Sat Jun 14 09:52:47 2008 +0200 @@ -18,32 +18,35 @@ - applet - cleanup ---> - - + --> + + + ====================== + INITIALIZATION SECTION + ====================== + --> - + + + - + - + + - + @@ -77,7 +80,10 @@ - + + + + @@ -90,12 +96,34 @@ + + + + + + + + + + + + + + + + + + + + + + - + Must set src.dir Must set test.src.dir Must set build.dir @@ -118,41 +146,70 @@ - - - - + + + + + + + - + + + + + + + + + + + + + + + - - - - - - - + + + + + + Must set javac.includes + + + + + + + + + - + + + - + - + + + - + @@ -163,11 +220,11 @@ - - - + + + - + @@ -175,24 +232,36 @@ - + - + - + + + + + + + + + + + + + + + - - + + - - - - + + @@ -200,7 +269,7 @@ - + @@ -209,17 +278,17 @@ - + - + - + @@ -228,102 +297,102 @@ - + - + - - + =================== + COMPILATION SECTION + =================== + --> + + - + + + + - + - + - + Must select some files in the IDE or set javac.includes - - - - - + + - + - - + ==================== + JAR BUILDING SECTION + ==================== + --> + + - + - + - + To run this application from the command line without Ant, try: - - + + java -cp "${run.classpath.with.dist.jar}" ${main.class} - - + + - + - - + + @@ -331,183 +400,194 @@ To run this application from the command line without Ant, try: - + java -jar "${dist.jar.resolved}" - + - + ================= + EXECUTION SECTION + ================= + --> + - + + + + Must select one file in the IDE or set run.class - + ================= + DEBUGGING SECTION + ================= + --> + - + - - + + - - + + Must select one file in the IDE or set debug.class - - + + Must set fix.includes - + - + - + =============== + JAVADOC SECTION + =============== + --> + - + - - - - - + + + - + - + - + ========================= + JUNIT COMPILATION SECTION + ========================= + --> + - - + + + + + - + - + - + Must select some files in the IDE or set javac.includes - - - - - + + - + - + - + ======================= + JUNIT EXECUTION SECTION + ======================= + --> + - - + + - + Some tests failed; see details above. - - - - + + + + - + Must select some files in the IDE or set test.includes - + - + Some tests failed; see details above. - + - + ======================= + JUNIT DEBUGGING SECTION + ======================= + --> + Must select one file in the IDE or set test.class - + + + + - + + + + + + + + - - + + - - + + - + - + ========================= + APPLET EXECUTION SECTION + ========================= + --> + Must select one file in the IDE or set applet.url @@ -516,11 +596,11 @@ - + ========================= + APPLET DEBUGGING SECTION + ========================= + --> + Must select one file in the IDE or set applet.url @@ -528,14 +608,14 @@ - + - - + =============== + CLEANUP SECTION + =============== + --> + + @@ -543,5 +623,5 @@ - + diff -r 4257f4cf226b -r a0b47629aad8 samples/apifest1/day1/elementbasedsolution/nbproject/genfiles.properties --- a/samples/apifest1/day1/elementbasedsolution/nbproject/genfiles.properties Sat Jun 14 09:52:45 2008 +0200 +++ b/samples/apifest1/day1/elementbasedsolution/nbproject/genfiles.properties Sat Jun 14 09:52:47 2008 +0200 @@ -1,8 +1,8 @@ build.xml.data.CRC32=3856b393 build.xml.script.CRC32=5c47136e -build.xml.stylesheet.CRC32=a12b3d02 +build.xml.stylesheet.CRC32=be360661 # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. nbproject/build-impl.xml.data.CRC32=3856b393 -nbproject/build-impl.xml.script.CRC32=6771a052 -nbproject/build-impl.xml.stylesheet.CRC32=c10f1eac +nbproject/build-impl.xml.script.CRC32=3552e577 +nbproject/build-impl.xml.stylesheet.CRC32=f1d9da08 diff -r 4257f4cf226b -r a0b47629aad8 samples/apifest1/day1/elementbasedsolution/nbproject/project.properties --- a/samples/apifest1/day1/elementbasedsolution/nbproject/project.properties Sat Jun 14 09:52:45 2008 +0200 +++ b/samples/apifest1/day1/elementbasedsolution/nbproject/project.properties Sat Jun 14 09:52:47 2008 +0200 @@ -15,6 +15,8 @@ dist.dir=dist dist.jar=${dist.dir}/boolcircuit.jar dist.javadoc.dir=${dist.dir}/javadoc +excludes= +includes=** jar.compress=false javac.classpath= # Space-separated list of extra javac options diff -r 4257f4cf226b -r a0b47629aad8 samples/apifest1/day1/elementbasedsolution/src/org/netbeans/apifest/boolcircuit/Circuit.java --- a/samples/apifest1/day1/elementbasedsolution/src/org/netbeans/apifest/boolcircuit/Circuit.java Sat Jun 14 09:52:45 2008 +0200 +++ b/samples/apifest1/day1/elementbasedsolution/src/org/netbeans/apifest/boolcircuit/Circuit.java Sat Jun 14 09:52:47 2008 +0200 @@ -21,6 +21,7 @@ /** */ +// BEGIN: apifest.day1.elementbasedsolution.Circuit public final class Circuit { private Circuit() { } @@ -71,3 +72,4 @@ } } } +// END: apifest.day1.elementbasedsolution.Circuit diff -r 4257f4cf226b -r a0b47629aad8 samples/apifest1/day1/subclassingsolution/nbproject/build-impl.xml --- a/samples/apifest1/day1/subclassingsolution/nbproject/build-impl.xml Sat Jun 14 09:52:45 2008 +0200 +++ b/samples/apifest1/day1/subclassingsolution/nbproject/build-impl.xml Sat Jun 14 09:52:47 2008 +0200 @@ -18,32 +18,35 @@ - applet - cleanup ---> - - + --> + + + ====================== + INITIALIZATION SECTION + ====================== + --> - + + + - + - + + - + @@ -77,7 +80,10 @@ - + + + + @@ -90,12 +96,34 @@ + + + + + + + + + + + + + + + + + + + + + + - + Must set src.dir Must set test.src.dir Must set build.dir @@ -118,41 +146,70 @@ - - - - + + + + + + + - + + + + + + + + + + + + + + + - - - - - - - + + + + + + Must set javac.includes + + + + + + + + + - + + + - + - + + + - + @@ -163,11 +220,11 @@ - - - + + + - + @@ -175,24 +232,36 @@ - + - + - + + + + + + + + + + + + + + + - - + + - - - - + + @@ -200,7 +269,7 @@ - + @@ -209,17 +278,17 @@ - + - + - + @@ -228,102 +297,102 @@ - + - + - - + =================== + COMPILATION SECTION + =================== + --> + + - + + + + - + - + - + Must select some files in the IDE or set javac.includes - - - - - + + - + - - + ==================== + JAR BUILDING SECTION + ==================== + --> + + - + - + - + To run this application from the command line without Ant, try: - - + + java -cp "${run.classpath.with.dist.jar}" ${main.class} - - + + - + - - + + @@ -331,183 +400,194 @@ To run this application from the command line without Ant, try: - + java -jar "${dist.jar.resolved}" - + - + ================= + EXECUTION SECTION + ================= + --> + - + + + + Must select one file in the IDE or set run.class - + ================= + DEBUGGING SECTION + ================= + --> + - + - - + + - - + + Must select one file in the IDE or set debug.class - - + + Must set fix.includes - + - + - + =============== + JAVADOC SECTION + =============== + --> + - + - - - - - + + + - + - + - + ========================= + JUNIT COMPILATION SECTION + ========================= + --> + - - + + + + + - + - + - + Must select some files in the IDE or set javac.includes - - - - - + + - + - + - + ======================= + JUNIT EXECUTION SECTION + ======================= + --> + - - + + - + Some tests failed; see details above. - - - - + + + + - + Must select some files in the IDE or set test.includes - + - + Some tests failed; see details above. - + - + ======================= + JUNIT DEBUGGING SECTION + ======================= + --> + Must select one file in the IDE or set test.class - + + + + - + + + + + + + + - - + + - - + + - + - + ========================= + APPLET EXECUTION SECTION + ========================= + --> + Must select one file in the IDE or set applet.url @@ -516,11 +596,11 @@ - + ========================= + APPLET DEBUGGING SECTION + ========================= + --> + Must select one file in the IDE or set applet.url @@ -528,14 +608,14 @@ - + - - + =============== + CLEANUP SECTION + =============== + --> + + @@ -543,5 +623,5 @@ - + diff -r 4257f4cf226b -r a0b47629aad8 samples/apifest1/day1/subclassingsolution/nbproject/genfiles.properties --- a/samples/apifest1/day1/subclassingsolution/nbproject/genfiles.properties Sat Jun 14 09:52:45 2008 +0200 +++ b/samples/apifest1/day1/subclassingsolution/nbproject/genfiles.properties Sat Jun 14 09:52:47 2008 +0200 @@ -4,5 +4,5 @@ # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. nbproject/build-impl.xml.data.CRC32=0f6dc18a -nbproject/build-impl.xml.script.CRC32=079f4b62 -nbproject/build-impl.xml.stylesheet.CRC32=c10f1eac +nbproject/build-impl.xml.script.CRC32=fde9979b +nbproject/build-impl.xml.stylesheet.CRC32=f1d9da08 diff -r 4257f4cf226b -r a0b47629aad8 samples/apifest1/day1/subclassingsolution/nbproject/project.properties --- a/samples/apifest1/day1/subclassingsolution/nbproject/project.properties Sat Jun 14 09:52:45 2008 +0200 +++ b/samples/apifest1/day1/subclassingsolution/nbproject/project.properties Sat Jun 14 09:52:47 2008 +0200 @@ -15,6 +15,8 @@ dist.dir=dist dist.jar=${dist.dir}/boolcircuit.jar dist.javadoc.dir=${dist.dir}/javadoc +excludes= +includes=** jar.compress=false javac.classpath= # Space-separated list of extra javac options diff -r 4257f4cf226b -r a0b47629aad8 samples/apifest1/day1/subclassingsolution/src/org/netbeans/apifest/boolcircuit/Circuit.java --- a/samples/apifest1/day1/subclassingsolution/src/org/netbeans/apifest/boolcircuit/Circuit.java Sat Jun 14 09:52:45 2008 +0200 +++ b/samples/apifest1/day1/subclassingsolution/src/org/netbeans/apifest/boolcircuit/Circuit.java Sat Jun 14 09:52:47 2008 +0200 @@ -20,6 +20,7 @@ package org.netbeans.apifest.boolcircuit; +// BEGIN: apifest.day1.subclassingsolution /** Usefull class for building your own circuits. * */ @@ -68,3 +69,6 @@ public abstract boolean evaluate(boolean... in); } +// END: apifest.day1.subclassingsolution + + diff -r 4257f4cf226b -r a0b47629aad8 samples/apifest1/day2/RealTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/apifest1/day2/RealTest.java Sat Jun 14 09:52:47 2008 +0200 @@ -0,0 +1,114 @@ +/* + * The contents of this file are subject to the terms of the Common Development + * and Distribution License (the License). You may not use this file except in + * compliance with the License. + * + * You can obtain a copy of the License at http://www.netbeans.org/cddl.html + * or http://www.netbeans.org/cddl.txt. + * + * When distributing Covered Code, include this CDDL Header Notice in each file + * and include the License file at http://www.netbeans.org/cddl.txt. + * If applicable, add the following below the CDDL Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun + * Microsystems, Inc. All Rights Reserved. + */ + +package org.netbeans.apifest.boolcircuit; + +import java.security.CodeSource; +import java.security.Permission; +import java.security.PermissionCollection; +import java.security.Policy; +import java.util.Collection; +import java.util.Collections; +import java.util.Enumeration; +import junit.framework.TestCase; +import junit.framework.*; + +// BEGIN: apitest.day2.RealTest +/** This file contains the APIFest quest for day 2. Simply, turn the + * boolean circuit into circuit that can compute with double values from 0 to 1. + *

+ * This means that where ever a boolean was used to represent input or + * output values, one can now use any double number from >= 0 and <= 1. + * Still, to support backward compatibility, the operations with booleans + * has to be kept available and have to work. In fact False shall be + * treated as 0 and True as 1. + *

+ * The basic elements has to be modified to work on doubles in the following + * way: + *

    + *
  • negation - neg(x) = 1 - x, this is correct extension as neg(false)=neg(0)=1-0=1=true + *
  • and - and(x,y) = x * y, again this is fine as and(true,true)=1*1=true and also + * and(false,true)=0*1=0=false + *
  • or - or(x,y) = 1 - (1 - x) * (1 - y) and this is also ok as + * or(false,false) = 1 - (1 - 0) * (1 - 0) = 1 - 1 = 0 = false + * or(true,false) = 1 - (1 - 1) * (1 - 0) = 1 - 0 * 1 = 1 = true + *
+ *

+ * However as the circuits with doubles are more rich than plain boolean circuits, + * there is additional requirement to allow any user of your API to write its + * own "element" type. This is all going to be exercise in the tests bellow + * which you are supposed to implement. + */ +public class RealTest extends TestCase { + static { + // your code shall run without any permissions + } + + public RealTest(String testName) { + super(testName); + } + + + /** First of all create a circuit which will evaluate + * expression (X1 and X2) or not(x1). Hold the circuit + * in some variable. + * + * Feed this circuit with x1=true, x2=false, assert result is false + * + * Feed the same circuit with x1=false, x2=true, assert result is true + * + * Feed the same circuit with x1=0.0, x2=1.0, assert result is 1.0 + * + * Feed the same circuit with x1=0.5, x2=0.5, assert result is 0.625 + * + * Feed the same circuit with x1=0.0, x2=2.0, make sure it throws an exception + */ + public void testX1andX2orNotX1() { + fail("testX1andX2orNotX1"); + } + + /** Ensure that one variable cannot be filled with two different values. + * Create a circuit for x1 and x1. Make sure that for any usage of your + * API that would not lead to x1 * x1 result, an exception is thrown. + * For example if there was a way to feed the circuit with two different + * values 0.3 and 0.5 an exception is thrown indicating that this is + * improper use of the circuit. + */ + public void testImproperUseOfTheCircuit() { + fail("testImproperUseOfTheCircuit"); + } + + /** Write your own element type called "gte" that will have two inputs and one output. + * The output value will be 1 if x1 >= x2 and 0 otherwise. + * + * Create + * circuit for following expression: (x1 and not(x1)) gte x1 + * + * Feed the circuit with 0.5 and verify the result is 0 + * + * Feed the same circuit with 1 and verify the result is 0 + * + * Feed the same circuit with 0 and verify the result is 1 + */ + public void testGreaterThanEqualElement() { + fail("testGreaterThanEqualElement"); + } +} +// END: apitest.day2.RealTest + diff -r 4257f4cf226b -r a0b47629aad8 samples/apifest1/day2/alwayscreatenewcircuit/nbproject/build-impl.xml --- a/samples/apifest1/day2/alwayscreatenewcircuit/nbproject/build-impl.xml Sat Jun 14 09:52:45 2008 +0200 +++ b/samples/apifest1/day2/alwayscreatenewcircuit/nbproject/build-impl.xml Sat Jun 14 09:52:47 2008 +0200 @@ -18,32 +18,35 @@ - applet - cleanup ---> - - + --> + + + ====================== + INITIALIZATION SECTION + ====================== + --> - + + + - + - + + - + @@ -77,7 +80,10 @@ - + + + + @@ -90,12 +96,34 @@ + + + + + + + + + + + + + + + + + + + + + + - + Must set src.dir Must set test.src.dir Must set build.dir @@ -118,41 +146,70 @@ - - - - + + + + + + + - + + + + + + + + + + + + + + + - - - - - - - + + + + + + Must set javac.includes + + + + + + + + + - + + + - + - + + + - + @@ -163,11 +220,11 @@ - - - + + + - + @@ -175,24 +232,36 @@ - + - + - + + + + + + + + + + + + + + + - - + + - - - - + + @@ -200,7 +269,7 @@ - + @@ -209,17 +278,17 @@ - + - + - + @@ -228,102 +297,102 @@ - + - + - - + =================== + COMPILATION SECTION + =================== + --> + + - + + + + - + - + - + Must select some files in the IDE or set javac.includes - - - - - + + - + - - + ==================== + JAR BUILDING SECTION + ==================== + --> + + - + - + - + To run this application from the command line without Ant, try: - - + + java -cp "${run.classpath.with.dist.jar}" ${main.class} - - + + - + - - + + @@ -331,183 +400,194 @@ To run this application from the command line without Ant, try: - + java -jar "${dist.jar.resolved}" - + - + ================= + EXECUTION SECTION + ================= + --> + - + + + + Must select one file in the IDE or set run.class - + ================= + DEBUGGING SECTION + ================= + --> + - + - - + + - - + + Must select one file in the IDE or set debug.class - - + + Must set fix.includes - + - + - + =============== + JAVADOC SECTION + =============== + --> + - + - - - - - + + + - + - + - + ========================= + JUNIT COMPILATION SECTION + ========================= + --> + - - + + + + + - + - + - + Must select some files in the IDE or set javac.includes - - - - - + + - + - + - + ======================= + JUNIT EXECUTION SECTION + ======================= + --> + - - + + - + Some tests failed; see details above. - - - - + + + + - + Must select some files in the IDE or set test.includes - + - + Some tests failed; see details above. - + - + ======================= + JUNIT DEBUGGING SECTION + ======================= + --> + Must select one file in the IDE or set test.class - + + + + - + + + + + + + + - - + + - - + + - + - + ========================= + APPLET EXECUTION SECTION + ========================= + --> + Must select one file in the IDE or set applet.url @@ -516,11 +596,11 @@ - + ========================= + APPLET DEBUGGING SECTION + ========================= + --> + Must select one file in the IDE or set applet.url @@ -528,14 +608,14 @@ - + - - + =============== + CLEANUP SECTION + =============== + --> + + @@ -543,5 +623,5 @@ - + diff -r 4257f4cf226b -r a0b47629aad8 samples/apifest1/day2/alwayscreatenewcircuit/nbproject/genfiles.properties --- a/samples/apifest1/day2/alwayscreatenewcircuit/nbproject/genfiles.properties Sat Jun 14 09:52:45 2008 +0200 +++ b/samples/apifest1/day2/alwayscreatenewcircuit/nbproject/genfiles.properties Sat Jun 14 09:52:47 2008 +0200 @@ -1,8 +1,8 @@ build.xml.data.CRC32=ffd6778c build.xml.script.CRC32=f0487089 -build.xml.stylesheet.CRC32=a12b3d02 +build.xml.stylesheet.CRC32=be360661 # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. nbproject/build-impl.xml.data.CRC32=ffd6778c -nbproject/build-impl.xml.script.CRC32=20ec1204 -nbproject/build-impl.xml.stylesheet.CRC32=c10f1eac +nbproject/build-impl.xml.script.CRC32=d54dcd8c +nbproject/build-impl.xml.stylesheet.CRC32=f1d9da08 diff -r 4257f4cf226b -r a0b47629aad8 samples/apifest1/day2/alwayscreatenewcircuit/nbproject/project.properties --- a/samples/apifest1/day2/alwayscreatenewcircuit/nbproject/project.properties Sat Jun 14 09:52:45 2008 +0200 +++ b/samples/apifest1/day2/alwayscreatenewcircuit/nbproject/project.properties Sat Jun 14 09:52:47 2008 +0200 @@ -15,6 +15,8 @@ dist.dir=dist dist.jar=${dist.dir}/boolcircuit.jar dist.javadoc.dir=${dist.dir}/javadoc +excludes= +includes=** jar.compress=false javac.classpath= # Space-separated list of extra javac options diff -r 4257f4cf226b -r a0b47629aad8 samples/apifest1/day2/alwayscreatenewcircuit/nbproject/project.xml --- a/samples/apifest1/day2/alwayscreatenewcircuit/nbproject/project.xml Sat Jun 14 09:52:45 2008 +0200 +++ b/samples/apifest1/day2/alwayscreatenewcircuit/nbproject/project.xml Sat Jun 14 09:52:47 2008 +0200 @@ -3,7 +3,7 @@ org.netbeans.modules.java.j2seproject - alwayscreatenewcircuit + alwayscreatenewcircuit - day2 1.6.5