Search in sources :

Example 41 with Model

use of de.neemann.digital.core.Model 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 42 with Model

use of de.neemann.digital.core.Model in project Digital by hneemann.

the class TestResultTest method testResultDontCareInput2.

public void testResultDontCareInput2() throws Exception {
    Model model = getModel("A*0+B*0+C");
    TestCaseDescription data = new TestCaseDescription("A B C Y\n" + "x x 0 0\n" + "x x 1 1\n");
    TestExecutor te = new TestExecutor(data).create(model);
    ValueTable tr = te.getResult();
    assertEquals(8, tr.getRows());
    assertTrue(te.allPassed());
}
Also used : ValueTable(de.neemann.digital.data.ValueTable) Model(de.neemann.digital.core.Model)

Example 43 with Model

use of de.neemann.digital.core.Model in project Digital by hneemann.

the class TestResultTest method testResultDontCareInput.

public void testResultDontCareInput() throws Exception {
    Model model = getModel("A*0+B");
    TestCaseDescription data = new TestCaseDescription("A B Y\n" + "x 0 0\n" + "x 1 1\n");
    TestExecutor te = new TestExecutor(data).create(model);
    ValueTable tr = te.getResult();
    assertEquals(4, tr.getRows());
    assertTrue(te.allPassed());
}
Also used : ValueTable(de.neemann.digital.data.ValueTable) Model(de.neemann.digital.core.Model)

Example 44 with Model

use of de.neemann.digital.core.Model in project Digital by hneemann.

the class TestResultTest method getModel.

private Model getModel(String func) throws IOException, ParseException, BuilderException, PinException, NodeException, ElementNotFoundException {
    ArrayList<Expression> exp = new Parser(func).parse();
    ElementLibrary library = new ElementLibrary();
    CircuitBuilder cb = new CircuitBuilder(new ShapeFactory(library));
    cb.addCombinatorial("Y", exp.get(0));
    Circuit circ = cb.createCircuit();
    Model model = new ModelCreator(circ, library).createModel(false);
    model.init();
    return model;
}
Also used : ElementLibrary(de.neemann.digital.draw.library.ElementLibrary) Expression(de.neemann.digital.analyse.expression.Expression) Model(de.neemann.digital.core.Model) ShapeFactory(de.neemann.digital.draw.shapes.ShapeFactory) Circuit(de.neemann.digital.draw.elements.Circuit) ModelCreator(de.neemann.digital.draw.model.ModelCreator) Parser(de.neemann.digital.analyse.parser.Parser) CircuitBuilder(de.neemann.digital.builder.circuit.CircuitBuilder)

Example 45 with Model

use of de.neemann.digital.core.Model in project Digital by hneemann.

the class FlipFlopsTest method testFlipFlopJKMS.

public void testFlipFlopJKMS() throws Exception {
    ObservableValue j = new ObservableValue("j", 1);
    ObservableValue k = new ObservableValue("k", 1);
    ObservableValue c = new ObservableValue("c", 1);
    ElementAttributes attr = new ElementAttributes().setBits(1);
    Model model = new Model();
    FanIn nor3 = model.add(new NOr(attr));
    FanIn nor4 = model.add(new NOr(attr));
    FanIn a1 = model.add(new And(attr));
    a1.setInputs(ovs(j, c, nor4.getOutput()));
    FanIn a2 = model.add(new And(attr));
    a2.setInputs(ovs(k, c, nor3.getOutput()));
    Not not = model.add(new Not(attr));
    not.setInputs(c.asList());
    FanIn nor1 = model.add(new NOr(attr));
    FanIn nor2 = model.add(new NOr(attr));
    nor1.setInputs(ovs(a1.getOutput(), nor2.getOutput()));
    nor2.setInputs(ovs(a2.getOutput(), nor1.getOutput()));
    FanIn a3 = model.add(new And(attr));
    a3.setInputs(ovs(nor1.getOutput(), not.getOutputs().get(0)));
    FanIn a4 = model.add(new And(attr));
    a4.setInputs(ovs(nor2.getOutput(), not.getOutputs().get(0)));
    nor3.setInputs(ovs(a3.getOutput(), nor4.getOutput()));
    nor4.setInputs(ovs(a4.getOutput(), nor3.getOutput()));
    TestExecuter sc = new TestExecuter(model, true).setInputs(c, j, k).setOutputs(nor3.getOutput(), nor4.getOutput());
    // undefined
    sc.checkZ(0, 1, 0, IGNORE, IGNORE);
    // undefined
    sc.checkZ(1, 1, 0, IGNORE, IGNORE);
    sc.check(0, 1, 0, 1, 0);
    sc.check(0, 0, 0, 1, 0);
    sc.check(1, 0, 0, 1, 0);
    sc.check(0, 1, 0, 1, 0);
    sc.check(1, 1, 0, 1, 0);
    sc.check(0, 0, 0, 1, 0);
    sc.check(1, 0, 0, 1, 0);
    sc.check(0, 0, 1, 1, 0);
    sc.check(1, 0, 1, 1, 0);
    sc.check(0, 0, 1, 0, 1);
    sc.check(0, 1, 1, 0, 1);
    sc.check(1, 1, 1, 0, 1);
    sc.check(0, 1, 1, 1, 0);
    sc.check(1, 1, 1, 1, 0);
    sc.check(0, 1, 1, 0, 1);
    sc.check(1, 1, 1, 0, 1);
    sc.check(0, 1, 1, 1, 0);
    sc.check(1, 1, 1, 1, 0);
    sc.check(0, 1, 1, 0, 1);
}
Also used : ObservableValue(de.neemann.digital.core.ObservableValue) Model(de.neemann.digital.core.Model) ElementAttributes(de.neemann.digital.core.element.ElementAttributes)

Aggregations

Model (de.neemann.digital.core.Model)85 ObservableValue (de.neemann.digital.core.ObservableValue)56 ElementAttributes (de.neemann.digital.core.element.ElementAttributes)52 TestExecuter (de.neemann.digital.TestExecuter)49 ToBreakRunner (de.neemann.digital.integration.ToBreakRunner)16 ValueTable (de.neemann.digital.data.ValueTable)6 Signal (de.neemann.digital.core.Signal)4 ModelCreator (de.neemann.digital.draw.model.ModelCreator)4 ObservableValues (de.neemann.digital.core.ObservableValues)3 Expression (de.neemann.digital.analyse.expression.Expression)2 BoolTable (de.neemann.digital.analyse.quinemc.BoolTable)2 Node (de.neemann.digital.core.Node)2 Delay (de.neemann.digital.core.wiring.Delay)2 Circuit (de.neemann.digital.draw.elements.Circuit)2 ElementLibrary (de.neemann.digital.draw.library.ElementLibrary)2 ShapeFactory (de.neemann.digital.draw.shapes.ShapeFactory)2 File (java.io.File)2 ArrayList (java.util.ArrayList)2 Variable (de.neemann.digital.analyse.expression.Variable)1 Parser (de.neemann.digital.analyse.parser.Parser)1