mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-14 15:26:52 -04:00
fixed the test cases
This commit is contained in:
parent
7329c06bd1
commit
95865a1a05
@ -13,9 +13,13 @@ import de.neemann.digital.core.element.ElementAttributes;
|
|||||||
import de.neemann.digital.draw.elements.Circuit;
|
import de.neemann.digital.draw.elements.Circuit;
|
||||||
import de.neemann.digital.draw.elements.VisualElement;
|
import de.neemann.digital.draw.elements.VisualElement;
|
||||||
import de.neemann.digital.draw.library.ElementLibrary;
|
import de.neemann.digital.draw.library.ElementLibrary;
|
||||||
|
import de.neemann.digital.draw.model.ModelCreator;
|
||||||
|
import de.neemann.digital.draw.shapes.ShapeFactory;
|
||||||
|
import de.neemann.digital.integration.Resources;
|
||||||
import de.neemann.digital.integration.ToBreakRunner;
|
import de.neemann.digital.integration.ToBreakRunner;
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@ -89,16 +93,20 @@ ExpressionCreator - s0 reduced from 17 to 2 variables ([Q_1n, Q_0n])
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testBacktrackCompleteness() throws Exception {
|
public void testBacktrackCompleteness() throws Exception {
|
||||||
ToBreakRunner toBreakRunner = new ToBreakRunner("dig/backtrack/AllComponents.dig", false);
|
File f = new File(Resources.getRoot(), "dig/backtrack/AllComponents.dig");
|
||||||
|
|
||||||
|
final ElementLibrary library = new ElementLibrary();
|
||||||
|
library.setRootFilePath(f.getParentFile());
|
||||||
|
ShapeFactory shapeFactory = new ShapeFactory(library);
|
||||||
|
Circuit circuit = Circuit.loadCircuit(f, shapeFactory);
|
||||||
|
|
||||||
// create a set of all components used in the circuit
|
// create a set of all components used in the circuit
|
||||||
Circuit circuit = toBreakRunner.getCircuit();
|
|
||||||
Set<String> set = new HashSet<>();
|
Set<String> set = new HashSet<>();
|
||||||
for (VisualElement e : circuit.getElements())
|
for (VisualElement e : circuit.getElements())
|
||||||
set.add(e.getElementName());
|
set.add(e.getElementName());
|
||||||
|
|
||||||
// ensure all available components are included in test circuit
|
// ensure all available components are included in test circuit
|
||||||
for (ElementLibrary.ElementContainer c : toBreakRunner.getLibrary()) {
|
for (ElementLibrary.ElementContainer c : library) {
|
||||||
if (!set.contains(c.getDescription().getName())) {
|
if (!set.contains(c.getDescription().getName())) {
|
||||||
// nodes with state are allowed to be missing
|
// nodes with state are allowed to be missing
|
||||||
Element n = c.getDescription().createElement(new ElementAttributes());
|
Element n = c.getDescription().createElement(new ElementAttributes());
|
||||||
@ -108,7 +116,8 @@ ExpressionCreator - s0 reduced from 17 to 2 variables ([Q_1n, Q_0n])
|
|||||||
}
|
}
|
||||||
|
|
||||||
// check if backtracking is ok at all components!
|
// check if backtracking is ok at all components!
|
||||||
ModelAnalyser m = new ModelAnalyser(toBreakRunner.getModel());
|
Model model = new ModelCreator(circuit, new SubstituteLibrary(library)).createModel(false);
|
||||||
|
ModelAnalyser m = new ModelAnalyser(model);
|
||||||
new DependencyAnalyser(m);
|
new DependencyAnalyser(m);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,10 +10,19 @@ import de.neemann.digital.analyse.quinemc.BoolTable;
|
|||||||
import de.neemann.digital.analyse.quinemc.BoolTableByteArray;
|
import de.neemann.digital.analyse.quinemc.BoolTableByteArray;
|
||||||
import de.neemann.digital.analyse.quinemc.ThreeStateValue;
|
import de.neemann.digital.analyse.quinemc.ThreeStateValue;
|
||||||
import de.neemann.digital.core.Model;
|
import de.neemann.digital.core.Model;
|
||||||
|
import de.neemann.digital.core.NodeException;
|
||||||
import de.neemann.digital.core.Signal;
|
import de.neemann.digital.core.Signal;
|
||||||
import de.neemann.digital.integration.ToBreakRunner;
|
import de.neemann.digital.draw.elements.Circuit;
|
||||||
|
import de.neemann.digital.draw.elements.PinException;
|
||||||
|
import de.neemann.digital.draw.library.ElementLibrary;
|
||||||
|
import de.neemann.digital.draw.library.ElementNotFoundException;
|
||||||
|
import de.neemann.digital.draw.model.ModelCreator;
|
||||||
|
import de.neemann.digital.draw.shapes.ShapeFactory;
|
||||||
|
import de.neemann.digital.integration.Resources;
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.TreeMap;
|
import java.util.TreeMap;
|
||||||
@ -25,8 +34,19 @@ import static de.neemann.digital.analyse.quinemc.ThreeStateValue.zero;
|
|||||||
*/
|
*/
|
||||||
public class ModelAnalyserTest extends TestCase {
|
public class ModelAnalyserTest extends TestCase {
|
||||||
|
|
||||||
|
public Model createModel(String file) throws IOException, ElementNotFoundException, PinException, NodeException {
|
||||||
|
File f = new File(Resources.getRoot(), file);
|
||||||
|
|
||||||
|
final ElementLibrary library = new ElementLibrary();
|
||||||
|
library.setRootFilePath(f.getParentFile());
|
||||||
|
ShapeFactory shapeFactory = new ShapeFactory(library);
|
||||||
|
Circuit circuit = Circuit.loadCircuit(f, shapeFactory);
|
||||||
|
|
||||||
|
return new ModelCreator(circuit, new SubstituteLibrary(library)).createModel(false);
|
||||||
|
}
|
||||||
|
|
||||||
public void testAnalyzer() throws Exception {
|
public void testAnalyzer() throws Exception {
|
||||||
Model model = new ToBreakRunner("dig/analyze/analyzeTest.dig").getModel();
|
Model model = createModel("dig/analyze/analyzeTest.dig");
|
||||||
TruthTable tt = new ModelAnalyser(model).analyse();
|
TruthTable tt = new ModelAnalyser(model).analyse();
|
||||||
|
|
||||||
assertEquals(4, tt.getRows());
|
assertEquals(4, tt.getRows());
|
||||||
@ -46,25 +66,25 @@ public class ModelAnalyserTest extends TestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testAnalyzerDFF() throws Exception {
|
public void testAnalyzerDFF() throws Exception {
|
||||||
Model model = new ToBreakRunner("dig/analyze/analyzeTestDFF.dig").getModel();
|
Model model = createModel("dig/analyze/analyzeTestDFF.dig");
|
||||||
TruthTable tt = new ModelAnalyser(model).analyse();
|
TruthTable tt = new ModelAnalyser(model).analyse();
|
||||||
check2BitCounter(tt);
|
check2BitCounter(tt);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testAnalyzerJKFF() throws Exception {
|
public void testAnalyzerJKFF() throws Exception {
|
||||||
Model model = new ToBreakRunner("dig/analyze/analyzeTestJKFF.dig", false).getModel();
|
Model model = createModel("dig/analyze/analyzeTestJKFF.dig");
|
||||||
TruthTable tt = new ModelAnalyser(model).analyse();
|
TruthTable tt = new ModelAnalyser(model).analyse();
|
||||||
check2BitCounter(tt);
|
check2BitCounter(tt);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testAnalyzerTFF() throws Exception {
|
public void testAnalyzerTFF() throws Exception {
|
||||||
Model model = new ToBreakRunner("dig/analyze/analyzeTestTFF.dig", false).getModel();
|
Model model = createModel("dig/analyze/analyzeTestTFF.dig");
|
||||||
TruthTable tt = new ModelAnalyser(model).analyse();
|
TruthTable tt = new ModelAnalyser(model).analyse();
|
||||||
check2BitCounter(tt);
|
check2BitCounter(tt);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testAnalyzerTFFEnable() throws Exception {
|
public void testAnalyzerTFFEnable() throws Exception {
|
||||||
Model model = new ToBreakRunner("dig/analyze/analyzeTestTFFEnable.dig", false).getModel();
|
Model model = createModel("dig/analyze/analyzeTestTFFEnable.dig");
|
||||||
TruthTable tt = new ModelAnalyser(model).analyse();
|
TruthTable tt = new ModelAnalyser(model).analyse();
|
||||||
check2BitCounter(tt);
|
check2BitCounter(tt);
|
||||||
}
|
}
|
||||||
@ -93,7 +113,7 @@ public class ModelAnalyserTest extends TestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testAnalyzerUniqueNames() throws Exception {
|
public void testAnalyzerUniqueNames() throws Exception {
|
||||||
Model model = new ToBreakRunner("dig/analyze/uniqueNames.dig", false).getModel();
|
Model model = createModel("dig/analyze/uniqueNames.dig");
|
||||||
try {
|
try {
|
||||||
new ModelAnalyser(model);
|
new ModelAnalyser(model);
|
||||||
fail();
|
fail();
|
||||||
@ -103,7 +123,7 @@ public class ModelAnalyserTest extends TestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testAnalyzerUniqueNames2() throws Exception {
|
public void testAnalyzerUniqueNames2() throws Exception {
|
||||||
Model model = new ToBreakRunner("dig/analyze/uniqueNames2.dig", false).getModel();
|
Model model = createModel("dig/analyze/uniqueNames2.dig");
|
||||||
ArrayList<Signal> ins = new ModelAnalyser(model).getInputs();
|
ArrayList<Signal> ins = new ModelAnalyser(model).getInputs();
|
||||||
assertEquals(2,ins.size());
|
assertEquals(2,ins.size());
|
||||||
assertEquals("Q_0n",ins.get(0).getName());
|
assertEquals("Q_0n",ins.get(0).getName());
|
||||||
@ -111,7 +131,7 @@ public class ModelAnalyserTest extends TestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testAnalyzerUniqueNames3() throws Exception {
|
public void testAnalyzerUniqueNames3() throws Exception {
|
||||||
Model model = new ToBreakRunner("dig/analyze/uniqueNames3.dig", false).getModel();
|
Model model = createModel("dig/analyze/uniqueNames3.dig");
|
||||||
ArrayList<Signal> ins = new ModelAnalyser(model).getInputs();
|
ArrayList<Signal> ins = new ModelAnalyser(model).getInputs();
|
||||||
assertEquals(2,ins.size());
|
assertEquals(2,ins.size());
|
||||||
assertEquals("Zn",ins.get(0).getName());
|
assertEquals("Zn",ins.get(0).getName());
|
||||||
@ -119,7 +139,7 @@ public class ModelAnalyserTest extends TestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testAnalyzerUniqueNames4() throws Exception {
|
public void testAnalyzerUniqueNames4() throws Exception {
|
||||||
Model model = new ToBreakRunner("dig/analyze/uniqueNames4.dig", false).getModel();
|
Model model = createModel("dig/analyze/uniqueNames4.dig");
|
||||||
ArrayList<Signal> ins = new ModelAnalyser(model).getInputs();
|
ArrayList<Signal> ins = new ModelAnalyser(model).getInputs();
|
||||||
assertEquals(2,ins.size());
|
assertEquals(2,ins.size());
|
||||||
assertEquals("Bn",ins.get(0).getName());
|
assertEquals("Bn",ins.get(0).getName());
|
||||||
@ -127,7 +147,7 @@ public class ModelAnalyserTest extends TestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testAnalyzerMultiBit() throws Exception {
|
public void testAnalyzerMultiBit() throws Exception {
|
||||||
Model model = new ToBreakRunner("dig/analyze/multiBitCounter.dig", false).getModel();
|
Model model = createModel("dig/analyze/multiBitCounter.dig");
|
||||||
TruthTable tt = new ModelAnalyser(model).analyse();
|
TruthTable tt = new ModelAnalyser(model).analyse();
|
||||||
checkTable(tt.getResult("Q0n+1"), one, zero, one, zero);
|
checkTable(tt.getResult("Q0n+1"), one, zero, one, zero);
|
||||||
checkTable(tt.getResult("Q1n+1"), zero, one, one, zero);
|
checkTable(tt.getResult("Q1n+1"), zero, one, one, zero);
|
||||||
@ -144,7 +164,7 @@ public class ModelAnalyserTest extends TestCase {
|
|||||||
|
|
||||||
|
|
||||||
public void testAnalyzerMultiBit2() throws Exception {
|
public void testAnalyzerMultiBit2() throws Exception {
|
||||||
Model model = new ToBreakRunner("dig/analyze/multiBitInOut.dig", false).getModel();
|
Model model = createModel("dig/analyze/multiBitInOut.dig");
|
||||||
TruthTable tt = new ModelAnalyser(model).analyse();
|
TruthTable tt = new ModelAnalyser(model).analyse();
|
||||||
checkIdent(tt);
|
checkIdent(tt);
|
||||||
|
|
||||||
@ -157,7 +177,7 @@ public class ModelAnalyserTest extends TestCase {
|
|||||||
|
|
||||||
// test with non zero default values set
|
// test with non zero default values set
|
||||||
public void testAnalyzerMultiBit3() throws Exception {
|
public void testAnalyzerMultiBit3() throws Exception {
|
||||||
Model model = new ToBreakRunner("dig/analyze/multiBitInOutDef.dig", false).getModel();
|
Model model = createModel("dig/analyze/multiBitInOutDef.dig");
|
||||||
TruthTable tt = new ModelAnalyser(model).analyse();
|
TruthTable tt = new ModelAnalyser(model).analyse();
|
||||||
checkIdent(tt);
|
checkIdent(tt);
|
||||||
}
|
}
|
||||||
@ -176,7 +196,7 @@ public class ModelAnalyserTest extends TestCase {
|
|||||||
|
|
||||||
|
|
||||||
public void testAnalyzerBacktrack() throws Exception {
|
public void testAnalyzerBacktrack() throws Exception {
|
||||||
Model model = new ToBreakRunner("dig/analyze/analyzeBacktrack.dig", false).getModel();
|
Model model = createModel("dig/analyze/analyzeBacktrack.dig");
|
||||||
TruthTable tt = new ModelAnalyser(model).analyse();
|
TruthTable tt = new ModelAnalyser(model).analyse();
|
||||||
|
|
||||||
final BoolTable Y1 = tt.getResult("1Y");
|
final BoolTable Y1 = tt.getResult("1Y");
|
||||||
@ -210,7 +230,7 @@ public class ModelAnalyserTest extends TestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testAnalyzerMultiBitPins() throws Exception {
|
public void testAnalyzerMultiBitPins() throws Exception {
|
||||||
Model model = new ToBreakRunner("dig/analyze/multiBitInOutXOr.dig", false).getModel();
|
Model model = createModel("dig/analyze/multiBitInOutXOr.dig");
|
||||||
ModelAnalyserInfo mai = new ModelAnalyser(model).analyse().getModelAnalyzerInfo();
|
ModelAnalyserInfo mai = new ModelAnalyser(model).analyse().getModelAnalyzerInfo();
|
||||||
|
|
||||||
assertEquals(2, mai.getInputBusMap().size());
|
assertEquals(2, mai.getInputBusMap().size());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user