Search in sources :

Example 41 with ElementAttributes

use of de.neemann.digital.core.element.ElementAttributes in project Digital by hneemann.

the class SplitterMixTest method test1.

public void test1() 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, "4,12"));
    splitter.setInputs(ovs(a, b));
    assertEquals(2, a.observerCount());
    assertEquals(1, b.observerCount());
    ObservableValues outputs = splitter.getOutputs();
    assertEquals(2, outputs.size());
    TestExecuter sc = new TestExecuter().setInputs(a, b).setOutputsOf(splitter);
    sc.check(0x00, 0x00, 0x0, 0x000);
    sc.check(0x01, 0x00, 0x1, 0x000);
    sc.check(0x10, 0x00, 0x0, 0x001);
    sc.check(0x00, 0x01, 0x0, 0x010);
    sc.check(0x00, 0x10, 0x0, 0x100);
    sc.check(0x0f, 0x00, 0xf, 0x000);
    sc.check(0xf0, 0x00, 0x0, 0x00f);
    sc.check(0x00, 0x0f, 0x0, 0x0f0);
    sc.check(0x00, 0xf0, 0x0, 0xf00);
    sc.check(0xc0, 0xab, 0x0, 0xabc);
}
Also used : ObservableValues(de.neemann.digital.core.ObservableValues) ObservableValue(de.neemann.digital.core.ObservableValue) ElementAttributes(de.neemann.digital.core.element.ElementAttributes) TestExecuter(de.neemann.digital.TestExecuter)

Example 42 with ElementAttributes

use of de.neemann.digital.core.element.ElementAttributes in project Digital by hneemann.

the class SplitterMixTest method test3.

public void test3() throws Exception {
    ObservableValue a = new ObservableValue("a", 4);
    ObservableValue b = new ObservableValue("b", 4);
    ObservableValue c = new ObservableValue("c", 4);
    Splitter splitter = new Splitter(new ElementAttributes().set(Keys.INPUT_SPLIT, "4,4,4").set(Keys.OUTPUT_SPLIT, "2,8,2"));
    splitter.setInputs(ovs(a, b, c));
    assertEquals(2, a.observerCount());
    assertEquals(1, b.observerCount());
    assertEquals(2, c.observerCount());
    ObservableValues outputs = splitter.getOutputs();
    assertEquals(3, outputs.size());
    TestExecuter sc = new TestExecuter().setInputs(a, b, c).setOutputsOf(splitter);
    sc.check(0x0, 0x0, 0x0, 0x0, 0x00, 0x0);
    sc.check(0xf, 0x0, 0x0, 0x3, 0x03, 0x0);
    sc.check(0x0, 0xf, 0x0, 0x0, 0x3c, 0x0);
    sc.check(0x0, 0x0, 0xf, 0x0, 0xc0, 0x3);
    sc.check(0xf, 0xf, 0xf, 0x3, 0xff, 0x3);
}
Also used : ObservableValues(de.neemann.digital.core.ObservableValues) ObservableValue(de.neemann.digital.core.ObservableValue) ElementAttributes(de.neemann.digital.core.element.ElementAttributes) TestExecuter(de.neemann.digital.TestExecuter)

Example 43 with ElementAttributes

use of de.neemann.digital.core.element.ElementAttributes in project Digital by hneemann.

the class AddTest method testAdd31.

public void testAdd31() throws Exception {
    ObservableValue a = new ObservableValue("a", 31);
    ObservableValue b = new ObservableValue("b", 31);
    ObservableValue c = new ObservableValue("c", 1);
    Model model = new Model();
    Add node = new Add(new ElementAttributes().setBits(31));
    node.setInputs(ovs(a, b, c));
    model.add(node);
    TestExecuter sc = new TestExecuter(model).setInputs(a, b, c).setOutputs(node.getOutputs());
    sc.check(-1, 0, 1, 0, 1);
    sc.check(-1, 1, 0, 0, 1);
}
Also used : ObservableValue(de.neemann.digital.core.ObservableValue) Model(de.neemann.digital.core.Model) ElementAttributes(de.neemann.digital.core.element.ElementAttributes) TestExecuter(de.neemann.digital.TestExecuter)

Example 44 with ElementAttributes

use of de.neemann.digital.core.element.ElementAttributes 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);
}
Also used : ObservableValue(de.neemann.digital.core.ObservableValue) Model(de.neemann.digital.core.Model) ElementAttributes(de.neemann.digital.core.element.ElementAttributes) TestExecuter(de.neemann.digital.TestExecuter)

Example 45 with ElementAttributes

use of de.neemann.digital.core.element.ElementAttributes 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);
}
Also used : ObservableValues(de.neemann.digital.core.ObservableValues) ObservableValue(de.neemann.digital.core.ObservableValue) Model(de.neemann.digital.core.Model) ElementAttributes(de.neemann.digital.core.element.ElementAttributes) TestExecuter(de.neemann.digital.TestExecuter)

Aggregations

ElementAttributes (de.neemann.digital.core.element.ElementAttributes)87 ObservableValue (de.neemann.digital.core.ObservableValue)73 TestExecuter (de.neemann.digital.TestExecuter)61 Model (de.neemann.digital.core.Model)52 ObservableValues (de.neemann.digital.core.ObservableValues)16 BitsException (de.neemann.digital.core.BitsException)3 FanIn (de.neemann.digital.core.basic.FanIn)3 NodeException (de.neemann.digital.core.NodeException)2 Delay (de.neemann.digital.core.wiring.Delay)2 Circuit (de.neemann.digital.draw.elements.Circuit)2 And (de.neemann.digital.core.basic.And)1 Not (de.neemann.digital.core.basic.Not)1 Or (de.neemann.digital.core.basic.Or)1 Element (de.neemann.digital.core.element.Element)1 Key (de.neemann.digital.core.element.Key)1 FlipflopD (de.neemann.digital.core.flipflops.FlipflopD)1 FlipflopJK (de.neemann.digital.core.flipflops.FlipflopJK)1 Clock (de.neemann.digital.core.wiring.Clock)1 VisualElement (de.neemann.digital.draw.elements.VisualElement)1 ElementLibrary (de.neemann.digital.draw.library.ElementLibrary)1