use of de.neemann.digital.core.ObservableValue in project Digital by hneemann.
the class AddTest method testAdd.
public void testAdd() throws Exception {
ObservableValue a = new ObservableValue("a", 4);
ObservableValue b = new ObservableValue("b", 4);
ObservableValue c = new ObservableValue("c", 1);
Model model = new Model();
Add node = new Add(new ElementAttributes().setBits(4));
node.setInputs(ovs(a, b, c));
model.add(node);
TestExecuter sc = new TestExecuter(model).setInputs(a, b, c).setOutputs(node.getOutputs());
sc.check(0, 0, 0, 0, 0);
sc.check(0, 0, 1, 1, 0);
sc.check(2, 3, 0, 5, 0);
sc.check(2, 3, 1, 6, 0);
sc.check(7, 7, 0, 14, 0);
sc.check(8, 8, 0, 0, 1);
sc.check(8, 8, 1, 1, 1);
}
use of de.neemann.digital.core.ObservableValue in project Digital by hneemann.
the class BarrelShifterTest method getTestExecuter.
private TestExecuter getTestExecuter(BarrelShifterMode mode, boolean signed, LeftRightFormat direction, int valueWidth, int shiftWidth) throws Exception {
ObservableValue value = new ObservableValue("value", valueWidth);
ObservableValue shift = new ObservableValue("shift", shiftWidth);
ElementAttributes attributes = new ElementAttributes().set(Keys.BARREL_SHIFTER_MODE, mode).set(Keys.BARREL_SIGNED, signed).set(Keys.DIRECTION, direction).set(Keys.BITS, valueWidth);
Model model = new Model();
BarrelShifter bs = new BarrelShifter(attributes);
bs.setInputs(ovs(value, shift));
model.add(bs);
ObservableValues outputs = bs.getOutputs();
assertEquals(1, outputs.size());
assertEquals(value.getBits(), outputs.get(0).getBits());
return new TestExecuter(model).setInputs(value, shift).setOutputs(outputs);
}
use of de.neemann.digital.core.ObservableValue in project Digital by hneemann.
the class BitCountTest method testBitCount.
public void testBitCount() throws Exception {
ObservableValue a = new ObservableValue("a", 6);
Model model = new Model();
BitCount node = new BitCount(new ElementAttributes().setBits(6));
node.setInputs(a.asList());
model.add(node);
ObservableValues outputs = node.getOutputs();
assertEquals(1, outputs.size());
assertEquals(3, outputs.get(0).getBits());
TestExecuter sc = new TestExecuter(model).setInputs(a).setOutputs(outputs);
sc.check(0, 0);
sc.check(1, 1);
sc.check(2, 1);
sc.check(4, 1);
sc.check(8, 1);
sc.check(16, 1);
sc.check(32, 1);
sc.check(3, 2);
sc.check(6, 2);
sc.check(12, 2);
sc.check(24, 2);
sc.check(48, 2);
sc.check(63, 6);
sc.check(255, 6);
}
use of de.neemann.digital.core.ObservableValue in project Digital by hneemann.
the class BitExtenderTest method testSignExtend.
public void testSignExtend() throws Exception {
ObservableValue in = new ObservableValue("in", 4);
BitExtender bitExtender = new BitExtender(new ElementAttributes().set(Keys.INPUT_BITS, 4).set(Keys.OUTPUT_BITS, 8));
bitExtender.setInputs(in.asList());
assertEquals(1, bitExtender.getOutputs().size());
ObservableValue out = bitExtender.getOutputs().get(0);
check(in, out, 0, 0);
check(in, out, 1, 1);
check(in, out, 7, 7);
check(in, out, 8, -8 & 0xff);
check(in, out, 9, -7 & 0xff);
check(in, out, -1, -1 & 0xff);
check(in, out, -2, -2 & 0xff);
}
use of de.neemann.digital.core.ObservableValue in project Digital by hneemann.
the class BitExtenderTest method testSignExtendError.
public void testSignExtendError() throws Exception {
try {
ObservableValue in = new ObservableValue("in", 4);
new BitExtender(new ElementAttributes().set(Keys.OUTPUT_BITS, 4)).setInputs(in.asList());
fail();
} catch (NodeException e) {
}
}
Aggregations