Search in sources :

Example 6 with Model

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

the class TestAnd method testAnd.

/**
 * Reads a file and sets up a model from it.
 * After that the model - a simple AND gate - is tested to be a working AND gate.
 *
 * @throws Exception
 */
public void testAnd() throws Exception {
    File filename = new File(Resources.getRoot(), "dig/and.dig");
    Circuit circuit = Circuit.loadCircuit(filename, new ShapeFactory(new ElementLibrary()));
    ModelCreator md = new ModelCreator(circuit, library);
    Model model = md.createModel(false);
    List<Node> nodes = model.getNodes();
    assertEquals(1, nodes.size());
    // get inputs and outputs
    List<ModelEntry> inputs = md.getEntries("In");
    assertEquals(2, inputs.size());
    List<ModelEntry> outputs = md.getEntries("Out");
    assertEquals(1, outputs.size());
    // check the inputs state: the input itself has an output
    assertEquals(0, inputs.get(0).getIoState().inputCount());
    assertEquals(1, inputs.get(0).getIoState().outputCount());
    assertEquals(0, inputs.get(1).getIoState().inputCount());
    assertEquals(1, inputs.get(1).getIoState().outputCount());
    // check the output state: the output itself has an input
    assertEquals(1, outputs.get(0).getIoState().inputCount());
    assertEquals(0, outputs.get(0).getIoState().outputCount());
    // setup the test executer
    TestExecuter te = new TestExecuter(model).setInputs(inputs).setOutputs(outputs);
    te.check(0, 0, 0);
    te.check(0, 1, 0);
    te.check(1, 0, 0);
    te.check(1, 1, 1);
}
Also used : ModelEntry(de.neemann.digital.draw.model.ModelEntry) ElementLibrary(de.neemann.digital.draw.library.ElementLibrary) Node(de.neemann.digital.core.Node) Model(de.neemann.digital.core.Model) ShapeFactory(de.neemann.digital.draw.shapes.ShapeFactory) Circuit(de.neemann.digital.draw.elements.Circuit) TestExecuter(de.neemann.digital.TestExecuter) File(java.io.File) ModelCreator(de.neemann.digital.draw.model.ModelCreator)

Example 7 with Model

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

the class DecoderTest method testDecoder.

public void testDecoder() throws Exception {
    Model model = new Model();
    ObservableValue sel = new ObservableValue("sel", 2);
    Decoder decoder = model.add(new Decoder(new ElementAttributes().set(Keys.SELECTOR_BITS, 2)));
    decoder.setInputs(sel.asList());
    TestExecuter te = new TestExecuter(model).setInputs(sel).setOutputs(decoder.getOutputs());
    te.check(0, 1, 0, 0, 0);
    te.check(1, 0, 1, 0, 0);
    te.check(2, 0, 0, 1, 0);
    te.check(3, 0, 0, 0, 1);
}
Also used : Model(de.neemann.digital.core.Model) ObservableValue(de.neemann.digital.core.ObservableValue) ElementAttributes(de.neemann.digital.core.element.ElementAttributes) TestExecuter(de.neemann.digital.TestExecuter)

Example 8 with Model

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

the class PriorityEncoderTest method testEncoder4.

public void testEncoder4() throws Exception {
    Model model = new Model();
    ObservableValue d0 = new ObservableValue("d0", 1);
    ObservableValue d1 = new ObservableValue("d1", 1);
    ObservableValue d2 = new ObservableValue("d2", 1);
    ObservableValue d3 = new ObservableValue("d3", 1);
    PriorityEncoder out = model.add(new PriorityEncoder(new ElementAttributes().set(Keys.SELECTOR_BITS, 2)));
    out.setInputs(ovs(d0, d1, d2, d3));
    TestExecuter te = new TestExecuter(model).setInputs(d3, d2, d1, d0).setOutputs(out.getOutputs());
    te.check(0, 0, 0, 0, 0, 0);
    te.check(0, 0, 0, 1, 0, 1);
    te.check(0, 0, 1, 0, 1, 1);
    te.check(0, 0, 1, 1, 1, 1);
    te.check(0, 1, 0, 0, 2, 1);
    te.check(0, 1, 0, 1, 2, 1);
    te.check(0, 1, 1, 0, 2, 1);
    te.check(0, 1, 1, 1, 2, 1);
    te.check(1, 0, 0, 0, 3, 1);
    te.check(1, 0, 0, 1, 3, 1);
    te.check(1, 0, 1, 0, 3, 1);
    te.check(1, 0, 1, 1, 3, 1);
    te.check(1, 1, 0, 0, 3, 1);
    te.check(1, 1, 0, 1, 3, 1);
    te.check(1, 1, 1, 0, 3, 1);
    te.check(1, 1, 1, 1, 3, 1);
}
Also used : Model(de.neemann.digital.core.Model) ObservableValue(de.neemann.digital.core.ObservableValue) ElementAttributes(de.neemann.digital.core.element.ElementAttributes) TestExecuter(de.neemann.digital.TestExecuter)

Example 9 with Model

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

the class FlipflopRSAsyncTest method testFlipFlop.

public void testFlipFlop() throws Exception {
    ObservableValue s = new ObservableValue("s", 1);
    ObservableValue r = new ObservableValue("r", 1);
    Model model = new Model();
    FlipflopRSAsync out = model.add(new FlipflopRSAsync(new ElementAttributes()));
    out.setInputs(ovs(s, r));
    TestExecuter sc = new TestExecuter(model).setInputs(s, r).setOutputs(out.getOutputs());
    // S  R  Q  ~Q
    sc.check(0, 0, 0, 1);
    sc.check(1, 0, 1, 0);
    sc.check(0, 0, 1, 0);
    sc.check(0, 1, 0, 1);
    sc.check(0, 0, 0, 1);
    sc.check(1, 1, 1, 1);
    sc.check(1, 0, 1, 0);
    sc.check(1, 1, 1, 1);
    sc.check(0, 1, 0, 1);
    ObservableValue q = out.getOutputs().get(0);
    ObservableValue qn = out.getOutputs().get(1);
    for (int i = 0; i < 100; i++) {
        s.setValue(1);
        r.setValue(1);
        model.doStep();
        assertTrue(q.getBool());
        assertTrue(qn.getBool());
        s.setValue(0);
        r.setValue(0);
        model.doStep();
        assertTrue(q.getBool() ^ qn.getBool());
    }
}
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 10 with Model

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

the class FlipflopRSTest method testFlipFlop.

public void testFlipFlop() throws Exception {
    ObservableValue s = new ObservableValue("s", 1);
    ObservableValue c = new ObservableValue("c", 1);
    ObservableValue r = new ObservableValue("r", 1);
    Model model = new Model();
    FlipflopRS out = model.add(new FlipflopRS(new ElementAttributes()));
    out.setInputs(ovs(s, c, r));
    TestExecuter sc = new TestExecuter(model).setInputs(s, c, r).setOutputs(out.getOutputs());
    // S  C  R  Q  ~Q
    sc.check(0, 0, 0, 0, 1);
    sc.check(1, 0, 0, 0, 1);
    sc.check(0, 1, 0, 0, 1);
    sc.check(1, 0, 0, 0, 1);
    sc.check(1, 1, 0, 1, 0);
    sc.check(1, 0, 0, 1, 0);
    sc.check(0, 1, 1, 0, 1);
    sc.check(0, 0, 1, 0, 1);
    ObservableValue q = out.getOutputs().get(0);
    ObservableValue qn = out.getOutputs().get(1);
    s.setValue(1);
    r.setValue(1);
    for (int i = 0; i < 100; i++) {
        c.setValue(1);
        model.doStep();
        final boolean qBool = q.getBool();
        final boolean qnBool = qn.getBool();
        assertTrue(qBool ^ qnBool);
        c.setValue(0);
        model.doStep();
        assertEquals(qBool, q.getBool());
        assertEquals(qnBool, qn.getBool());
    }
}
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