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);
}
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());
}
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());
}
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;
}
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);
}
Aggregations