Search in sources :

Example 6 with TruthTable

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());
}
Also used : BoolTableByteArray(de.neemann.digital.analyse.quinemc.BoolTableByteArray) TruthTable(de.neemann.digital.analyse.TruthTable)

Example 7 with TruthTable

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());
}
Also used : BoolTableByteArray(de.neemann.digital.analyse.quinemc.BoolTableByteArray) BoolTable(de.neemann.digital.analyse.quinemc.BoolTable) TruthTable(de.neemann.digital.analyse.TruthTable)

Example 8 with TruthTable

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());
}
Also used : ModelAnalyser(de.neemann.digital.analyse.ModelAnalyser) ElementNotFoundException(de.neemann.digital.draw.library.ElementNotFoundException) AnalyseException(de.neemann.digital.analyse.AnalyseException) ModelCreator(de.neemann.digital.draw.model.ModelCreator) TableDialog(de.neemann.digital.gui.components.table.TableDialog) ValueTableDialog(de.neemann.digital.gui.components.testing.ValueTableDialog) TruthTable(de.neemann.digital.analyse.TruthTable) LibraryTreeModel(de.neemann.digital.gui.components.tree.LibraryTreeModel) ExpressionDialog(de.neemann.digital.gui.components.expression.ExpressionDialog)

Example 9 with TruthTable

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));
}
Also used : TruthTable(de.neemann.digital.analyse.TruthTable)

Example 10 with TruthTable

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");
}
Also used : ModelAnalyser(de.neemann.digital.analyse.ModelAnalyser) TruthTable(de.neemann.digital.analyse.TruthTable) ToBreakRunner(de.neemann.digital.integration.ToBreakRunner) Circuit(de.neemann.digital.draw.elements.Circuit) VisualElement(de.neemann.digital.draw.elements.VisualElement) BuilderExpressionCreator(de.neemann.digital.gui.components.table.BuilderExpressionCreator) ExpressionListenerStore(de.neemann.digital.gui.components.table.ExpressionListenerStore) ExpressionCreator(de.neemann.digital.gui.components.table.ExpressionCreator) BuilderExpressionCreator(de.neemann.digital.gui.components.table.BuilderExpressionCreator)

Aggregations

TruthTable (de.neemann.digital.analyse.TruthTable)13 BoolTableByteArray (de.neemann.digital.analyse.quinemc.BoolTableByteArray)5 TruthTableTableModel (de.neemann.digital.analyse.TruthTableTableModel)4 ModelAnalyser (de.neemann.digital.analyse.ModelAnalyser)3 ContextFiller (de.neemann.digital.analyse.expression.ContextFiller)3 ExpressionException (de.neemann.digital.analyse.expression.ExpressionException)3 Variable (de.neemann.digital.analyse.expression.Variable)3 BoolTable (de.neemann.digital.analyse.quinemc.BoolTable)3 AnalyseException (de.neemann.digital.analyse.AnalyseException)2 Circuit (de.neemann.digital.draw.elements.Circuit)2 ArrayList (java.util.ArrayList)2 Expression (de.neemann.digital.analyse.expression.Expression)1 FormatToExpression (de.neemann.digital.analyse.expression.format.FormatToExpression)1 FormatToTableLatex (de.neemann.digital.analyse.expression.format.FormatToTableLatex)1 FormatterException (de.neemann.digital.analyse.expression.format.FormatterException)1 ExpressionModifier (de.neemann.digital.analyse.expression.modify.ExpressionModifier)1 NAnd (de.neemann.digital.analyse.expression.modify.NAnd)1 NOr (de.neemann.digital.analyse.expression.modify.NOr)1 TwoInputs (de.neemann.digital.analyse.expression.modify.TwoInputs)1 TruthTableFormatterLaTeX (de.neemann.digital.analyse.format.TruthTableFormatterLaTeX)1