Search in sources :

Example 56 with Model

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

the class AddTest method testAdd.

public void testAdd() throws Exception {
    ObservableValue a = new ObservableValue("a", 4);
    ObservableValue b = new ObservableValue("b", 4);
    ObservableValue c = new ObservableValue("c", 1);
    Model model = new Model();
    Add node = new Add(new ElementAttributes().setBits(4));
    node.setInputs(ovs(a, b, c));
    model.add(node);
    TestExecuter sc = new TestExecuter(model).setInputs(a, b, c).setOutputs(node.getOutputs());
    sc.check(0, 0, 0, 0, 0);
    sc.check(0, 0, 1, 1, 0);
    sc.check(2, 3, 0, 5, 0);
    sc.check(2, 3, 1, 6, 0);
    sc.check(7, 7, 0, 14, 0);
    sc.check(8, 8, 0, 0, 1);
    sc.check(8, 8, 1, 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 57 with Model

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

the class BarrelShifterTest method getTestExecuter.

private TestExecuter getTestExecuter(BarrelShifterMode mode, boolean signed, LeftRightFormat direction, int valueWidth, int shiftWidth) throws Exception {
    ObservableValue value = new ObservableValue("value", valueWidth);
    ObservableValue shift = new ObservableValue("shift", shiftWidth);
    ElementAttributes attributes = new ElementAttributes().set(Keys.BARREL_SHIFTER_MODE, mode).set(Keys.BARREL_SIGNED, signed).set(Keys.DIRECTION, direction).set(Keys.BITS, valueWidth);
    Model model = new Model();
    BarrelShifter bs = new BarrelShifter(attributes);
    bs.setInputs(ovs(value, shift));
    model.add(bs);
    ObservableValues outputs = bs.getOutputs();
    assertEquals(1, outputs.size());
    assertEquals(value.getBits(), outputs.get(0).getBits());
    return new TestExecuter(model).setInputs(value, shift).setOutputs(outputs);
}
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 58 with Model

use of de.neemann.digital.core.Model 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 59 with Model

use of de.neemann.digital.core.Model 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 60 with Model

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

Aggregations

Model (de.neemann.digital.core.Model)85 ObservableValue (de.neemann.digital.core.ObservableValue)56 ElementAttributes (de.neemann.digital.core.element.ElementAttributes)52 TestExecuter (de.neemann.digital.TestExecuter)49 ToBreakRunner (de.neemann.digital.integration.ToBreakRunner)16 ValueTable (de.neemann.digital.data.ValueTable)6 Signal (de.neemann.digital.core.Signal)4 ModelCreator (de.neemann.digital.draw.model.ModelCreator)4 ObservableValues (de.neemann.digital.core.ObservableValues)3 Expression (de.neemann.digital.analyse.expression.Expression)2 BoolTable (de.neemann.digital.analyse.quinemc.BoolTable)2 Node (de.neemann.digital.core.Node)2 Delay (de.neemann.digital.core.wiring.Delay)2 Circuit (de.neemann.digital.draw.elements.Circuit)2 ElementLibrary (de.neemann.digital.draw.library.ElementLibrary)2 ShapeFactory (de.neemann.digital.draw.shapes.ShapeFactory)2 File (java.io.File)2 ArrayList (java.util.ArrayList)2 Variable (de.neemann.digital.analyse.expression.Variable)1 Parser (de.neemann.digital.analyse.parser.Parser)1