Search in sources :

Example 11 with ElementAttributes

use of de.neemann.digital.core.element.ElementAttributes 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);
}
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 12 with ElementAttributes

use of de.neemann.digital.core.element.ElementAttributes 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());
    }
}
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 13 with ElementAttributes

use of de.neemann.digital.core.element.ElementAttributes 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());
    }
}
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 14 with ElementAttributes

use of de.neemann.digital.core.element.ElementAttributes 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);
}
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 15 with ElementAttributes

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

the class NOrTest method testNOr.

public void testNOr() throws Exception {
    ObservableValue a = new ObservableValue("a", 1);
    ObservableValue b = new ObservableValue("b", 1);
    Model model = new Model();
    NOr nor = model.add(new NOr(new ElementAttributes().setBits(1)));
    nor.setInputs(ovs(a, b));
    TestExecuter sc = new TestExecuter(model).setInputs(a, b).setOutputs(nor.getOutputs());
    sc.check(0, 0, 1);
    sc.check(1, 0, 0);
    sc.check(0, 1, 0);
    sc.check(1, 1, 0);
    sc.check(1, 0, 0);
    sc.check(0, 1, 0);
    sc.check(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)

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