mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-16 00:15:01 -04:00
Added tests for svg shape compatibility check
This commit is contained in:
parent
8a2fbe89a9
commit
04dc00cf60
@ -266,20 +266,23 @@ public class Circuit {
|
||||
* Adds a ne VisualElement
|
||||
*
|
||||
* @param visualElement the visual element to add
|
||||
* @return this for chained calls
|
||||
*/
|
||||
public void add(VisualElement visualElement) {
|
||||
public Circuit add(VisualElement visualElement) {
|
||||
visualElements.add(visualElement);
|
||||
modified();
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new Wire
|
||||
*
|
||||
* @param newWire the wire to add
|
||||
* @return this for chained calls
|
||||
*/
|
||||
public void add(Wire newWire) {
|
||||
public Circuit add(Wire newWire) {
|
||||
if (newWire.p1.equals(newWire.p2))
|
||||
return;
|
||||
return null;
|
||||
|
||||
wires.add(newWire);
|
||||
WireConsistencyChecker checker = new WireConsistencyChecker(wires);
|
||||
@ -287,6 +290,7 @@ public class Circuit {
|
||||
|
||||
dotsPresent = false;
|
||||
modified();
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -21,9 +21,6 @@ import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
|
||||
import static de.neemann.digital.draw.shapes.GenericShape.SIZE;
|
||||
import static de.neemann.digital.draw.shapes.GenericShape.SIZE2;
|
||||
|
||||
/**
|
||||
* Is intended to be stored in a file.
|
||||
*/
|
||||
@ -151,22 +148,6 @@ public class CustomShapeDescription implements Iterable<CustomShapeDescription.H
|
||||
label.transform(tr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a simple dummy shape
|
||||
*
|
||||
* @return the dummy shape
|
||||
*/
|
||||
public static CustomShapeDescription createDummy() {
|
||||
return new CustomShapeDescription()
|
||||
.addPin("A", new Vector(0, 0), true)
|
||||
.addPin("B", new Vector(0, SIZE * 2), true)
|
||||
.addPin("Y", new Vector(SIZE * 3, SIZE), true)
|
||||
.addCircle(new Vector(0, -SIZE2), new Vector(SIZE * 3, SIZE * 3 - SIZE2), Style.NORMAL.getThickness(), Color.BLACK, false)
|
||||
.addPolygon(Polygon.createFromPath("m 20,5 c 30 0 0 30 -30 0 z"), Style.NORMAL.getThickness(), Color.BLACK, false)
|
||||
.addLine(new Vector(0, -SIZE2), new Vector(SIZE * 3, SIZE * 3 - SIZE2), Style.NORMAL.getThickness(), Color.BLACK)
|
||||
.addText(new Vector(20, -25), new Vector(21, -25), "Hi!", Orientation.LEFTCENTER, 20, Color.BLACK);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the number of pins in this shape
|
||||
*/
|
||||
|
@ -0,0 +1,101 @@
|
||||
package de.neemann.digital.draw.shapes.custom;
|
||||
|
||||
import de.neemann.digital.core.element.Keys;
|
||||
import de.neemann.digital.core.io.In;
|
||||
import de.neemann.digital.core.io.Out;
|
||||
import de.neemann.digital.core.wiring.Clock;
|
||||
import de.neemann.digital.draw.elements.Circuit;
|
||||
import de.neemann.digital.draw.elements.PinException;
|
||||
import de.neemann.digital.draw.elements.VisualElement;
|
||||
import de.neemann.digital.draw.elements.Wire;
|
||||
import de.neemann.digital.draw.shapes.custom.svg.SvgException;
|
||||
import de.neemann.digital.draw.shapes.custom.svg.SvgImporter;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static de.neemann.digital.draw.graphics.Vector.vec;
|
||||
import static de.neemann.digital.draw.shapes.custom.SvgImporterTest.in;
|
||||
|
||||
public class CustomShapeDescriptionTest extends TestCase {
|
||||
|
||||
private CustomShapeDescription custom;
|
||||
|
||||
public void setUp() throws IOException, SvgException {
|
||||
custom = new SvgImporter(
|
||||
in("<svg viewBox=\"0 0 200 100\" xmlns=\"http://www.w3.org/2000/svg\">\n" +
|
||||
" <path d=\"M 0,0 l 0,100 l 100,0 l 0,-100\" />\n" +
|
||||
" <circle id=\"pin:in\" cx=\"0\" cy=\"00\" r=\"6\" />\n" +
|
||||
" <circle id=\"pin:out\" cx=\"40\" cy=\"0\" r=\"6\" />\n" +
|
||||
"</svg>")).create();
|
||||
}
|
||||
|
||||
public void testCheckCompatibilityOk() throws PinException {
|
||||
Circuit circuit = new Circuit()
|
||||
.add(new VisualElement(In.DESCRIPTION.getName()).setPos(vec(0, 0)).setAttribute(Keys.LABEL, "in"))
|
||||
.add(new VisualElement(Out.DESCRIPTION.getName()).setPos(vec(20, 0)).setAttribute(Keys.LABEL, "out"))
|
||||
.add(new Wire(vec(0, 0), vec(20, 0)));
|
||||
|
||||
custom.checkCompatibility(circuit);
|
||||
}
|
||||
|
||||
public void testCheckCompatibilityClock() throws PinException {
|
||||
Circuit circuit = new Circuit()
|
||||
.add(new VisualElement(Clock.DESCRIPTION.getName()).setPos(vec(0, 0)).setAttribute(Keys.LABEL, "in"))
|
||||
.add(new VisualElement(Out.DESCRIPTION.getName()).setPos(vec(20, 0)).setAttribute(Keys.LABEL, "out"))
|
||||
.add(new Wire(vec(0, 0), vec(20, 0)));
|
||||
|
||||
custom.checkCompatibility(circuit);
|
||||
}
|
||||
|
||||
public void testCheckCompatibilityInPinMissing() {
|
||||
Circuit circuit = new Circuit()
|
||||
.add(new VisualElement(In.DESCRIPTION.getName()).setPos(vec(0, 0)).setAttribute(Keys.LABEL, "in"))
|
||||
.add(new VisualElement(In.DESCRIPTION.getName()).setPos(vec(0, 20)).setAttribute(Keys.LABEL, "in2"))
|
||||
.add(new VisualElement(Out.DESCRIPTION.getName()).setPos(vec(20, 0)).setAttribute(Keys.LABEL, "out"));
|
||||
|
||||
try {
|
||||
custom.checkCompatibility(circuit);
|
||||
fail();
|
||||
} catch (PinException e) {
|
||||
assertTrue(true);
|
||||
}
|
||||
}
|
||||
|
||||
public void testCheckCompatibilityOutPinMissing() {
|
||||
Circuit circuit = new Circuit()
|
||||
.add(new VisualElement(In.DESCRIPTION.getName()).setPos(vec(0, 0)).setAttribute(Keys.LABEL, "in"))
|
||||
.add(new VisualElement(Out.DESCRIPTION.getName()).setPos(vec(20, 0)).setAttribute(Keys.LABEL, "out"))
|
||||
.add(new VisualElement(Out.DESCRIPTION.getName()).setPos(vec(20, 20)).setAttribute(Keys.LABEL, "out2"));
|
||||
|
||||
try {
|
||||
custom.checkCompatibility(circuit);
|
||||
fail();
|
||||
} catch (PinException e) {
|
||||
assertTrue(true);
|
||||
}
|
||||
}
|
||||
|
||||
public void testCheckCompatibilityOutPinToMuch() {
|
||||
Circuit circuit = new Circuit()
|
||||
.add(new VisualElement(In.DESCRIPTION.getName()).setPos(vec(0, 0)).setAttribute(Keys.LABEL, "in"));
|
||||
|
||||
try {
|
||||
custom.checkCompatibility(circuit);
|
||||
fail();
|
||||
} catch (PinException e) {
|
||||
assertTrue(true);
|
||||
}
|
||||
}
|
||||
public void testCheckCompatibilityInPinToMuch() {
|
||||
Circuit circuit = new Circuit()
|
||||
.add(new VisualElement(Out.DESCRIPTION.getName()).setPos(vec(0, 0)).setAttribute(Keys.LABEL, "out"));
|
||||
|
||||
try {
|
||||
custom.checkCompatibility(circuit);
|
||||
fail();
|
||||
} catch (PinException e) {
|
||||
assertTrue(true);
|
||||
}
|
||||
}
|
||||
}
|
@ -514,7 +514,7 @@ public class SvgImporterTest extends TestCase {
|
||||
//*****************************************************************************************************
|
||||
|
||||
|
||||
private InputStream in(String s) {
|
||||
static InputStream in(String s) {
|
||||
return new ByteArrayInputStream(s.getBytes());
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user