fixed a bug in the test executor

This commit is contained in:
hneemann 2018-01-04 17:17:39 +01:00
parent bd19b80578
commit 4bc24f68ee
7 changed files with 41 additions and 27 deletions

View File

@ -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);

View File

@ -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;

View File

@ -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
}

View File

@ -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
}

View File

@ -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);
}

View File

@ -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);
}
}

View File

@ -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);