use of de.neemann.digital.core.ObservableValue in project Digital by hneemann.
the class Splitter2Test method testBits.
public void testBits() throws Exception {
ObservableValue a = new ObservableValue("a", 4);
Splitter splitter = new Splitter(new ElementAttributes().set(Keys.INPUT_SPLIT, "4").set(Keys.OUTPUT_SPLIT, "1,1,1,1"));
splitter.setInputs(a.asList());
assertEquals(4, a.observerCount());
ObservableValues outputs = splitter.getOutputs();
assertEquals(4, outputs.size());
TestExecuter sc = new TestExecuter().setInputs(a).setOutputsOf(splitter);
sc.check(0, 0, 0, 0, 0);
sc.check(1, 1, 0, 0, 0);
sc.check(2, 0, 1, 0, 0);
sc.check(4, 0, 0, 1, 0);
sc.check(8, 0, 0, 0, 1);
sc.check(15, 1, 1, 1, 1);
}
use of de.neemann.digital.core.ObservableValue in project Digital by hneemann.
the class Splitter64BitTest method test64Bit2.
public void test64Bit2() throws NodeException, PinException {
ObservableValue a = new ObservableValue("a", 64);
Splitter splitter = new Splitter(new ElementAttributes().set(Keys.INPUT_SPLIT, "64").set(Keys.OUTPUT_SPLIT, "16,16,16,16"));
splitter.setInputs(ovs(a));
ObservableValues outputs = splitter.getOutputs();
assertEquals(4, outputs.size());
TestExecuter sc = new TestExecuter().setInputs(a).setOutputsOf(splitter);
sc.check(0x0, 0x0, 0x0, 0x0, 0x0);
sc.check(-1, 0xffff, 0xffff, 0xffff, 0xffff);
sc.check(0xffffffffffffffffL, 0xffff, 0xffff, 0xffff, 0xffff);
sc.check(0xffffffffffff0000L, 0, 0xffff, 0xffff, 0xffff);
sc.check(0xffffffff0000ffffL, 0xffff, 0, 0xffff, 0xffff);
sc.check(0xffff0000ffffffffL, 0xffff, 0xffff, 0, 0xffff);
sc.check(0x0000ffffffffffffL, 0xffff, 0xffff, 0xffff, 0);
}
use of de.neemann.digital.core.ObservableValue in project Digital by hneemann.
the class FlipflopRSAsyncTest method testFlipFlop.
public void testFlipFlop() throws Exception {
ObservableValue s = new ObservableValue("s", 1);
ObservableValue r = new ObservableValue("r", 1);
Model model = new Model();
FlipflopRSAsync out = model.add(new FlipflopRSAsync(new ElementAttributes()));
out.setInputs(ovs(s, r));
TestExecuter sc = new TestExecuter(model).setInputs(s, r).setOutputs(out.getOutputs());
// S R Q ~Q
sc.check(0, 0, 0, 1);
sc.check(1, 0, 1, 0);
sc.check(0, 0, 1, 0);
sc.check(0, 1, 0, 1);
sc.check(0, 0, 0, 1);
sc.check(1, 1, 1, 1);
sc.check(1, 0, 1, 0);
sc.check(1, 1, 1, 1);
sc.check(0, 1, 0, 1);
ObservableValue q = out.getOutputs().get(0);
ObservableValue qn = out.getOutputs().get(1);
for (int i = 0; i < 100; i++) {
s.setValue(1);
r.setValue(1);
model.doStep();
assertTrue(q.getBool());
assertTrue(qn.getBool());
s.setValue(0);
r.setValue(0);
model.doStep();
assertTrue(q.getBool() ^ qn.getBool());
}
}
use of de.neemann.digital.core.ObservableValue in project Digital by hneemann.
the class FlipflopRSTest method testFlipFlop.
public void testFlipFlop() throws Exception {
ObservableValue s = new ObservableValue("s", 1);
ObservableValue c = new ObservableValue("c", 1);
ObservableValue r = new ObservableValue("r", 1);
Model model = new Model();
FlipflopRS out = model.add(new FlipflopRS(new ElementAttributes()));
out.setInputs(ovs(s, c, r));
TestExecuter sc = new TestExecuter(model).setInputs(s, c, r).setOutputs(out.getOutputs());
// S C R Q ~Q
sc.check(0, 0, 0, 0, 1);
sc.check(1, 0, 0, 0, 1);
sc.check(0, 1, 0, 0, 1);
sc.check(1, 0, 0, 0, 1);
sc.check(1, 1, 0, 1, 0);
sc.check(1, 0, 0, 1, 0);
sc.check(0, 1, 1, 0, 1);
sc.check(0, 0, 1, 0, 1);
ObservableValue q = out.getOutputs().get(0);
ObservableValue qn = out.getOutputs().get(1);
s.setValue(1);
r.setValue(1);
for (int i = 0; i < 100; i++) {
c.setValue(1);
model.doStep();
final boolean qBool = q.getBool();
final boolean qnBool = qn.getBool();
assertTrue(qBool ^ qnBool);
c.setValue(0);
model.doStep();
assertEquals(qBool, q.getBool());
assertEquals(qnBool, qn.getBool());
}
}
use of de.neemann.digital.core.ObservableValue in project Digital by hneemann.
the class NAndTest method testAnd.
public void testAnd() throws Exception {
ObservableValue a = new ObservableValue("a", 1);
ObservableValue b = new ObservableValue("b", 1);
Model model = new Model();
FanIn out = model.add(new NAnd(new ElementAttributes().setBits(1)));
out.setInputs(ovs(a, b));
TestExecuter sc = new TestExecuter(model).setInputs(a, b).setOutputs(out.getOutputs());
sc.check(0, 0, 1);
sc.check(1, 0, 1);
sc.check(0, 1, 1);
sc.check(1, 1, 0);
sc.check(1, 0, 1);
sc.check(0, 1, 1);
}
Aggregations