mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-14 15:26:52 -04:00
moved the init code to the constructor
This commit is contained in:
parent
c56e921728
commit
71cc6fc8ec
@ -33,14 +33,14 @@ public class TestExecutor {
|
||||
private final Model model;
|
||||
private final LineEmitter lines;
|
||||
private final ValueTable results;
|
||||
private final ArrayList<VirtualSignal> virtualSignals;
|
||||
private final Context context;
|
||||
private final ArrayList<TestSignal> inputs;
|
||||
private final ArrayList<TestSignal> outputs;
|
||||
private boolean errorOccurred;
|
||||
private int failedCount;
|
||||
private int passedCount;
|
||||
private int rowCount;
|
||||
private boolean toManyResults = false;
|
||||
private ArrayList<TestSignal> inputs;
|
||||
private ArrayList<TestSignal> outputs;
|
||||
private int visibleRows;
|
||||
private boolean allowMissingInputs;
|
||||
|
||||
@ -79,59 +79,11 @@ public class TestExecutor {
|
||||
*/
|
||||
public TestExecutor(TestCaseDescription testCase, Model model) throws TestingDataException {
|
||||
names = testCase.getNames();
|
||||
virtualSignals = testCase.getVirtualSignals();
|
||||
this.model = model;
|
||||
results = new ValueTable(names);
|
||||
visibleRows = 0;
|
||||
lines = testCase.getLines();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the model to the given row.
|
||||
*
|
||||
* @param row the row to advance the model to
|
||||
* @throws TestingDataException DataException
|
||||
* @throws ParserException ParserException
|
||||
*/
|
||||
public void executeTo(int row) throws TestingDataException, ParserException {
|
||||
execute(new LineListener() {
|
||||
private int r = row;
|
||||
|
||||
@Override
|
||||
public void add(TestRow testRow) {
|
||||
Value[] values = testRow.getValues();
|
||||
Value[] res = new Value[values.length];
|
||||
|
||||
if (r >= 0) {
|
||||
advanceModel(model, testRow, values, res);
|
||||
r--;
|
||||
}
|
||||
}
|
||||
}, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the result by comparing the testing vector with the given model
|
||||
*
|
||||
* @return the result of the test execution
|
||||
* @throws TestingDataException DataException
|
||||
* @throws ParserException ParserException
|
||||
*/
|
||||
public TestExecutor.Result execute() throws TestingDataException, ParserException {
|
||||
return execute(values -> checkRow(model, values), true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the test and sends all the test lines to the {@link LineListener} provided.
|
||||
*
|
||||
* @param lineListener the line listener to use
|
||||
* @param closeModel if true the model is closed
|
||||
* @return the result of the test execution
|
||||
* @throws TestingDataException DataException
|
||||
* @throws ParserException ParserException
|
||||
*/
|
||||
private TestExecutor.Result execute(LineListener lineListener, boolean closeModel) throws TestingDataException, ParserException {
|
||||
try {
|
||||
HashSet<String> usedSignals = new HashSet<>();
|
||||
inputs = new ArrayList<>();
|
||||
outputs = new ArrayList<>();
|
||||
@ -168,9 +120,9 @@ public class TestExecutor {
|
||||
}
|
||||
}
|
||||
|
||||
Context context = new Context().setModel(model);
|
||||
context = new Context().setModel(model);
|
||||
|
||||
for (VirtualSignal s : virtualSignals) {
|
||||
for (VirtualSignal s : testCase.getVirtualSignals()) {
|
||||
final int index = getIndexOf(s.getName());
|
||||
if (index >= 0) {
|
||||
outputs.add(new TestSignal(index, s.getValue(context)));
|
||||
@ -196,9 +148,52 @@ public class TestExecutor {
|
||||
if (event.getType() == ModelEventType.ERROR_OCCURRED)
|
||||
errorOccurred = true;
|
||||
}, ModelEventType.ERROR_OCCURRED);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the model to the given row.
|
||||
*
|
||||
* @param row the row to advance the model to
|
||||
* @throws ParserException ParserException
|
||||
*/
|
||||
public void executeTo(int row) throws ParserException {
|
||||
execute(new LineListener() {
|
||||
private int r = row;
|
||||
|
||||
@Override
|
||||
public void add(TestRow testRow) {
|
||||
Value[] values = testRow.getValues();
|
||||
Value[] res = new Value[values.length];
|
||||
|
||||
if (r >= 0) {
|
||||
advanceModel(model, testRow, values, res);
|
||||
r--;
|
||||
}
|
||||
}
|
||||
}, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the result by comparing the testing vector with the given model
|
||||
*
|
||||
* @return the result of the test execution
|
||||
* @throws ParserException ParserException
|
||||
*/
|
||||
public TestExecutor.Result execute() throws ParserException {
|
||||
return execute(values -> checkRow(model, values), true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the test and sends all the test lines to the {@link LineListener} provided.
|
||||
*
|
||||
* @param lineListener the line listener to use
|
||||
* @param closeModel if true the model is closed
|
||||
* @return the result of the test execution
|
||||
* @throws ParserException ParserException
|
||||
*/
|
||||
private TestExecutor.Result execute(LineListener lineListener, boolean closeModel) throws ParserException {
|
||||
try {
|
||||
lines.emitLines(new LineListenerResolveDontCare(lineListener, inputs), context);
|
||||
|
||||
return new Result();
|
||||
} finally {
|
||||
if (closeModel)
|
||||
|
Loading…
x
Reference in New Issue
Block a user