use of de.neemann.digital.core.element.ElementAttributes 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);
}
use of de.neemann.digital.core.element.ElementAttributes in project Digital by hneemann.
the class FlipFlopsTest method testFlipFlopNAnd.
public void testFlipFlopNAnd() throws Exception {
ObservableValue r = new ObservableValue("r", 1);
ObservableValue s = new ObservableValue("s", 1);
Model model = new Model();
FanIn a1 = model.add(new NAnd(new ElementAttributes().setBits(1)));
FanIn a2 = model.add(new NAnd(new ElementAttributes().setBits(1)));
a1.setInputs(ovs(r, a2.getOutput()));
a2.setInputs(ovs(s, a1.getOutput()));
TestExecuter sc = new TestExecuter(model).setInputs(r, s).setOutputs(a1.getOutput(), a2.getOutput());
sc.check(1, 0, 0, 1);
sc.check(1, 1, 0, 1);
sc.check(0, 1, 1, 0);
sc.check(1, 1, 1, 0);
sc.check(1, 0, 0, 1);
}
use of de.neemann.digital.core.element.ElementAttributes in project Digital by hneemann.
the class FlipFlopsTest method testFlipFlopNOr.
public void testFlipFlopNOr() throws Exception {
ObservableValue r = new ObservableValue("r", 1);
ObservableValue s = new ObservableValue("s", 1);
Model model = new Model();
FanIn a1 = model.add(new NOr(new ElementAttributes().setBits(1)));
FanIn a2 = model.add(new NOr(new ElementAttributes().setBits(1)));
a1.setInputs(ovs(r, a2.getOutput()));
a2.setInputs(ovs(s, a1.getOutput()));
TestExecuter sc = new TestExecuter(model, true).setInputs(r, s).setOutputs(a1.getOutput(), a2.getOutput());
sc.check(0, 1, 1, 0);
sc.check(0, 0, 1, 0);
sc.check(1, 0, 0, 1);
sc.check(0, 0, 0, 1);
sc.check(0, 1, 1, 0);
// verbotener Zustand!!
sc.check(1, 1, 0, 0);
// gehe aus verbotenem Zustand raus!!!
r.setValue(0);
s.setValue(0);
// geht nur mit noise!
model.doStep(true);
assertTrue(// endzustand ist undefiniert!
(a1.getOutput().getValue() == 1 && a2.getOutput().getValue() == 0) || (a1.getOutput().getValue() == 0 && a2.getOutput().getValue() == 1));
}
use of de.neemann.digital.core.element.ElementAttributes in project Digital by hneemann.
the class DependencyAnalyserTest method testBacktrackCompleteness.
public void testBacktrackCompleteness() throws Exception {
ToBreakRunner toBreakRunner = new ToBreakRunner("dig/backtrack/AllComponents.dig", false);
// create a set of all components used in the circuit
Circuit circuit = toBreakRunner.getCircuit();
Set<String> set = new HashSet<>();
for (VisualElement e : circuit.getElements()) set.add(e.getElementName());
// ensure all available components are included in test circuit
for (ElementLibrary.ElementContainer c : toBreakRunner.getLibrary()) {
if (!set.contains(c.getDescription().getName())) {
// nodes with state are allowed to be missing
Element n = c.getDescription().createElement(new ElementAttributes());
boolean ok = (n instanceof Node) && ((Node) n).hasState();
assertTrue("component " + c.getDescription().getName() + " is missing in test/resources/dig/backtrack/AllComponents.dig!", ok);
}
}
// check if backtracking is ok at all components!
ModelAnalyser m = new ModelAnalyser(toBreakRunner.getModel());
new DependencyAnalyser(m);
}
use of de.neemann.digital.core.element.ElementAttributes in project Digital by hneemann.
the class SplitterMixTest method test2.
public void test2() throws Exception {
ObservableValue a = new ObservableValue("a", 8);
ObservableValue b = new ObservableValue("b", 8);
Splitter splitter = new Splitter(new ElementAttributes().set(Keys.INPUT_SPLIT, "8,8").set(Keys.OUTPUT_SPLIT, "12,4"));
splitter.setInputs(ovs(a, b));
assertEquals(1, a.observerCount());
assertEquals(2, b.observerCount());
ObservableValues outputs = splitter.getOutputs();
assertEquals(2, outputs.size());
TestExecuter sc = new TestExecuter().setInputs(a, b).setOutputsOf(splitter);
sc.check(0x00, 0x00, 0x000, 0x0);
sc.check(0x01, 0x00, 0x001, 0x0);
sc.check(0x10, 0x00, 0x010, 0x0);
sc.check(0x00, 0x01, 0x100, 0x0);
sc.check(0x00, 0x10, 0x000, 0x1);
sc.check(0x0f, 0x00, 0x00f, 0x0);
sc.check(0xf0, 0x00, 0x0f0, 0x0);
sc.check(0x00, 0x0f, 0xf00, 0x0);
sc.check(0x00, 0xf0, 0x000, 0xf);
sc.check(0xbc, 0xda, 0xabc, 0xd);
}
Aggregations