mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-24 04:42:51 -04:00
preserves the test case seed value during a debug session, closes #675
This commit is contained in:
parent
4b6ac347bd
commit
08f091d232
@ -1194,6 +1194,9 @@ public final class Main extends JFrame implements ClosingWindowListener.ConfirmS
|
|||||||
if (tsl.isEmpty())
|
if (tsl.isEmpty())
|
||||||
throw new TestingDataException(Lang.get("err_noTestData"));
|
throw new TestingDataException(Lang.get("err_noTestData"));
|
||||||
|
|
||||||
|
for (Circuit.TestCase tc : tsl)
|
||||||
|
tc.getTestCaseDescription().setNewSeed();
|
||||||
|
|
||||||
windowPosManager.register("testResult", new ValueTableDialog(Main.this, Lang.get("msg_testResult"))
|
windowPosManager.register("testResult", new ValueTableDialog(Main.this, Lang.get("msg_testResult"))
|
||||||
.addTestResult(tsl, circuitComponent.getCircuit(), library))
|
.addTestResult(tsl, circuitComponent.getCircuit(), library))
|
||||||
.setVisible(true);
|
.setVisible(true);
|
||||||
|
@ -7,6 +7,7 @@ package de.neemann.digital.testing;
|
|||||||
|
|
||||||
import de.neemann.digital.lang.Lang;
|
import de.neemann.digital.lang.Lang;
|
||||||
import de.neemann.digital.testing.parser.*;
|
import de.neemann.digital.testing.parser.*;
|
||||||
|
import de.neemann.digital.testing.parser.functions.Random;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -20,6 +21,8 @@ public class TestCaseDescription {
|
|||||||
private transient ArrayList<String> names;
|
private transient ArrayList<String> names;
|
||||||
private transient ArrayList<VirtualSignal> virtualSignals;
|
private transient ArrayList<VirtualSignal> virtualSignals;
|
||||||
private transient ModelInitializer modelInitializer;
|
private transient ModelInitializer modelInitializer;
|
||||||
|
private transient Random random;
|
||||||
|
private transient long seed;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -48,6 +51,14 @@ public class TestCaseDescription {
|
|||||||
*/
|
*/
|
||||||
public TestCaseDescription(TestCaseDescription valueToCopy) {
|
public TestCaseDescription(TestCaseDescription valueToCopy) {
|
||||||
this.dataString = valueToCopy.dataString;
|
this.dataString = valueToCopy.dataString;
|
||||||
|
this.seed = valueToCopy.seed;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new seed value
|
||||||
|
*/
|
||||||
|
public void setNewSeed() {
|
||||||
|
seed = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -65,6 +76,9 @@ public class TestCaseDescription {
|
|||||||
throw new TestingDataException(Lang.get("err_errorParsingTestdata"), e);
|
throw new TestingDataException(Lang.get("err_errorParsingTestdata"), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (seed == 0)
|
||||||
|
seed = System.currentTimeMillis();
|
||||||
|
random.setSeed(seed);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void parseDataString() throws IOException, ParserException {
|
private void parseDataString() throws IOException, ParserException {
|
||||||
@ -73,6 +87,7 @@ public class TestCaseDescription {
|
|||||||
names = tdp.getNames();
|
names = tdp.getNames();
|
||||||
virtualSignals = tdp.getVirtualSignals();
|
virtualSignals = tdp.getVirtualSignals();
|
||||||
modelInitializer = tdp.getModelInitializer();
|
modelInitializer = tdp.getModelInitializer();
|
||||||
|
random = tdp.getRandom();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -37,6 +37,7 @@ public class Parser {
|
|||||||
private final ArrayList<VirtualSignal> virtualSignals;
|
private final ArrayList<VirtualSignal> virtualSignals;
|
||||||
private final Tokenizer tok;
|
private final Tokenizer tok;
|
||||||
private final HashMap<String, Function> functions = new HashMap<>();
|
private final HashMap<String, Function> functions = new HashMap<>();
|
||||||
|
private final Random random;
|
||||||
private LineEmitter emitter;
|
private LineEmitter emitter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -46,7 +47,8 @@ public class Parser {
|
|||||||
*/
|
*/
|
||||||
public Parser(String data) {
|
public Parser(String data) {
|
||||||
functions.put("signExt", new SignExtend());
|
functions.put("signExt", new SignExtend());
|
||||||
functions.put("random", new Random());
|
random = new Random();
|
||||||
|
functions.put("random", random);
|
||||||
functions.put("ite", new IfThenElse());
|
functions.put("ite", new IfThenElse());
|
||||||
names = new ArrayList<>();
|
names = new ArrayList<>();
|
||||||
virtualSignals = new ArrayList<>();
|
virtualSignals = new ArrayList<>();
|
||||||
@ -302,6 +304,13 @@ public class Parser {
|
|||||||
return modelInit;
|
return modelInit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the random function
|
||||||
|
*/
|
||||||
|
public Random getRandom() {
|
||||||
|
return random;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the line emitter
|
* @return the line emitter
|
||||||
*/
|
*/
|
||||||
|
@ -17,15 +17,27 @@ import java.util.ArrayList;
|
|||||||
*/
|
*/
|
||||||
public class Random extends Function {
|
public class Random extends Function {
|
||||||
|
|
||||||
|
private final java.util.Random rnd;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new function
|
* Creates a new function
|
||||||
*/
|
*/
|
||||||
public Random() {
|
public Random() {
|
||||||
super(1);
|
super(1);
|
||||||
|
this.rnd = new java.util.Random();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the random seed
|
||||||
|
*
|
||||||
|
* @param seed the seed
|
||||||
|
*/
|
||||||
|
public void setSeed(long seed) {
|
||||||
|
rnd.setSeed(seed);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long calcValue(Context c, ArrayList<Expression> args) throws ParserException {
|
public long calcValue(Context c, ArrayList<Expression> args) throws ParserException {
|
||||||
return (long) (Math.random() * args.get(0).value(c));
|
return (long) (rnd.nextDouble() * args.get(0).value(c));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user