use of de.neemann.digital.analyse.TruthTable in project Digital by hneemann.
the class TestReorderOutputs method testDeleteResult.
public void testDeleteResult() throws Exception {
TruthTable t = new TruthTable(3).addResult().addResult();
BoolTableByteArray col = (BoolTableByteArray) t.getResult(0);
for (int i = 0; i < t.getRows(); i++) col.set(i, i + 1);
ReorderOutputs reorderOutputs = new ReorderOutputs(t);
reorderOutputs.getItems().delete(1);
TruthTable newTable = reorderOutputs.reorder();
assertEquals(3, newTable.getVars().size());
assertEquals(1, newTable.getResultCount());
}
use of de.neemann.digital.analyse.TruthTable in project Digital by hneemann.
the class BuilderExpressionCreatorTest method testMultipleResults.
public void testMultipleResults() throws AnalyseException, FormatterException, ExpressionException {
BoolTable table = new BoolTableByteArray(new byte[] { 2, 0, 0, 0, 1, 2, 0, 0, 1, 1, 2, 0, 1, 1, 1, 2 });
TruthTable tt = new TruthTable(vars(4)).addResult("Y", table);
ExpressionListenerStore els = new ExpressionListenerStore(null);
new ExpressionCreator(tt).create(els);
assertEquals(4, els.getResults().size());
}
use of de.neemann.digital.analyse.TruthTable in project Digital by hneemann.
the class Main method createAnalyseMenu.
/**
* Creates the analyse menu
*
* @param menuBar the menu bar
*/
private void createAnalyseMenu(JMenuBar menuBar) {
JMenu analyse = new JMenu(Lang.get("menu_analyse"));
menuBar.add(analyse);
analyse.add(new ToolTipAction(Lang.get("menu_analyse")) {
@Override
public void actionPerformed(ActionEvent e) {
try {
Model model = new ModelCreator(circuitComponent.getCircuit(), library).createModel(false);
try {
if (model.isInvalidSignal())
new ErrorMessage(Lang.get("msg_invalidSignalsAnalysed")).show(Main.this);
else
new TableDialog(Main.this, new ModelAnalyser(model).analyse(), library, shapeFactory, getBaseFileName()).setVisible(true);
ensureModelIsStopped();
} finally {
model.close();
}
} catch (PinException | NodeException | AnalyseException | ElementNotFoundException | BacktrackException | RuntimeException e1) {
showErrorWithoutARunningModel(Lang.get("msg_analyseErr"), e1);
}
}
}.setToolTip(Lang.get("menu_analyse_tt")).setAccelerator("F9").createJMenuItem());
analyse.add(new ToolTipAction(Lang.get("menu_synthesise")) {
@Override
public void actionPerformed(ActionEvent e) {
TruthTable tt = new TruthTable(3).addResult();
new TableDialog(Main.this, tt, library, shapeFactory, getBaseFileName()).setVisible(true);
ensureModelIsStopped();
}
}.setToolTip(Lang.get("menu_synthesise_tt")).createJMenuItem());
analyse.add(new ToolTipAction(Lang.get("menu_expression")) {
@Override
public void actionPerformed(ActionEvent e) {
new ExpressionDialog(Main.this, library, shapeFactory, getBaseFileName()).setVisible(true);
}
}.setToolTip(Lang.get("menu_expression_tt")).createJMenuItem());
}
use of de.neemann.digital.analyse.TruthTable in project Digital by hneemann.
the class TruthTableFormatterLaTeXTest method testFormat.
public void testFormat() throws Exception {
TruthTable tt = new TruthTable(3);
tt.addResult("Y_0");
tt.addResult("Y_1");
assertEquals("\\begin{center}\n" + "\\begin{tabular}{ccc|cc}\n" + "$A$&$B$&$C$&$Y_{0}$&$Y_{1}$\\\\\n" + "\\hline\n" + "$0$&$0$&$0$&$0$&$0$\\\\\n" + "$0$&$0$&$1$&$0$&$0$\\\\\n" + "$0$&$1$&$0$&$0$&$0$\\\\\n" + "$0$&$1$&$1$&$0$&$0$\\\\\n" + "$1$&$0$&$0$&$0$&$0$\\\\\n" + "$1$&$0$&$1$&$0$&$0$\\\\\n" + "$1$&$1$&$0$&$0$&$0$\\\\\n" + "$1$&$1$&$1$&$0$&$0$\\\\\n" + "\\end{tabular}\n" + "\\end{center}\n", new TruthTableFormatterLaTeX().format(tt));
}
use of de.neemann.digital.analyse.TruthTable in project Digital by hneemann.
the class CircuitBuilderTest method testBus.
public void testBus() throws Exception {
final ToBreakRunner runner = new ToBreakRunner("dig/circuitBuilder/busTest.dig", false);
// create truth table incl. ModelAnalyzerInfo
TruthTable tt = new ModelAnalyser(runner.getModel()).analyse();
assertEquals(8, tt.getVars().size());
assertEquals(8, tt.getResultCount());
// create expressions based on truth table
ExpressionListenerStore expr = new ExpressionListenerStore(null);
new ExpressionCreator(tt).create(expr);
// build a new circuit
CircuitBuilder circuitBuilder = new CircuitBuilder(runner.getLibrary().getShapeFactory(), false, tt.getVars()).setModelAnalyzerInfo(tt.getModelAnalyzerInfo());
new BuilderExpressionCreator(circuitBuilder).create(expr);
Circuit circuit = circuitBuilder.createCircuit();
// check
List<VisualElement> in = circuit.findElements(v -> v.equalsDescription(In.DESCRIPTION));
assertEquals(2, in.size());
checkPin(in.get(0), "A", "1,2,3,4");
checkPin(in.get(1), "B", "5,6,7,8");
List<VisualElement> out = circuit.findElements(v -> v.equalsDescription(Out.DESCRIPTION));
assertEquals(2, out.size());
checkPin(out.get(0), "S", "9,10,11,12");
checkPin(out.get(1), "U", "13,14,15,16");
}
Aggregations