mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-19 01:44:44 -04:00
fixed a bug in the test executor
This commit is contained in:
parent
bd19b80578
commit
4bc24f68ee
@ -94,8 +94,8 @@ public class FlipFlopsTest extends TestCase {
|
||||
nor4.setInputs(ovs(a4.getOutput(), nor3.getOutput()));
|
||||
|
||||
TestExecuter sc = new TestExecuter(model, true).setInputs(c, j, k).setOutputs(nor3.getOutput(), nor4.getOutput());
|
||||
sc.check(0, 1, 0, IGNORE, IGNORE); // undefined
|
||||
sc.check(1, 1, 0, IGNORE, IGNORE); // undefined
|
||||
sc.checkZ(0, 1, 0, IGNORE, IGNORE); // undefined
|
||||
sc.checkZ(1, 1, 0, IGNORE, IGNORE); // undefined
|
||||
sc.check(0, 1, 0, 1, 0);
|
||||
sc.check(0, 0, 0, 1, 0);
|
||||
sc.check(1, 0, 0, 1, 0);
|
||||
|
@ -1,9 +1,6 @@
|
||||
package de.neemann.digital;
|
||||
|
||||
import de.neemann.digital.core.Model;
|
||||
import de.neemann.digital.core.NodeException;
|
||||
import de.neemann.digital.core.ObservableValue;
|
||||
import de.neemann.digital.core.ObservableValues;
|
||||
import de.neemann.digital.core.*;
|
||||
import de.neemann.digital.core.element.Element;
|
||||
import de.neemann.digital.draw.elements.Circuit;
|
||||
import de.neemann.digital.draw.elements.PinException;
|
||||
@ -27,8 +24,8 @@ import static org.junit.Assert.assertTrue;
|
||||
* @author hneemann
|
||||
*/
|
||||
public class TestExecuter {
|
||||
public static final int IGNORE = -1;
|
||||
public static final int HIGHZ = -2;
|
||||
public static final Object IGNORE = new Object();
|
||||
public static final Object HIGHZ = new Object();
|
||||
|
||||
private final Model model;
|
||||
private ArrayList<ObservableValue> inputs;
|
||||
@ -47,6 +44,7 @@ public class TestExecuter {
|
||||
public TestExecuter() throws NodeException {
|
||||
this(null);
|
||||
}
|
||||
|
||||
public TestExecuter(Model model) throws NodeException {
|
||||
this(model, false);
|
||||
}
|
||||
@ -130,27 +128,43 @@ public class TestExecuter {
|
||||
clock.setBool(false);
|
||||
check(val);
|
||||
}
|
||||
public void check(long... val) throws NodeException {
|
||||
|
||||
public void checkZ(Object... val) throws NodeException {
|
||||
for (int i = 0; i < inputs.size(); i++) {
|
||||
if (val[i]==HIGHZ)
|
||||
if (val[i] == HIGHZ)
|
||||
inputs.get(i).set(0, true);
|
||||
else
|
||||
inputs.get(i).set(val[i], false);
|
||||
inputs.get(i).set(((Number) val[i]).longValue(), false);
|
||||
}
|
||||
if (model != null)
|
||||
model.doStep();
|
||||
|
||||
for (int i = 0; i < outputs.size(); i++) {
|
||||
long should = val[i + inputs.size()];
|
||||
if (should != IGNORE) {
|
||||
if (should == HIGHZ) {
|
||||
final Object v = val[i + inputs.size()];
|
||||
if (v != IGNORE) {
|
||||
if (v == HIGHZ) {
|
||||
assertTrue("highz output " + i, outputs.get(i).isHighZ());
|
||||
} else
|
||||
} else {
|
||||
long should = ((Number) v).longValue();
|
||||
assertEquals("output " + i, outputs.get(i).getValueBits(should), outputs.get(i).getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void check(long... val) throws NodeException {
|
||||
for (int i = 0; i < inputs.size(); i++)
|
||||
inputs.get(i).set(val[i], false);
|
||||
if (model != null)
|
||||
model.doStep();
|
||||
|
||||
for (int i = 0; i < outputs.size(); i++) {
|
||||
long should = val[i + inputs.size()];
|
||||
assertEquals("output " + i, outputs.get(i).getValueBits(should), outputs.get(i).getValue());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void clockUntil(int... val) throws NodeException {
|
||||
for (int clocks = 0; clocks < 1000; clocks++) {
|
||||
boolean isReached = true;
|
||||
|
@ -31,10 +31,10 @@ public class RAMDualPortTest extends TestCase {
|
||||
|
||||
TestExecuter sc = new TestExecuter(model).setInputs(a, d, str, clk, ld).setOutputs(out.getOutputs());
|
||||
// A D ST C LD
|
||||
sc.check(0, 0, 0, 0, 0, HIGHZ); // def
|
||||
sc.check(0, 5, 1, 1, 0, HIGHZ); // st 0->5
|
||||
sc.check(0, 0, 0, 0, 0, HIGHZ); // def
|
||||
sc.check(1, 9, 1, 1, 0, HIGHZ); // st 1->9
|
||||
sc.checkZ(0, 0, 0, 0, 0, HIGHZ); // def
|
||||
sc.checkZ(0, 5, 1, 1, 0, HIGHZ); // st 0->5
|
||||
sc.checkZ(0, 0, 0, 0, 0, HIGHZ); // def
|
||||
sc.checkZ(1, 9, 1, 1, 0, HIGHZ); // st 1->9
|
||||
sc.check(0, 0, 0, 0, 1, 5); // rd 5
|
||||
sc.check(1, 0, 0, 0, 1, 9); // rd 5
|
||||
}
|
||||
|
@ -31,10 +31,10 @@ public class RAMSinglePortTest extends TestCase {
|
||||
|
||||
TestExecuter sc = new TestExecuter(model).setInputs(a, d, str, clk, ld).setOutputs(out.getOutputs());
|
||||
// A D ST C LD
|
||||
sc.check(0, 0, 0, 0, 0, HIGHZ); // def
|
||||
sc.check(0, 5, 1, 1, 0, HIGHZ); // st 0->5
|
||||
sc.check(0, 0, 0, 0, 0, HIGHZ); // def
|
||||
sc.check(1, 9, 1, 1, 0, HIGHZ); // st 1->9
|
||||
sc.checkZ(0, 0, 0, 0, 0, HIGHZ); // def
|
||||
sc.checkZ(0, 5, 1, 1, 0, HIGHZ); // st 0->5
|
||||
sc.checkZ(0, 0, 0, 0, 0, HIGHZ); // def
|
||||
sc.checkZ(1, 9, 1, 1, 0, HIGHZ); // st 1->9
|
||||
sc.check(0, 0, 0, 0, 1, 5); // rd 5
|
||||
sc.check(1, 0, 0, 0, 1, 9); // rd 5
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ public class DriverTest extends TestCase {
|
||||
TestExecuter sc = new TestExecuter(model).setInputs(a, sel).setOutputs(out.getOutputs());
|
||||
sc.check(0, 1, 0);
|
||||
sc.check(2, 1, 2);
|
||||
sc.check(2, 0, HIGHZ);
|
||||
sc.checkZ(2, 0, HIGHZ);
|
||||
sc.check(2, 1, 2);
|
||||
}
|
||||
|
||||
|
@ -66,7 +66,7 @@ public class SplitterHighZTest extends TestCase {
|
||||
sc.check(1, 1, 0);
|
||||
sc.check(2, 0, 1);
|
||||
sc.check(3, 1, 1);
|
||||
sc.check(HIGHZ, HIGHZ, HIGHZ);
|
||||
sc.checkZ(HIGHZ, HIGHZ, HIGHZ);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -76,8 +76,8 @@ public class TestNesting extends TestCase {
|
||||
public void testMSFF() throws Exception {
|
||||
TestExecuter te = createTestExecuterForNesting("dig/nestedMSFF.dig");
|
||||
// C J K Q
|
||||
te.check(0, 0, 0, IGNORE); // initial state is undefined
|
||||
te.check(1, 0, 1, IGNORE);
|
||||
te.checkZ(0, 0, 0, IGNORE); // initial state is undefined
|
||||
te.checkZ(1, 0, 1, IGNORE);
|
||||
te.check(0, 0, 0, 0);
|
||||
te.check(1, 1, 0, 0);
|
||||
te.check(0, 0, 0, 1);
|
||||
|
Loading…
x
Reference in New Issue
Block a user