samples/apifest1/day3-intermezzo/pnejedly/against-stackbasedsolution/test/apifest/CircuitTest.java
author Jaroslav Tulach <jtulach@netbeans.org>
Sat, 14 Jun 2008 09:52:52 +0200
changeset 58 be49ca0fff33
parent 54 45b0d58e66ca
permissions -rw-r--r--
Rewriting the infrastructure to use shared common.xml
     1 package apifest;
     2 
     3 import java.util.Arrays;
     4 import java.util.Stack;
     5 import junit.framework.TestCase;
     6 import org.netbeans.apifest.boolcircuit.Circuit;
     7 import org.netbeans.apifest.boolcircuit.CircuitFactory;
     8 import org.netbeans.apifest.boolcircuit.Operation;
     9 
    10 
    11 /** Write a test that works with version from day A and fails with version B.
    12  */
    13 public class CircuitTest extends TestCase {
    14     public CircuitTest(String n) {
    15         super(n);
    16     }
    17     
    18     // no need to comment
    19 
    20     public void testSourceComp() throws Exception {
    21         Operation nand = new Operation() {
    22             public char evaluate(char i1, char i2) throws IllegalArgumentException {
    23                return i1 == '1' && i2 == '1' ? '0' : '1';
    24             }
    25         };
    26     }
    27 
    28     public void testSourceComp2() throws Exception {
    29         Operation nand = new Operation() {
    30             public char evaluate(char i1, char i2) throws IllegalArgumentException {
    31                 evaluate(1, 2);
    32                 return i1 == '1' && i2 == '1' ? '0' : '1';
    33             }
    34             // checker
    35             public char evaluate(double d1, double d2) {
    36                 return '1';
    37             }
    38         };
    39     }
    40     
    41     public void testBinaryComp() throws Exception {
    42         Operation nand = new Operation() {
    43             public char evaluate(char i1, char i2) throws IllegalArgumentException {
    44                return i1 == '1' && i2 == '1' ? '0' : '1';
    45             }
    46         };
    47         Circuit cir = CircuitFactory.getBasicCircuit(nand);
    48 
    49         Stack<Character> s = new Stack<Character> ();
    50         s.addAll(Arrays.asList('0', '1'));
    51         
    52         assertEquals('1', cir.evaluate(s));
    53     }
    54 
    55 }