Search in sources :

Example 31 with Variable

use of de.neemann.digital.analyse.expression.Variable in project Digital by hneemann.

the class FormatToExpressionTest method testFormatNamesExp.

public void testFormatNamesExp() throws Exception {
    Variable a = v("A");
    Variable b = v("B");
    Expression e = and(a, b);
    NamedExpression n = new NamedExpression("U", e);
    assertEquals("U = A ∧ B", FormatToExpression.FORMATTER_UNICODE.format(n));
    n = new NamedExpression("V", n);
    assertEquals("V = U = A ∧ B", FormatToExpression.FORMATTER_UNICODE.format(n));
}
Also used : Variable(de.neemann.digital.analyse.expression.Variable) Expression(de.neemann.digital.analyse.expression.Expression) NamedExpression(de.neemann.digital.analyse.expression.NamedExpression) NamedExpression(de.neemann.digital.analyse.expression.NamedExpression)

Example 32 with Variable

use of de.neemann.digital.analyse.expression.Variable in project Digital by hneemann.

the class FormatToExpressionTest method testFormatExpLaTeX.

public void testFormatExpLaTeX() throws Exception {
    Variable a = new Variable("A_n");
    Variable b = new Variable("B_n");
    Expression e = new NamedExpression("Y_n+1", and(a, not(b)));
    assertEquals("Y_{n+1} = A_{n} \\und \\nicht{B_{n}}", FormatToExpression.FORMATTER_LATEX.format(e));
}
Also used : Variable(de.neemann.digital.analyse.expression.Variable) Expression(de.neemann.digital.analyse.expression.Expression) NamedExpression(de.neemann.digital.analyse.expression.NamedExpression) NamedExpression(de.neemann.digital.analyse.expression.NamedExpression)

Example 33 with Variable

use of de.neemann.digital.analyse.expression.Variable in project Digital by hneemann.

the class MinimizerRegressionTest method performTestCalculation.

/**
 * Generates a expression from the table and then checks if
 * the expression reproduces the given table.
 * Does not test if the expression is minimal.
 *
 * @param n   the number of variables
 * @param tab the truth table
 * @throws ExpressionException
 */
private static void performTestCalculation(int n, byte[] tab, MinimizerInterface minimizer) throws ExpressionException, FormatterException {
    ArrayList<Variable> v = vars(n);
    final ExpressionListenerStore listener = new ExpressionListenerStore(null);
    minimizer.minimize(v, new BoolTableByteArray(tab), "Y", listener);
    Expression e = listener.getFirst();
    assertNotNull(e);
    ContextFiller context = new ContextFiller(v);
    for (int i = 0; i < tab.length; i++) {
        if (tab[i] <= 1)
            assertEquals(tab[i] == 1, e.calculate(context.setContextTo(i)));
    }
}
Also used : Variable(de.neemann.digital.analyse.expression.Variable) Expression(de.neemann.digital.analyse.expression.Expression) ContextFiller(de.neemann.digital.analyse.expression.ContextFiller) ExpressionListenerStore(de.neemann.digital.gui.components.table.ExpressionListenerStore)

Example 34 with Variable

use of de.neemann.digital.analyse.expression.Variable in project Digital by hneemann.

the class TruthTableTest method testGetByContext.

public void testGetByContext() throws Exception {
    ArrayList<Variable> vars = Variable.vars(5);
    TruthTable t = new TruthTable(vars).addResult();
    BoolTableByteArray result = (BoolTableByteArray) t.getResult(0);
    for (int i = 0; i < t.getRows(); i++) {
        result.set(i, i % 3);
    }
    ContextFiller fc = new ContextFiller(vars);
    for (int i = 0; i < t.getRows(); i++) {
        fc.setContextTo(i);
        assertEquals(i % 3, t.getByContext(0, fc));
    }
}
Also used : Variable(de.neemann.digital.analyse.expression.Variable) BoolTableByteArray(de.neemann.digital.analyse.quinemc.BoolTableByteArray) ContextFiller(de.neemann.digital.analyse.expression.ContextFiller)

Example 35 with Variable

use of de.neemann.digital.analyse.expression.Variable in project Digital by hneemann.

the class TruthTableTest method testHexExportTwo.

public void testHexExportTwo() throws Exception {
    ArrayList<Variable> vars = Variable.vars(3);
    TruthTable t = new TruthTable(vars).addResult();
    BoolTableByteArray result = (BoolTableByteArray) t.getResult(0);
    for (int i = 0; i < t.getRows(); i++) {
        result.set(i, i % 2);
    }
    t.addResult();
    result = (BoolTableByteArray) t.getResult(1);
    for (int i = 0; i < t.getRows(); i++) {
        result.set(i, (i + 1) % 2);
    }
    StringWriter w = new StringWriter();
    t.saveHex(w);
    w.close();
    assertEquals("v2.0 raw\n" + "2\n" + "1\n" + "2\n" + "1\n" + "2\n" + "1\n" + "2\n" + "1\n", w.toString());
}
Also used : Variable(de.neemann.digital.analyse.expression.Variable) BoolTableByteArray(de.neemann.digital.analyse.quinemc.BoolTableByteArray) StringWriter(java.io.StringWriter)

Aggregations

Variable (de.neemann.digital.analyse.expression.Variable)51 Expression (de.neemann.digital.analyse.expression.Expression)34 ContextFiller (de.neemann.digital.analyse.expression.ContextFiller)10 NamedExpression (de.neemann.digital.analyse.expression.NamedExpression)8 ArrayList (java.util.ArrayList)8 ByteArrayOutputStream (java.io.ByteArrayOutputStream)7 BoolTableByteArray (de.neemann.digital.analyse.quinemc.BoolTableByteArray)6 FormatToExpression (de.neemann.digital.analyse.expression.format.FormatToExpression)5 TestExecuter (de.neemann.digital.TestExecuter)4 Circuit (de.neemann.digital.draw.elements.Circuit)4 ElementLibrary (de.neemann.digital.draw.library.ElementLibrary)4 ModelCreator (de.neemann.digital.draw.model.ModelCreator)4 ShapeFactory (de.neemann.digital.draw.shapes.ShapeFactory)4 ExpressionException (de.neemann.digital.analyse.expression.ExpressionException)3 BoolTable (de.neemann.digital.analyse.quinemc.BoolTable)3 TableReducer (de.neemann.digital.analyse.quinemc.TableReducer)3 TruthTable (de.neemann.digital.analyse.TruthTable)2 FormatterException (de.neemann.digital.analyse.expression.format.FormatterException)2 FuseMapFillerException (de.neemann.digital.builder.jedec.FuseMapFillerException)2 JedecWriter (de.neemann.digital.builder.jedec.JedecWriter)2