Search in sources :

Example 46 with ElementAttributes

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

the class BitCountTest method testBitCount.

public void testBitCount() throws Exception {
    ObservableValue a = new ObservableValue("a", 6);
    Model model = new Model();
    BitCount node = new BitCount(new ElementAttributes().setBits(6));
    node.setInputs(a.asList());
    model.add(node);
    ObservableValues outputs = node.getOutputs();
    assertEquals(1, outputs.size());
    assertEquals(3, outputs.get(0).getBits());
    TestExecuter sc = new TestExecuter(model).setInputs(a).setOutputs(outputs);
    sc.check(0, 0);
    sc.check(1, 1);
    sc.check(2, 1);
    sc.check(4, 1);
    sc.check(8, 1);
    sc.check(16, 1);
    sc.check(32, 1);
    sc.check(3, 2);
    sc.check(6, 2);
    sc.check(12, 2);
    sc.check(24, 2);
    sc.check(48, 2);
    sc.check(63, 6);
    sc.check(255, 6);
}
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)

Example 47 with ElementAttributes

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

the class BitExtenderTest method testSignExtend.

public void testSignExtend() throws Exception {
    ObservableValue in = new ObservableValue("in", 4);
    BitExtender bitExtender = new BitExtender(new ElementAttributes().set(Keys.INPUT_BITS, 4).set(Keys.OUTPUT_BITS, 8));
    bitExtender.setInputs(in.asList());
    assertEquals(1, bitExtender.getOutputs().size());
    ObservableValue out = bitExtender.getOutputs().get(0);
    check(in, out, 0, 0);
    check(in, out, 1, 1);
    check(in, out, 7, 7);
    check(in, out, 8, -8 & 0xff);
    check(in, out, 9, -7 & 0xff);
    check(in, out, -1, -1 & 0xff);
    check(in, out, -2, -2 & 0xff);
}
Also used : ObservableValue(de.neemann.digital.core.ObservableValue) ElementAttributes(de.neemann.digital.core.element.ElementAttributes)

Example 48 with ElementAttributes

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

the class BitExtenderTest method testSignExtendError.

public void testSignExtendError() throws Exception {
    try {
        ObservableValue in = new ObservableValue("in", 4);
        new BitExtender(new ElementAttributes().set(Keys.OUTPUT_BITS, 4)).setInputs(in.asList());
        fail();
    } catch (NodeException e) {
    }
}
Also used : ObservableValue(de.neemann.digital.core.ObservableValue) NodeException(de.neemann.digital.core.NodeException) ElementAttributes(de.neemann.digital.core.element.ElementAttributes)

Example 49 with ElementAttributes

use of de.neemann.digital.core.element.ElementAttributes 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 50 with ElementAttributes

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

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