use of de.neemann.digital.core.ObservableValues in project Digital by hneemann.
the class Multiplexer method setInputs.
@Override
public void setInputs(ObservableValues inputs) throws NodeException {
selector = inputs.get(0).addObserverToValue(this).checkBits(selectorBits, this);
ObservableValues in = new ObservableValues(inputs, 1, inputs.size());
super.setInputs(in);
if (in.size() != (1 << selectorBits))
throw new BitsException(Lang.get("err_selectorInputCountMismatch"), this, -1, selector);
}
use of de.neemann.digital.core.ObservableValues in project Digital by hneemann.
the class PortsTest method testPortsSimple.
public void testPortsSimple() throws Exception {
Splitter.Ports p = new Splitter.Ports("1,2,1,4");
ObservableValues outs = p.getOutputs();
assertEquals(4, outs.size());
assertEquals(1, outs.get(0).getBits());
assertEquals(2, outs.get(1).getBits());
assertEquals(1, outs.get(2).getBits());
assertEquals(4, outs.get(3).getBits());
}
use of de.neemann.digital.core.ObservableValues in project Digital by hneemann.
the class Splitter1Test method testMoreBits.
public void testMoreBits() throws Exception {
ObservableValue a = new ObservableValue("a", 4);
ObservableValue b = new ObservableValue("b", 4);
ObservableValue c = new ObservableValue("c", 4);
ObservableValue d = new ObservableValue("d", 4);
Splitter splitter = new Splitter(new ElementAttributes().set(Keys.INPUT_SPLIT, "4,4,4,4").set(Keys.OUTPUT_SPLIT, "16"));
splitter.setInputs(ovs(a, b, c, d));
assertEquals(1, a.observerCount());
assertEquals(1, b.observerCount());
assertEquals(1, c.observerCount());
assertEquals(1, d.observerCount());
ObservableValues outputs = splitter.getOutputs();
assertEquals(1, outputs.size());
TestExecuter sc = new TestExecuter().setInputs(d, c, b, a).setOutputsOf(splitter);
sc.check(0, 0, 0, 0, 0x0000);
sc.check(0, 0, 0, 1, 0x0001);
sc.check(0, 0, 1, 0, 0x0010);
sc.check(0, 1, 0, 0, 0x0100);
sc.check(1, 0, 0, 0, 0x1000);
sc.check(0, 0, 0, 15, 0x000F);
sc.check(0, 0, 15, 0, 0x00F0);
sc.check(0, 15, 0, 0, 0x0F00);
sc.check(15, 0, 0, 0, 0xF000);
}
use of de.neemann.digital.core.ObservableValues in project Digital by hneemann.
the class Splitter1Test method testBits.
public void testBits() throws Exception {
ObservableValue a = new ObservableValue("a", 1);
ObservableValue b = new ObservableValue("b", 1);
ObservableValue c = new ObservableValue("c", 1);
ObservableValue d = new ObservableValue("d", 1);
Splitter splitter = new Splitter(new ElementAttributes().set(Keys.INPUT_SPLIT, "1,1,1,1").set(Keys.OUTPUT_SPLIT, "4"));
splitter.setInputs(ovs(a, b, c, d));
assertEquals(1, a.observerCount());
assertEquals(1, b.observerCount());
assertEquals(1, c.observerCount());
assertEquals(1, d.observerCount());
ObservableValues outputs = splitter.getOutputs();
assertEquals(1, outputs.size());
TestExecuter sc = new TestExecuter().setInputs(a, b, c, d).setOutputsOf(splitter);
sc.check(0, 0, 0, 0, 0);
sc.check(1, 0, 0, 0, 1);
sc.check(0, 1, 0, 0, 2);
sc.check(0, 0, 1, 0, 4);
sc.check(0, 0, 0, 1, 8);
sc.check(1, 1, 0, 0, 3);
sc.check(1, 1, 1, 0, 7);
sc.check(1, 1, 1, 1, 15);
sc.check(0, 0, 1, 1, 12);
sc.check(0, 1, 1, 1, 14);
}
use of de.neemann.digital.core.ObservableValues 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);
}
Aggregations