Search in sources :

Example 1 with Node

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

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

the class ModelCreator method addNodeElementsTo.

/**
 * Adds all the VisualElements, witch have generated one of the given nodes to the collection
 * of Drawables.
 *
 * @param nodes       The collection of nodes
 * @param highLighted the list of drawables to add the VisualElements to
 */
public void addNodeElementsTo(Collection<Node> nodes, Collection<Drawable> highLighted) {
    if (nodes == null)
        return;
    HashSet<Node> nodeSet = new HashSet<>();
    nodeSet.addAll(nodes);
    for (ModelEntry me : entries) {
        Element element = me.getElement();
        if (element instanceof Node && nodeSet.contains(element))
            highLighted.add(me.getContainingVisualElement());
    }
}
Also used : Node(de.neemann.digital.core.Node) CustomElement(de.neemann.digital.draw.library.CustomElement)

Example 3 with Node

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

the class TestTrans method testTrans.

public void testTrans() throws Exception {
    Model model = new ToBreakRunner("dig/test/transp/transtest3.dig").getModel();
    assertEquals(2, model.getInputs().size());
    assertEquals(1, model.getOutputs().size());
    assertEquals(1, model.getNodes().size());
    Node node = model.getNodes().get(0);
    assertTrue(node instanceof XOr);
    XOr xor = (XOr) node;
    // The models inputs are the xor input values!
    // All the intermediate transparent stuff is removed!
    ArrayList<ObservableValue> ins = new ArrayList<>();
    for (Signal s : model.getInputs()) ins.add(s.getValue());
    assertTrue(ins.contains(xor.getInputs().get(0)));
    assertTrue(ins.contains(xor.getInputs().get(1)));
}
Also used : Signal(de.neemann.digital.core.Signal) Node(de.neemann.digital.core.Node) Model(de.neemann.digital.core.Model) ObservableValue(de.neemann.digital.core.ObservableValue) ArrayList(java.util.ArrayList) XOr(de.neemann.digital.core.basic.XOr)

Example 4 with Node

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

the class ROMManger method applyTo.

/**
 * Applies the available roms to the model
 *
 * @param model the mode to use
 */
public void applyTo(Model model) {
    for (Node n : model.findNode(n -> n instanceof ROMInterface)) {
        ROMInterface rom = (ROMInterface) n;
        DataField data = roms.get(rom.getLabel());
        if (data != null)
            rom.setData(data);
    }
}
Also used : DataField(de.neemann.digital.core.memory.DataField) Node(de.neemann.digital.core.Node)

Aggregations

Node (de.neemann.digital.core.Node)4 Model (de.neemann.digital.core.Model)2 TestExecuter (de.neemann.digital.TestExecuter)1 ObservableValue (de.neemann.digital.core.ObservableValue)1 Signal (de.neemann.digital.core.Signal)1 XOr (de.neemann.digital.core.basic.XOr)1 DataField (de.neemann.digital.core.memory.DataField)1 Circuit (de.neemann.digital.draw.elements.Circuit)1 CustomElement (de.neemann.digital.draw.library.CustomElement)1 ElementLibrary (de.neemann.digital.draw.library.ElementLibrary)1 ModelCreator (de.neemann.digital.draw.model.ModelCreator)1 ModelEntry (de.neemann.digital.draw.model.ModelEntry)1 ShapeFactory (de.neemann.digital.draw.shapes.ShapeFactory)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1