fixed an issue with the clock cycle during test execution

This commit is contained in:
hneemann 2017-07-04 09:33:23 +02:00
parent 47ea8752ce
commit 748634bcea
5 changed files with 88 additions and 20 deletions

View File

@ -104,21 +104,10 @@ public class DataPlotter implements Drawable {
long width = data.getMax(i); long width = data.getMax(i);
if (width == 0) width = 1; if (width == 0) width = 1;
int ry; int ry;
if (s[i].getType() == Value.Type.CLOCK) {
int xdown = (int) (size / 4);
ry = 0;
g.drawLine(new Vector(xx, y + ry), new Vector(xx + xdown, y + ry), style);
if (!first && ry != lastRy[i])
g.drawLine(new Vector(xx, y + lastRy[i]), new Vector(xx, y + ry), style);
ry = SIZE;
g.drawLine(new Vector(xx + xdown, y + ry), new Vector((int) (xx + size), y + ry), style);
g.drawLine(new Vector(xx + xdown, y), new Vector(xx + xdown, y + SIZE), style);
} else {
ry = (int) (SIZE - (SIZE * s[i].getValue()) / width); ry = (int) (SIZE - (SIZE * s[i].getValue()) / width);
g.drawLine(new Vector(xx, y + ry), new Vector((int) (xx + size), y + ry), style); g.drawLine(new Vector(xx, y + ry), new Vector((int) (xx + size), y + ry), style);
if (!first && ry != lastRy[i]) if (!first && ry != lastRy[i])
g.drawLine(new Vector(xx, y + lastRy[i]), new Vector(xx, y + ry), style); g.drawLine(new Vector(xx, y + lastRy[i]), new Vector(xx, y + ry), style);
}
lastRy[i] = ry; lastRy[i] = ry;
y += SIZE + SEP; y += SIZE + SEP;

View File

@ -15,6 +15,7 @@ public class ValueTable extends Observable implements Iterable<Value[]> {
private final String[] names; private final String[] names;
private final ArrayList<Value[]> values; private final ArrayList<Value[]> values;
private ArrayList<Integer> tableRowIndex;
private final long[] max; private final long[] max;
private int maxSize = 0; private int maxSize = 0;
@ -45,6 +46,16 @@ public class ValueTable extends Observable implements Iterable<Value[]> {
return values.size(); return values.size();
} }
/**
* @return number of rows in a table
*/
public int getTableRows() {
if (tableRowIndex == null)
return values.size();
else
return tableRowIndex.size();
}
/** /**
* add values without copying them * add values without copying them
* *
@ -53,13 +64,20 @@ public class ValueTable extends Observable implements Iterable<Value[]> {
*/ */
public ValueTable add(Value[] row) { public ValueTable add(Value[] row) {
if (maxSize > 0 && values.size() >= maxSize) { if (maxSize > 0 && values.size() >= maxSize) {
if (tableRowIndex != null)
throw new RuntimeException("delete not allowed if table index is present");
while (values.size() >= maxSize) while (values.size() >= maxSize)
values.remove(0); values.remove(0);
Arrays.fill(max, 0); Arrays.fill(max, 0);
for (Value[] v : values) for (Value[] v : values)
checkMax(v); checkMax(v);
} }
if (tableRowIndex != null)
tableRowIndex.add(values.size());
values.add(row); values.add(row);
checkMax(row); checkMax(row);
fireHasChanged(); fireHasChanged();
@ -67,6 +85,22 @@ public class ValueTable extends Observable implements Iterable<Value[]> {
return this; return this;
} }
/**
* omit the last added value in a table representation
*
* @return this for chained calls
*/
public ValueTable omitInTable() {
if (tableRowIndex == null) {
tableRowIndex = new ArrayList<>();
for (int i = 0; i < values.size(); i++)
tableRowIndex.add(i);
}
tableRowIndex.remove(tableRowIndex.size() - 1);
return this;
}
private void checkMax(Value[] row) { private void checkMax(Value[] row) {
for (int i = 0; i < row.length; i++) for (int i = 0; i < row.length; i++)
if (max[i] < row[i].getValue()) max[i] = row[i].getValue(); if (max[i] < row[i].getValue()) max[i] = row[i].getValue();
@ -75,7 +109,7 @@ public class ValueTable extends Observable implements Iterable<Value[]> {
/** /**
* provides the values * provides the values
* *
* @param rowIndex the wow * @param rowIndex the row
* @param columnIndex the column * @param columnIndex the column
* @return the value stored at the given position * @return the value stored at the given position
*/ */
@ -83,6 +117,20 @@ public class ValueTable extends Observable implements Iterable<Value[]> {
return values.get(rowIndex)[columnIndex]; return values.get(rowIndex)[columnIndex];
} }
/**
* provides the values for the use in a table
*
* @param rowIndex the row
* @param columnIndex the column
* @return the value stored at the given position
*/
public Value getTableValue(int rowIndex, int columnIndex) {
if (tableRowIndex == null)
return values.get(rowIndex)[columnIndex];
else
return values.get(tableRowIndex.get(rowIndex))[columnIndex];
}
/** /**
* the number of signals * the number of signals
* *

View File

@ -32,7 +32,7 @@ public class ValueTableModel implements TableModel, Observer {
@Override @Override
public int getRowCount() { public int getRowCount() {
return values.getRows(); return values.getTableRows();
} }
@Override @Override
@ -66,7 +66,7 @@ public class ValueTableModel implements TableModel, Observer {
if (columnIndex == 0) if (columnIndex == 0)
return rowIndex; return rowIndex;
else else
return values.getValue(rowIndex, columnIndex - 1); return values.getTableValue(rowIndex, columnIndex - 1);
} }

View File

@ -132,19 +132,25 @@ public class TestExecutor {
try { try {
if (clockIsUsed) { // a clock signal is used if (clockIsUsed) { // a clock signal is used
model.doStep(); // propagate all except clock model.doStep(); // propagate all except clock
addClockRow(row.length);
// set clock // set clock
for (TestSignal in : inputs) for (TestSignal in : inputs)
if (row[in.index].getType() == Value.Type.CLOCK) if (row[in.index].getType() == Value.Type.CLOCK) {
row[in.index].copyTo(in.value); row[in.index].copyTo(in.value);
res[in.index] = row[in.index];
}
// propagate clock change // propagate clock change
model.doStep(); model.doStep();
addClockRow(row.length);
// restore clock // restore clock
for (TestSignal in : inputs) // invert the clock values for (TestSignal in : inputs) // invert the clock values
if (row[in.index].getType() == Value.Type.CLOCK) if (row[in.index].getType() == Value.Type.CLOCK) {
in.value.setBool(!in.value.getBool()); in.value.setBool(!in.value.getBool());
res[in.index] = new Value(in.value);
}
} }
model.doStep(); model.doStep();
@ -170,6 +176,18 @@ public class TestExecutor {
toManyResults = true; toManyResults = true;
} }
private void addClockRow(int cols) {
if (results.getRows() < ERR_RESULTS) {
Value[] r = new Value[cols];
for (TestSignal out : outputs)
r[out.index] = new Value(out.value);
for (TestSignal in : inputs)
r[in.index] = new Value(in.value);
results.add(r).omitInTable();
} else
toManyResults = true;
}
/** /**
* @return true if all tests have passed * @return true if all tests have passed
*/ */

View File

@ -44,4 +44,17 @@ public class ValueTableTest extends TestCase {
assertEquals(4,t.getMax(1)); assertEquals(4,t.getMax(1));
assertEquals(3,t.getMax(2)); assertEquals(3,t.getMax(2));
} }
public void testOmit() {
ValueTable t = new ValueTable("A");
t.add(new Value[]{new Value(1)});
t.add(new Value[]{new Value(2)}).omitInTable();
t.add(new Value[]{new Value(3)});
t.add(new Value[]{new Value(4)}).omitInTable();
t.add(new Value[]{new Value(5)});
assertEquals(3,t.getTableRows());
assertTrue(new Value(1).isEqualTo(t.getTableValue(0,0)));
assertTrue(new Value(3).isEqualTo(t.getTableValue(1,0)));
assertTrue(new Value(5).isEqualTo(t.getTableValue(2,0)));
}
} }