Search in sources :

Example 21 with Variable

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

the class CircuitBuilderTest method testBuilderSequentialJK_JequalsK.

public void testBuilderSequentialJK_JequalsK() 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)));
    ElementLibrary library = new ElementLibrary();
    Circuit circuit = new CircuitBuilder(new ShapeFactory(library), true).addSequential("Y_0", y0s).addSequential("Y_1", y1s).createCircuit();
    ModelCreator m = new ModelCreator(circuit, library);
    TestExecuter te = new TestExecuter(m.createModel(false)).setUp(m);
    te.check(0, 0);
    te.checkC(1, 0);
    te.checkC(0, 1);
    te.checkC(1, 1);
    te.checkC(0, 0);
}
Also used : ElementLibrary(de.neemann.digital.draw.library.ElementLibrary) Variable(de.neemann.digital.analyse.expression.Variable) Expression(de.neemann.digital.analyse.expression.Expression) ShapeFactory(de.neemann.digital.draw.shapes.ShapeFactory) Circuit(de.neemann.digital.draw.elements.Circuit) TestExecuter(de.neemann.digital.TestExecuter) ModelCreator(de.neemann.digital.draw.model.ModelCreator)

Example 22 with Variable

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

the class FuseMapFillerTest method testFillExpression.

public void testFillExpression() throws Exception {
    FuseMap fuseMap = new FuseMap(16);
    Variable a = new Variable("A");
    Variable b = new Variable("B");
    Variable c = new Variable("C");
    Variable d = new Variable("D");
    Expression e = or(and(a, b, c, d), and(not(a), not(b), not(c), not(d)));
    new FuseMapFiller(fuseMap, 4).addVariable(0, a).addVariable(1, b).addVariable(2, c).addVariable(3, d).fillExpression(0, e, 2);
    byte[] data = fuseMap.getFuseData();
    assertEquals(0xAA, data[0] & 0xff);
    assertEquals(0x55, data[1] & 0xff);
}
Also used : Variable(de.neemann.digital.analyse.expression.Variable) Expression(de.neemann.digital.analyse.expression.Expression)

Example 23 with Variable

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

the class KarnaughMapTest method testBUG_1.

// in 4x4 map a 8 cell block is drawn in wrong orientation
public void testBUG_1() throws IOException, ParseException, KarnaughException {
    Expression exp = new Variable("D");
    KarnaughMap c = new KarnaughMap(Variable.vars(4), exp);
    assertEquals(1, c.size());
    KarnaughMap.Cover co = c.iterator().next();
    assertTrue(co.isDisconnected());
    assertFalse(co.onlyEdges());
    assertTrue(co.isVerticalDivided());
    exp = new Variable("B");
    c = new KarnaughMap(Variable.vars(4), exp);
    assertEquals(1, c.size());
    co = c.iterator().next();
    assertTrue(co.isDisconnected());
    assertFalse(co.onlyEdges());
    assertFalse(co.isVerticalDivided());
}
Also used : Variable(de.neemann.digital.analyse.expression.Variable) Expression(de.neemann.digital.analyse.expression.Expression)

Example 24 with Variable

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

the class BuilderExpressionCreatorTest method testSimple.

public void testSimple() throws FormatterException, ExpressionException, ElementNotFoundException, PinException, NodeException, AnalyseException, BacktrackException {
    Variable a = v("A");
    Variable b = v("B");
    Expression xor = or(and(a, not(b)), and(not(a), b));
    ExpressionListenerStore els = new ExpressionListenerStore(null);
    els.resultFound("xor", xor);
    els.close();
    Model m = create(els, ExpressionModifier.IDENTITY);
    assertEquals(5, m.size());
    assertEquals(2, m.findNode(And.class).size());
    assertEquals(1, m.findNode(Or.class).size());
    assertEquals(2, m.findNode(Not.class).size());
    check(m);
    m = create(els, new de.neemann.digital.analyse.expression.modify.NAnd());
    assertEquals(5, m.size());
    assertEquals(2, m.findNode(Not.class).size());
    assertEquals(3, m.findNode(NAnd.class).size());
    check(m);
    m = create(els, new de.neemann.digital.analyse.expression.modify.NOr());
    assertEquals(6, m.size());
    assertEquals(3, m.findNode(Not.class).size());
    assertEquals(3, m.findNode(NOr.class).size());
    check(m);
}
Also used : Variable(de.neemann.digital.analyse.expression.Variable) Expression(de.neemann.digital.analyse.expression.Expression) Model(de.neemann.digital.core.Model)

Example 25 with Variable

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

the class BoolTableExpandedTest method check.

private void check(BoolTableByteArray e, ArrayList<Signal> in1, ArrayList<Signal> in2, List<Variable> vars) {
    BoolTableExpanded bt = new BoolTableExpanded(e, in1, in2);
    TableReducer tr = new TableReducer(vars, bt);
    assertTrue(tr.canReduceOnlyCheckTable());
    List<Variable> v = tr.getVars();
    assertEquals(in1.size(), v.size());
    for (int i = 0; i < v.size(); i++) assertEquals(in1.get(i).getName(), v.get(i).getIdentifier());
    BoolTable t1 = tr.getTable();
    assertEquals(e.size(), t1.size());
    for (int r = 0; r < e.size(); r++) assertEquals(e.get(r), t1.get(r));
}
Also used : Variable(de.neemann.digital.analyse.expression.Variable) BoolTable(de.neemann.digital.analyse.quinemc.BoolTable) TableReducer(de.neemann.digital.analyse.quinemc.TableReducer)

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