Search in sources :

Example 36 with Variable

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

the class TruthTableTest method testHexExportSingle.

public void testHexExportSingle() 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);
    }
    StringWriter w = new StringWriter();
    t.saveHex(w);
    w.close();
    assertEquals("v2.0 raw\n" + "0\n" + "1\n" + "0\n" + "1\n" + "0\n" + "1\n" + "0\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)

Example 37 with Variable

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

the class SimplifyTest method testSimplify.

public void testSimplify() throws Exception, FormatterException {
    Variable a = v("a");
    Variable b = v("b");
    Expression e = or(and(a, b), a);
    Expression s = QuineMcCluskey.simplify(e);
    assertEquals("a", FormatToExpression.FORMATTER_UNICODE.format(s));
}
Also used : Variable(de.neemann.digital.analyse.expression.Variable) FormatToExpression(de.neemann.digital.analyse.expression.format.FormatToExpression) Expression(de.neemann.digital.analyse.expression.Expression)

Example 38 with Variable

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

the class SimplifyTest method testSimplify3.

public void testSimplify3() throws Exception {
    Variable a = v("a");
    Variable b = v("b");
    Variable c = v("c");
    Expression e = and(or(a, b), c);
    Expression s = QuineMcCluskey.simplify(e);
    assertTrue(s == e);
}
Also used : Variable(de.neemann.digital.analyse.expression.Variable) FormatToExpression(de.neemann.digital.analyse.expression.format.FormatToExpression) Expression(de.neemann.digital.analyse.expression.Expression)

Example 39 with Variable

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

the class BruteForceGetAllTest method performTestCalculation.

/*
    public void testFull() throws ExpressionException, FormatterException {
        new FullVariantDontCareCreator(4) {
            @Override
            public void handleTable(int n, int[] tab) throws ExpressionException {
                performTestCalculation(n, tab);
            }
        }.create();
    } /**/
private static void performTestCalculation(int n, byte[] tab) throws ExpressionException {
    BruteForceGetAll ps = new BruteForceGetAll();
    ArrayList<Variable> v = vars(n);
    new QuineMcCluskey(v).fillTableWith(new BoolTableByteArray(tab)).simplify(ps);
    ArrayList<ArrayList<TableRow>> solutions = ps.getAllSolutions();
    if (solutions != null) {
        for (ArrayList<TableRow> sol : solutions) {
            Expression e = QuineMcCluskey.addAnd(null, sol, v);
            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 : QuineMcCluskey(de.neemann.digital.analyse.quinemc.QuineMcCluskey) Variable(de.neemann.digital.analyse.expression.Variable) BoolTableByteArray(de.neemann.digital.analyse.quinemc.BoolTableByteArray) Expression(de.neemann.digital.analyse.expression.Expression) ContextFiller(de.neemann.digital.analyse.expression.ContextFiller) TableRow(de.neemann.digital.analyse.quinemc.TableRow) ArrayList(java.util.ArrayList)

Example 40 with Variable

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

the class Gal16V8CuplExporterTest method testCUPLExporter.

public void testCUPLExporter() throws Exception {
    Variable y0 = new Variable("Y_0");
    Variable y1 = new Variable("Y_1");
    // counter
    Expression y0s = not(y0);
    Expression y1s = or(and(not(y0), y1), and(y0, not(y1)));
    CuplExporter ce = new CuplExporter("user", null).setProjectName("test");
    ce.getPinMapping().parseString("Y_0=12;Y_1=13;A=14");
    ce.getBuilder().addSequential("Y_0", y0s).addSequential("Y_1", y1s).addCombinatorial("A", and(y0, y1));
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ce.writeTo(baos);
    assertEquals("Name     test ;\r\n" + "PartNo   00 ;\r\n" + "Date     unknownDate ;\r\n" + "Revision 01 ;\r\n" + "Designer user ;\r\n" + "Company  unknown ;\r\n" + "Assembly None ;\r\n" + "Location unknown ;\r\n" + "Device   g16v8a ;\r\n" + "\r\n" + "/* inputs */\r\n" + "PIN 1 = CLK;\r\n" + "\r\n" + "/* outputs */\r\n" + "PIN 12 = Y_0;\r\n" + "PIN 13 = Y_1;\r\n" + "PIN 14 = A;\r\n" + "\r\n" + "/* sequential logic */\r\n" + "Y_0.D = !Y_0;\r\n" + "Y_1.D = (!Y_0 & Y_1) # (Y_0 & !Y_1);\r\n" + "\r\n" + "/* combinatorial logic */\r\n" + "A = Y_0 & Y_1;\r\n", baos.toString());
}
Also used : Variable(de.neemann.digital.analyse.expression.Variable) Expression(de.neemann.digital.analyse.expression.Expression) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

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