Search in sources :

Example 36 with Model

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

the class ModelAnalyserTest method testAnalyzerUniqueNames2.

public void testAnalyzerUniqueNames2() throws Exception {
    Model model = new ToBreakRunner("dig/analyze/uniqueNames2.dig", false).getModel();
    try {
        new ModelAnalyser(model);
        fail();
    } catch (AnalyseException e) {
    }
}
Also used : Model(de.neemann.digital.core.Model) ToBreakRunner(de.neemann.digital.integration.ToBreakRunner)

Example 37 with Model

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

the class ModelAnalyserTest method testAnalyzerMultiBitPins.

public void testAnalyzerMultiBitPins() throws Exception {
    Model model = new ToBreakRunner("dig/analyze/multiBitInOutXOr.dig", false).getModel();
    ModelAnalyserInfo mai = new ModelAnalyser(model).analyse().getModelAnalyzerInfo();
    assertEquals(2, mai.getInputBusMap().size());
    checkBus(mai.getInputBusMap(), "A", "A0", "A1", "A2", "A3");
    checkBus(mai.getInputBusMap(), "B", "B0", "B1", "B2", "B3");
    assertEquals(1, mai.getOutputBusMap().size());
    checkBus(mai.getOutputBusMap(), "S", "S0", "S1", "S2", "S3");
}
Also used : Model(de.neemann.digital.core.Model) ToBreakRunner(de.neemann.digital.integration.ToBreakRunner)

Example 38 with Model

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

the class TestExamples method check.

/**
 * Loads the model and initializes and test it if test cases are present
 *
 * @param dig the model file
 */
public static void check(File dig) throws Exception {
    boolean shouldFail = dig.getName().endsWith("Error.dig");
    ToBreakRunner br;
    try {
        br = new ToBreakRunner(dig);
    } catch (Exception e) {
        if (shouldFail) {
            return;
        } else
            throw e;
    }
    try {
        boolean isLib = dig.getPath().replace('\\', '/').contains("/lib/");
        assertTrue("wrong locked mode", isLib == br.getCircuit().getAttributes().get(Keys.LOCKED_MODE));
        try {
            for (VisualElement el : br.getCircuit().getElements()) if (el.equalsDescription(TestCaseElement.TESTCASEDESCRIPTION)) {
                String label = el.getElementAttributes().getCleanLabel();
                TestCaseDescription td = el.getElementAttributes().get(TestCaseElement.TESTDATA);
                Model model = new ModelCreator(br.getCircuit(), br.getLibrary()).createModel(false);
                try {
                    TestExecutor tr = new TestExecutor(td).create(model);
                    if (label.contains("Failing"))
                        assertFalse(dig.getName() + ":" + label, tr.allPassed());
                    else
                        assertTrue(dig.getName() + ":" + label, tr.allPassed());
                    testCasesInFiles++;
                } finally {
                    model.close();
                }
            }
        } catch (Exception e) {
            if (shouldFail) {
                return;
            } else
                throw e;
        }
        assertFalse("File should fail but doesn't!", shouldFail);
    } finally {
        br.close();
    }
}
Also used : TestExecutor(de.neemann.digital.testing.TestExecutor) Model(de.neemann.digital.core.Model) VisualElement(de.neemann.digital.draw.elements.VisualElement) ModelCreator(de.neemann.digital.draw.model.ModelCreator) TestCaseDescription(de.neemann.digital.testing.TestCaseDescription)

Example 39 with Model

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

the class TestProcessor method createProcessor.

private ToBreakRunner createProcessor(String program, String processor) throws IOException, PinException, NodeException, ElementNotFoundException {
    ToBreakRunner runner = new ToBreakRunner(processor, false);
    Model model = runner.getModel();
    ROM rom = null;
    for (ROM r : model.findNode(ROM.class)) {
        if (r.isProgramMemory())
            rom = r;
    }
    assertNotNull(rom);
    rom.setData(new DataField(new File(Resources.getRoot(), program)));
    runner.getModel().init(true);
    return runner;
}
Also used : ROM(de.neemann.digital.core.memory.ROM) DataField(de.neemann.digital.core.memory.DataField) Model(de.neemann.digital.core.Model) File(java.io.File)

Example 40 with Model

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

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