Search in sources :

Example 56 with ObservableValue

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

the class BitExtenderTest method testSignExtendInit.

public void testSignExtendInit() throws Exception {
    ObservableValue in = new ObservableValue("in", 4).setValue(1);
    BitExtender bitExtender = new BitExtender(new ElementAttributes().set(Keys.INPUT_BITS, 4).set(Keys.OUTPUT_BITS, 8));
    bitExtender.setInputs(in.asList());
    assertEquals(1, bitExtender.getOutputs().get(0).getValue());
}
Also used : ObservableValue(de.neemann.digital.core.ObservableValue) ElementAttributes(de.neemann.digital.core.element.ElementAttributes)

Example 57 with ObservableValue

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

the class ComparatorTest method testCompSigned.

public void testCompSigned() 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, true));
    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(7, 2, 1, 0, 0);
    sc.check(8, 2, 0, 0, 1);
    sc.check(15, 2, 0, 0, 1);
    sc.check(13, 15, 0, 0, 1);
    sc.check(-2, -3, 1, 0, 0);
    sc.check(-7, -8, 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 58 with ObservableValue

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

the class ComparatorTest method testCompUnsigned64Bit.

public void testCompUnsigned64Bit() 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, false));
    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, 0, 0, 1);
    sc.check(-2, 0, 1, 0, 0);
    sc.check(-1, -2, 1, 0, 0);
    sc.check(-2, -1, 0, 0, 1);
    sc.check(2, 1, 1, 0, 0);
    sc.check(0xC000000000000000L, 0x8000000000000000L, 1, 0, 0);
    sc.check(0x8000000000000000L, 0, 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 59 with ObservableValue

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

the class MulTest method testMul.

public void testMul() throws Exception {
    ObservableValue a = new ObservableValue("a", 4);
    ObservableValue b = new ObservableValue("b", 4);
    Model model = new Model();
    Mul node = model.add(new Mul(new ElementAttributes().setBits(4)));
    node.setInputs(ovs(a, b));
    TestExecuter sc = new TestExecuter(model).setInputs(a, b).setOutputsOf(node);
    sc.check(0, 0, 0);
    sc.check(6, 6, 36);
    sc.check(15, 15, 225);
}
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 60 with ObservableValue

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

the class NegTest method testNeg.

public void testNeg() throws Exception {
    ObservableValue a = new ObservableValue("a", 4);
    Model model = new Model();
    Neg out = model.add(new Neg(new ElementAttributes().setBits(4)));
    out.setInputs(a.asList());
    TestExecuter sc = new TestExecuter(model).setInputs(a).setOutputs(out.getOutputs());
    sc.check(0, 0);
    sc.check(1, 15);
    sc.check(15, 1);
    sc.check(3, 13);
    sc.check(7, 9);
    sc.check(8, 8);
    sc.check(9, 7);
}
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