Search in sources :

Example 11 with ObservableValue

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);
}
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 ObservableValue

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);
}
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 13 with ObservableValue

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());
    }
}
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 ObservableValue

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());
    }
}
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 ObservableValue

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);
}
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

ObservableValue (de.neemann.digital.core.ObservableValue)88 ElementAttributes (de.neemann.digital.core.element.ElementAttributes)73 TestExecuter (de.neemann.digital.TestExecuter)61 Model (de.neemann.digital.core.Model)56 ObservableValues (de.neemann.digital.core.ObservableValues)17 NodeException (de.neemann.digital.core.NodeException)5 ArrayList (java.util.ArrayList)4 BitsException (de.neemann.digital.core.BitsException)3 FanIn (de.neemann.digital.core.basic.FanIn)3 Signal (de.neemann.digital.core.Signal)2 Element (de.neemann.digital.core.element.Element)2 Clock (de.neemann.digital.core.wiring.Clock)2 Delay (de.neemann.digital.core.wiring.Delay)2 DataBus (de.neemann.digital.core.wiring.bus.DataBus)2 IOState (de.neemann.digital.draw.elements.IOState)2 CircuitComponent (de.neemann.digital.gui.components.CircuitComponent)2 Sync (de.neemann.digital.gui.sync.Sync)2 BurnException (de.neemann.digital.core.BurnException)1 Node (de.neemann.digital.core.Node)1 NodeWithoutDelay (de.neemann.digital.core.NodeWithoutDelay)1