Search in sources :

Example 41 with TestExecuter

use of de.neemann.digital.TestExecuter 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 42 with TestExecuter

use of de.neemann.digital.TestExecuter 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 43 with TestExecuter

use of de.neemann.digital.TestExecuter in project Digital by hneemann.

the class BarrelShifterTest method test64Bit.

public void test64Bit() throws Exception {
    TestExecuter bsTest = getTestExecuter(BarrelShifterMode.rotate, false, LeftRightFormat.left, 64, 7);
    bsTest.check(0xC000000000000000L, 0, 0xC000000000000000L);
    bsTest.check(0xC000000000000000L, 1, 0x8000000000000001L);
    bsTest.check(0x8000000000000001L, 1, 0x0000000000000003L);
    bsTest.check(0x4000000000000001L, 1, 0x8000000000000002L);
    bsTest = getTestExecuter(BarrelShifterMode.arithmetic, false, LeftRightFormat.left, 64, 7);
    bsTest.check(0xC000000000000000L, 0, 0xC000000000000000L);
    bsTest.check(0x4000000000000000L, 1, 0x8000000000000000L);
    bsTest.check(0x2000000000000000L, 1, 0x4000000000000000L);
    bsTest = getTestExecuter(BarrelShifterMode.logical, false, LeftRightFormat.left, 64, 7);
    bsTest.check(0xC000000000000000L, 0, 0xC000000000000000L);
    bsTest.check(0x4000000000000000L, 1, 0x8000000000000000L);
    bsTest.check(0x2000000000000000L, 1, 0x4000000000000000L);
    bsTest = getTestExecuter(BarrelShifterMode.rotate, false, LeftRightFormat.right, 64, 7);
    bsTest.check(0xC000000000000001L, 0, 0xC000000000000001L);
    bsTest.check(0x8000000000000001L, 1, 0xC000000000000000L);
    bsTest.check(0x4000000000000001L, 1, 0xA000000000000000L);
    bsTest = getTestExecuter(BarrelShifterMode.arithmetic, false, LeftRightFormat.right, 64, 7);
    bsTest.check(0xC000000000000000L, 0, 0xC000000000000000L);
    bsTest.check(0x8000000000000000L, 1, 0xC000000000000000L);
    bsTest.check(0x4000000000000000L, 1, 0x2000000000000000L);
    bsTest = getTestExecuter(BarrelShifterMode.logical, false, LeftRightFormat.right, 64, 7);
    bsTest.check(0xC000000000000000L, 0, 0xC000000000000000L);
    bsTest.check(0x8000000000000000L, 1, 0x4000000000000000L);
    bsTest.check(0x4000000000000000L, 1, 0x2000000000000000L);
}
Also used : TestExecuter(de.neemann.digital.TestExecuter)

Example 44 with TestExecuter

use of de.neemann.digital.TestExecuter in project Digital by hneemann.

the class BarrelShifterTest method testRotateUnsignedLeft.

public void testRotateUnsignedLeft() throws Exception {
    TestExecuter bsTest = getTestExecuter(BarrelShifterMode.rotate, false, LeftRightFormat.left, 6, 3);
    bsTest.check(0b001100, 0, 0b001100);
    bsTest.check(0b001100, 1, 0b011000);
    bsTest.check(0b001100, 2, 0b110000);
    bsTest.check(0b010001, 2, 0b000101);
    bsTest.check(0b001100, 3, 0b100001);
    bsTest.check(0b001100, 5, 0b000110);
    bsTest.check(0b001100, -1, 0b011000);
    bsTest.check(0b001100, -4, 0b000011);
    bsTest.check(0b001100, -5, 0b100001);
    for (int s = 0; s < 7; s++) bsTest.check(0b10101010, s, (s & 1) == 0 ? 0b10101010 : 0b01010101);
}
Also used : TestExecuter(de.neemann.digital.TestExecuter)

Example 45 with TestExecuter

use of de.neemann.digital.TestExecuter in project Digital by hneemann.

the class BarrelShifterTest method testNormalUnsignedRight.

public void testNormalUnsignedRight() throws Exception {
    TestExecuter bsTest = getTestExecuter(BarrelShifterMode.logical, false, LeftRightFormat.right, 6, 3);
    bsTest.check(0b001100, 0, 0b001100);
    bsTest.check(0b001100, 1, 0b000110);
    bsTest.check(0b001100, 2, 0b000011);
    bsTest.check(0b010001, 2, 0b000100);
    bsTest.check(0b001100, 3, 0b000001);
    bsTest.check(0b001100, 5, 0b000000);
    bsTest.check(0b001100, -1, 0b000000);
    bsTest.check(0b001100, -4, 0b000000);
    bsTest.check(0b001100, -5, 0b000001);
}
Also used : TestExecuter(de.neemann.digital.TestExecuter)

Aggregations

TestExecuter (de.neemann.digital.TestExecuter)80 ObservableValue (de.neemann.digital.core.ObservableValue)61 ElementAttributes (de.neemann.digital.core.element.ElementAttributes)61 Model (de.neemann.digital.core.Model)49 ObservableValues (de.neemann.digital.core.ObservableValues)16 Circuit (de.neemann.digital.draw.elements.Circuit)5 ElementLibrary (de.neemann.digital.draw.library.ElementLibrary)5 ModelCreator (de.neemann.digital.draw.model.ModelCreator)5 ShapeFactory (de.neemann.digital.draw.shapes.ShapeFactory)5 Expression (de.neemann.digital.analyse.expression.Expression)4 Variable (de.neemann.digital.analyse.expression.Variable)4 Node (de.neemann.digital.core.Node)1 FanIn (de.neemann.digital.core.basic.FanIn)1 Delay (de.neemann.digital.core.wiring.Delay)1 ModelEntry (de.neemann.digital.draw.model.ModelEntry)1 File (java.io.File)1