Search in sources :

Example 21 with Circuit

use of de.neemann.digital.draw.elements.Circuit in project Digital by hneemann.

the class DependencyAnalyserTest method testBacktrackCompleteness.

public void testBacktrackCompleteness() throws Exception {
    ToBreakRunner toBreakRunner = new ToBreakRunner("dig/backtrack/AllComponents.dig", false);
    // create a set of all components used in the circuit
    Circuit circuit = toBreakRunner.getCircuit();
    Set<String> set = new HashSet<>();
    for (VisualElement e : circuit.getElements()) set.add(e.getElementName());
    // ensure all available components are included in test circuit
    for (ElementLibrary.ElementContainer c : toBreakRunner.getLibrary()) {
        if (!set.contains(c.getDescription().getName())) {
            // nodes with state are allowed to be missing
            Element n = c.getDescription().createElement(new ElementAttributes());
            boolean ok = (n instanceof Node) && ((Node) n).hasState();
            assertTrue("component " + c.getDescription().getName() + " is missing in test/resources/dig/backtrack/AllComponents.dig!", ok);
        }
    }
    // check if backtracking is ok at all components!
    ModelAnalyser m = new ModelAnalyser(toBreakRunner.getModel());
    new DependencyAnalyser(m);
}
Also used : VisualElement(de.neemann.digital.draw.elements.VisualElement) Element(de.neemann.digital.core.element.Element) Circuit(de.neemann.digital.draw.elements.Circuit) VisualElement(de.neemann.digital.draw.elements.VisualElement) ElementAttributes(de.neemann.digital.core.element.ElementAttributes) ElementLibrary(de.neemann.digital.draw.library.ElementLibrary) ToBreakRunner(de.neemann.digital.integration.ToBreakRunner) HashSet(java.util.HashSet)

Example 22 with Circuit

use of de.neemann.digital.draw.elements.Circuit in project Digital by hneemann.

the class CircuitBuilderTest method testBuilderSequentialJK.

public void testBuilderSequentialJK() throws Exception {
    Variable y0 = new Variable("Y_0");
    Variable y1 = new Variable("Y_1");
    // counter
    Expression y0s = not(y0);
    Expression y1s = or(not(y0), not(y1));
    ElementLibrary library = new ElementLibrary();
    Circuit circuit = new CircuitBuilder(new ShapeFactory(library), true).addSequential("Y_0", y0s).addSequential("Y_1", y1s).createCircuit();
    ModelCreator m = new ModelCreator(circuit, library);
    TestExecuter te = new TestExecuter(m.createModel(false)).setUp(m);
    te.check(0, 0);
    te.checkC(1, 1);
    te.checkC(0, 0);
    te.checkC(1, 1);
    te.checkC(0, 0);
}
Also used : ElementLibrary(de.neemann.digital.draw.library.ElementLibrary) Variable(de.neemann.digital.analyse.expression.Variable) Expression(de.neemann.digital.analyse.expression.Expression) ShapeFactory(de.neemann.digital.draw.shapes.ShapeFactory) Circuit(de.neemann.digital.draw.elements.Circuit) TestExecuter(de.neemann.digital.TestExecuter) ModelCreator(de.neemann.digital.draw.model.ModelCreator)

Example 23 with Circuit

use of de.neemann.digital.draw.elements.Circuit in project Digital by hneemann.

the class CircuitBuilderTest method testBus.

public void testBus() throws Exception {
    final ToBreakRunner runner = new ToBreakRunner("dig/circuitBuilder/busTest.dig", false);
    // create truth table incl. ModelAnalyzerInfo
    TruthTable tt = new ModelAnalyser(runner.getModel()).analyse();
    assertEquals(8, tt.getVars().size());
    assertEquals(8, tt.getResultCount());
    // create expressions based on truth table
    ExpressionListenerStore expr = new ExpressionListenerStore(null);
    new ExpressionCreator(tt).create(expr);
    // build a new circuit
    CircuitBuilder circuitBuilder = new CircuitBuilder(runner.getLibrary().getShapeFactory(), false, tt.getVars()).setModelAnalyzerInfo(tt.getModelAnalyzerInfo());
    new BuilderExpressionCreator(circuitBuilder).create(expr);
    Circuit circuit = circuitBuilder.createCircuit();
    // check
    List<VisualElement> in = circuit.findElements(v -> v.equalsDescription(In.DESCRIPTION));
    assertEquals(2, in.size());
    checkPin(in.get(0), "A", "1,2,3,4");
    checkPin(in.get(1), "B", "5,6,7,8");
    List<VisualElement> out = circuit.findElements(v -> v.equalsDescription(Out.DESCRIPTION));
    assertEquals(2, out.size());
    checkPin(out.get(0), "S", "9,10,11,12");
    checkPin(out.get(1), "U", "13,14,15,16");
}
Also used : ModelAnalyser(de.neemann.digital.analyse.ModelAnalyser) TruthTable(de.neemann.digital.analyse.TruthTable) ToBreakRunner(de.neemann.digital.integration.ToBreakRunner) Circuit(de.neemann.digital.draw.elements.Circuit) VisualElement(de.neemann.digital.draw.elements.VisualElement) BuilderExpressionCreator(de.neemann.digital.gui.components.table.BuilderExpressionCreator) ExpressionListenerStore(de.neemann.digital.gui.components.table.ExpressionListenerStore) ExpressionCreator(de.neemann.digital.gui.components.table.ExpressionCreator) BuilderExpressionCreator(de.neemann.digital.gui.components.table.BuilderExpressionCreator)

Example 24 with Circuit

use of de.neemann.digital.draw.elements.Circuit in project Digital by hneemann.

the class NetListTest method testTunnel3.

public void testTunnel3() throws Exception {
    Circuit c = new Circuit();
    c.add(new Wire(new Vector(1, 1), new Vector(2, 1)));
    addTunnel(c, new Vector(2, 1), "A");
    c.add(new Wire(new Vector(3, 1), new Vector(4, 1)));
    addTunnel(c, new Vector(3, 1), "A");
    addTunnel(c, new Vector(4, 1), "C");
    c.add(new Wire(new Vector(1, 4), new Vector(2, 4)));
    addTunnel(c, new Vector(2, 4), "B");
    addTunnel(c, new Vector(1, 4), "C");
    c.add(new Wire(new Vector(3, 4), new Vector(4, 4)));
    addTunnel(c, new Vector(3, 4), "B");
    NetList ns = new NetList(c);
    assertEquals(1, ns.size());
}
Also used : Circuit(de.neemann.digital.draw.elements.Circuit) Wire(de.neemann.digital.draw.elements.Wire) Vector(de.neemann.digital.draw.graphics.Vector)

Example 25 with Circuit

use of de.neemann.digital.draw.elements.Circuit in project Digital by hneemann.

the class NetListTest method testSimple.

public void testSimple() throws Exception {
    Circuit c = new Circuit();
    c.add(new Wire(new Vector(1, 1), new Vector(1, 2)));
    c.add(new Wire(new Vector(2, 1), new Vector(2, 2)));
    c.add(new Wire(new Vector(1, 2), new Vector(2, 2)));
    c.add(new Wire(new Vector(1, 1), new Vector(2, 1)));
    NetList ns = new NetList(c);
    assertEquals(1, ns.size());
}
Also used : Circuit(de.neemann.digital.draw.elements.Circuit) Wire(de.neemann.digital.draw.elements.Wire) Vector(de.neemann.digital.draw.graphics.Vector)

Aggregations

Circuit (de.neemann.digital.draw.elements.Circuit)26 ElementLibrary (de.neemann.digital.draw.library.ElementLibrary)9 ShapeFactory (de.neemann.digital.draw.shapes.ShapeFactory)8 Vector (de.neemann.digital.draw.graphics.Vector)7 ModelCreator (de.neemann.digital.draw.model.ModelCreator)7 Expression (de.neemann.digital.analyse.expression.Expression)6 VisualElement (de.neemann.digital.draw.elements.VisualElement)6 File (java.io.File)6 TestExecuter (de.neemann.digital.TestExecuter)5 Wire (de.neemann.digital.draw.elements.Wire)5 Variable (de.neemann.digital.analyse.expression.Variable)4 IOException (java.io.IOException)4 ElementAttributes (de.neemann.digital.core.element.ElementAttributes)3 Main (de.neemann.digital.gui.Main)3 CircuitBuilder (de.neemann.digital.builder.circuit.CircuitBuilder)2 Model (de.neemann.digital.core.Model)2 ExpressionListenerStore (de.neemann.digital.gui.components.table.ExpressionListenerStore)2 ToBreakRunner (de.neemann.digital.integration.ToBreakRunner)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 ModelAnalyser (de.neemann.digital.analyse.ModelAnalyser)1