Search in sources :

Example 31 with ObservableValue

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

the class BitExtenderTest method testSignExtend64.

public void testSignExtend64() throws Exception {
    ObservableValue in = new ObservableValue("in", 63);
    BitExtender bitExtender = new BitExtender(new ElementAttributes().set(Keys.INPUT_BITS, 63).set(Keys.OUTPUT_BITS, 64));
    bitExtender.setInputs(in.asList());
    assertEquals(1, bitExtender.getOutputs().size());
    ObservableValue out = bitExtender.getOutputs().get(0);
    check(in, out, 0, 0);
    check(in, out, 0x4000000000000000L, 0xC000000000000000L);
}
Also used : ObservableValue(de.neemann.digital.core.ObservableValue) ElementAttributes(de.neemann.digital.core.element.ElementAttributes)

Example 32 with ObservableValue

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

the class ComparatorTest method testCompSigned64Bit.

public void testCompSigned64Bit() throws Exception {
    ObservableValue a = new ObservableValue("a", 64);
    ObservableValue b = new ObservableValue("b", 64);
    Model model = new Model();
    Comparator node = new Comparator(new ElementAttributes().setBits(64).set(Keys.SIGNED, true));
    node.setInputs(ovs(a, b));
    model.add(node);
    TestExecuter sc = new TestExecuter(model).setInputs(a, b).setOutputs(node.getOutputs());
    // gr eq kl
    sc.check(0, 0, 0, 1, 0);
    sc.check(0, -2, 1, 0, 0);
    sc.check(-2, 0, 0, 0, 1);
    sc.check(-1, -2, 1, 0, 0);
    sc.check(-2, -1, 0, 0, 1);
    sc.check(0x8000000000000000L, 0, 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 33 with ObservableValue

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

the class ComparatorTest method testCompUnsigned.

public void testCompUnsigned() throws Exception {
    ObservableValue a = new ObservableValue("a", 4);
    ObservableValue b = new ObservableValue("b", 4);
    Model model = new Model();
    Comparator node = new Comparator(new ElementAttributes().setBits(4).set(Keys.SIGNED, false));
    node.setInputs(ovs(a, b));
    model.add(node);
    TestExecuter sc = new TestExecuter(model).setInputs(a, b).setOutputs(node.getOutputs());
    sc.check(0, 0, 0, 1, 0);
    sc.check(1, 0, 1, 0, 0);
    sc.check(1, 2, 0, 0, 1);
    sc.check(14, 2, 1, 0, 0);
}
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 34 with ObservableValue

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

the class AndTest 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 And(new ElementAttributes().setBits(1)));
    out.setInputs(ovs(a, b));
    TestExecuter sc = new TestExecuter(model).setInputs(a, b).setOutputs(out.getOutputs());
    sc.check(0, 0, 0);
    sc.check(1, 0, 0);
    sc.check(0, 1, 0);
    sc.check(1, 1, 1);
    sc.check(1, 0, 0);
    sc.check(0, 1, 0);
}
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 35 with ObservableValue

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

the class DelayTest method testDelayVar.

public void testDelayVar() throws Exception {
    for (int delayTime = 0; delayTime < 5; delayTime++) {
        ObservableValue in = new ObservableValue("in", 1);
        Model model = new Model();
        Delay delay = model.add(new Delay(new ElementAttributes().set(Keys.DELAY_TIME, delayTime)));
        delay.setInputs(in.asList());
        assertEquals(1, delay.getOutputs().size());
        ObservableValue out = delay.getOutputs().get(0);
        model.init();
        in.setValue(0);
        model.doStep();
        assertEquals(0, out.getValue());
        in.setValue(1);
        for (int i = 1; i < delayTime; i++) {
            assertTrue(model.needsUpdate());
            model.doMicroStep(false);
            assertEquals(0, out.getValue());
        }
        assertTrue(model.needsUpdate());
        model.doMicroStep(false);
        assertEquals(1, out.getValue());
        assertFalse(model.needsUpdate());
    }
}
Also used : ObservableValue(de.neemann.digital.core.ObservableValue) Model(de.neemann.digital.core.Model) ElementAttributes(de.neemann.digital.core.element.ElementAttributes) Delay(de.neemann.digital.core.wiring.Delay)

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