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