use of de.neemann.digital.core.ObservableValue in project Digital by hneemann.
the class TestTrans method testTrans.
public void testTrans() throws Exception {
Model model = new ToBreakRunner("dig/test/transp/transtest3.dig").getModel();
assertEquals(2, model.getInputs().size());
assertEquals(1, model.getOutputs().size());
assertEquals(1, model.getNodes().size());
Node node = model.getNodes().get(0);
assertTrue(node instanceof XOr);
XOr xor = (XOr) node;
// The models inputs are the xor input values!
// All the intermediate transparent stuff is removed!
ArrayList<ObservableValue> ins = new ArrayList<>();
for (Signal s : model.getInputs()) ins.add(s.getValue());
assertTrue(ins.contains(xor.getInputs().get(0)));
assertTrue(ins.contains(xor.getInputs().get(1)));
}
use of de.neemann.digital.core.ObservableValue in project Digital by hneemann.
the class CircuitComponent method actualToDefault.
/**
* Makes actual input values to the default value
*/
public void actualToDefault() {
if (!isLocked()) {
Modifications.Builder builder = new Modifications.Builder(Lang.get("menu_actualToDefault"));
for (VisualElement ve : circuit.getElements()) if (ve.equalsDescription(In.DESCRIPTION)) {
ObservableValue ov = ((InputShape) ve.getShape()).getObservableValue();
if (ov != null) {
InValue newValue = new InValue(ov);
InValue oldValue = ve.getElementAttributes().get(Keys.INPUT_DEFAULT);
if (!newValue.equals(oldValue))
builder.add(new ModifyAttribute<>(ve, Keys.INPUT_DEFAULT, newValue));
}
}
modify(builder.build());
}
}
use of de.neemann.digital.core.ObservableValue 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.ObservableValue 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.ObservableValue 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));
}
Aggregations