mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 09:12:09 +10:00
add unit tests for netlist
This commit is contained in:
@@ -27,6 +27,8 @@ import java.util.HashSet;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import org.diylc.core.IDIYComponent;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a group of {@link Node}s that are connected together.
|
* Represents a group of {@link Node}s that are connected together.
|
||||||
*
|
*
|
||||||
@@ -45,6 +47,11 @@ public class Group implements Comparable<Group> {
|
|||||||
nodes.add(node2);
|
nodes.add(node2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Group connect(IDIYComponent<?> component, int index) {
|
||||||
|
getNodes().add(new Node(component, index));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public Set<Node> getNodes() {
|
public Set<Node> getNodes() {
|
||||||
return nodes;
|
return nodes;
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-3
@@ -28,11 +28,11 @@ import java.util.Set;
|
|||||||
|
|
||||||
import org.diylc.core.IDIYComponent;
|
import org.diylc.core.IDIYComponent;
|
||||||
|
|
||||||
public abstract class AbstractNetlistAnalyzer {
|
public class NetlistAnalyzer {
|
||||||
|
|
||||||
public AbstractNetlistAnalyzer() {}
|
public NetlistAnalyzer() {}
|
||||||
|
|
||||||
protected Tree constructTreeBetween(Netlist netlist, Node nodeA, Node nodeB) {
|
public Tree constructTreeBetween(Netlist netlist, Node nodeA, Node nodeB) {
|
||||||
Tree tree = new Tree(TreeConnectionType.Parallel);
|
Tree tree = new Tree(TreeConnectionType.Parallel);
|
||||||
connectNodes(netlist, nodeA, nodeB, tree.getChildren(), new Tree(TreeConnectionType.Series), new HashSet<Node>());
|
connectNodes(netlist, nodeA, nodeB, tree.getChildren(), new Tree(TreeConnectionType.Series), new HashSet<Node>());
|
||||||
|
|
||||||
@@ -22,6 +22,8 @@
|
|||||||
package org.diylc.netlist;
|
package org.diylc.netlist;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class Tree {
|
public class Tree {
|
||||||
@@ -98,6 +100,19 @@ public class Tree {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private List<Tree> getOrderedChildren() {
|
||||||
|
if (getConnectionType() == TreeConnectionType.Series)
|
||||||
|
return children;
|
||||||
|
List<Tree> ordered = new ArrayList<Tree>(children);
|
||||||
|
Collections.sort(ordered, new Comparator<Tree>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compare(Tree o1, Tree o2) {
|
||||||
|
return o1.toString().compareToIgnoreCase(o2.toString());
|
||||||
|
}});
|
||||||
|
return ordered;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
if (leaf != null)
|
if (leaf != null)
|
||||||
@@ -105,7 +120,7 @@ public class Tree {
|
|||||||
|
|
||||||
StringBuilder sb = new StringBuilder("(");
|
StringBuilder sb = new StringBuilder("(");
|
||||||
boolean first = true;
|
boolean first = true;
|
||||||
for(Tree child : children) {
|
for(Tree child : getOrderedChildren()) {
|
||||||
if (!first)
|
if (!first)
|
||||||
sb.append(" " ).append(connectionType).append(" ");
|
sb.append(" " ).append(connectionType).append(" ");
|
||||||
first = false;
|
first = false;
|
||||||
@@ -119,6 +134,8 @@ public class Tree {
|
|||||||
if (leaf != null)
|
if (leaf != null)
|
||||||
return leaf.toHTML();
|
return leaf.toHTML();
|
||||||
|
|
||||||
|
List<Tree> children = getOrderedChildren();
|
||||||
|
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
if (depth > 0 && children.size() > 1)
|
if (depth > 0 && children.size() > 1)
|
||||||
sb.append("(");
|
sb.append("(");
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<classpath>
|
<classpath>
|
||||||
<classpathentry kind="src" path="src"/>
|
<classpathentry kind="src" path="src"/>
|
||||||
|
<classpathentry kind="src" path="test"/>
|
||||||
<classpathentry kind="lib" path="lib/log4j-1.2.15.jar"/>
|
<classpathentry kind="lib" path="lib/log4j-1.2.15.jar"/>
|
||||||
<classpathentry kind="lib" path="lib/app-framework.jar"/>
|
<classpathentry kind="lib" path="lib/app-framework.jar"/>
|
||||||
<classpathentry kind="lib" path="lib/jep-2.4.1.jar"/>
|
<classpathentry kind="lib" path="lib/jep-2.4.1.jar"/>
|
||||||
@@ -8,5 +9,6 @@
|
|||||||
<classpathentry combineaccessrules="false" kind="src" path="/diylc-core"/>
|
<classpathentry combineaccessrules="false" kind="src" path="/diylc-core"/>
|
||||||
<classpathentry kind="lib" path="lib/xstream-1.4.3.jar"/>
|
<classpathentry kind="lib" path="lib/xstream-1.4.3.jar"/>
|
||||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jdk1.6.0_45"/>
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jdk1.6.0_45"/>
|
||||||
|
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
|
||||||
<classpathentry kind="output" path="bin"/>
|
<classpathentry kind="output" path="bin"/>
|
||||||
</classpath>
|
</classpath>
|
||||||
|
|||||||
Binary file not shown.
@@ -37,7 +37,7 @@ import org.diylc.components.guitar.SingleCoilPickup;
|
|||||||
import org.diylc.components.passive.PotentiometerPanel;
|
import org.diylc.components.passive.PotentiometerPanel;
|
||||||
import org.diylc.core.IDIYComponent;
|
import org.diylc.core.IDIYComponent;
|
||||||
|
|
||||||
public class GuitarDiagramAnalyzer extends AbstractNetlistAnalyzer implements INetlistAnalyzer {
|
public class GuitarDiagramAnalyzer extends NetlistAnalyzer implements INetlistAnalyzer {
|
||||||
|
|
||||||
private static Set<String> JACK_TYPES = new HashSet<String>();
|
private static Set<String> JACK_TYPES = new HashSet<String>();
|
||||||
private static Set<String> POT_TYPES = new HashSet<String>();
|
private static Set<String> POT_TYPES = new HashSet<String>();
|
||||||
|
|||||||
@@ -0,0 +1,126 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
|
DIY Layout Creator (DIYLC).
|
||||||
|
Copyright (c) 2009-2018 held jointly by the individual authors.
|
||||||
|
|
||||||
|
This file is part of DIYLC.
|
||||||
|
|
||||||
|
DIYLC is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
DIYLC is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with DIYLC. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
*/
|
||||||
|
package org.diylc.netlist;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
|
import org.diylc.components.electromechanical.OpenJack1_4;
|
||||||
|
import org.diylc.components.guitar.HumbuckerPickup;
|
||||||
|
import org.diylc.components.guitar.SingleCoilPickup;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class NetlistAnalyzerTests {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testOneSinglePickup() throws TreeException {
|
||||||
|
OpenJack1_4 jack = new OpenJack1_4();
|
||||||
|
SingleCoilPickup pickup = new SingleCoilPickup();
|
||||||
|
pickup.setName("Pickup");
|
||||||
|
Netlist netlist = new Netlist();
|
||||||
|
Group tipGroup = new Group().connect(jack, 0).connect(pickup, 1);
|
||||||
|
Group sleeveGroup = new Group().connect(jack, 1).connect(pickup, 2);
|
||||||
|
netlist.getGroups().add(tipGroup);
|
||||||
|
netlist.getGroups().add(sleeveGroup);
|
||||||
|
Tree tree = new GuitarDiagramAnalyzer().constructTree(netlist);
|
||||||
|
String s = tree.toString();
|
||||||
|
assertEquals("((Pickup.North<-))", s);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testOneSinglePickupReverse() throws TreeException {
|
||||||
|
OpenJack1_4 jack = new OpenJack1_4();
|
||||||
|
SingleCoilPickup pickup = new SingleCoilPickup();
|
||||||
|
pickup.setName("Pickup");
|
||||||
|
Netlist netlist = new Netlist();
|
||||||
|
Group tipGroup = new Group().connect(jack, 0).connect(pickup, 2);
|
||||||
|
Group sleeveGroup = new Group().connect(jack, 1).connect(pickup, 1);
|
||||||
|
netlist.getGroups().add(tipGroup);
|
||||||
|
netlist.getGroups().add(sleeveGroup);
|
||||||
|
Tree tree = new GuitarDiagramAnalyzer().constructTree(netlist);
|
||||||
|
String s = tree.toString();
|
||||||
|
assertEquals("((Pickup.North->))", s);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testOneHumbuckerSeries() throws TreeException {
|
||||||
|
OpenJack1_4 jack = new OpenJack1_4();
|
||||||
|
HumbuckerPickup pickup = new HumbuckerPickup();
|
||||||
|
pickup.setName("Pickup");
|
||||||
|
Netlist netlist = new Netlist();
|
||||||
|
Group tipGroup = new Group().connect(jack, 0).connect(pickup, 0);
|
||||||
|
Group coilTapGroup = new Group().connect(pickup, 1).connect(pickup, 2);
|
||||||
|
Group sleeveGroup = new Group().connect(jack, 1).connect(pickup, 3);
|
||||||
|
netlist.getGroups().add(tipGroup);
|
||||||
|
netlist.getGroups().add(coilTapGroup);
|
||||||
|
netlist.getGroups().add(sleeveGroup);
|
||||||
|
Tree tree = new GuitarDiagramAnalyzer().constructTree(netlist);
|
||||||
|
String s = tree.toString();
|
||||||
|
assertEquals("((Pickup.North<- + Pickup.South<-))", s);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testOneHumbuckerSeriesReverse() throws TreeException {
|
||||||
|
OpenJack1_4 jack = new OpenJack1_4();
|
||||||
|
HumbuckerPickup pickup = new HumbuckerPickup();
|
||||||
|
pickup.setName("Pickup");
|
||||||
|
Netlist netlist = new Netlist();
|
||||||
|
Group tipGroup = new Group().connect(jack, 0).connect(pickup, 3);
|
||||||
|
Group coilTapGroup = new Group().connect(pickup, 1).connect(pickup, 2);
|
||||||
|
Group sleeveGroup = new Group().connect(jack, 1).connect(pickup, 0);
|
||||||
|
netlist.getGroups().add(tipGroup);
|
||||||
|
netlist.getGroups().add(coilTapGroup);
|
||||||
|
netlist.getGroups().add(sleeveGroup);
|
||||||
|
Tree tree = new GuitarDiagramAnalyzer().constructTree(netlist);
|
||||||
|
String s = tree.toString();
|
||||||
|
assertEquals("((Pickup.South-> + Pickup.North->))", s);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testOneHumbuckerParallel() throws TreeException {
|
||||||
|
OpenJack1_4 jack = new OpenJack1_4();
|
||||||
|
HumbuckerPickup pickup = new HumbuckerPickup();
|
||||||
|
pickup.setName("Pickup");
|
||||||
|
Netlist netlist = new Netlist();
|
||||||
|
Group tipGroup = new Group().connect(jack, 0).connect(pickup, 0).connect(pickup, 2);
|
||||||
|
Group sleeveGroup = new Group().connect(jack, 1).connect(pickup, 1).connect(pickup, 3);
|
||||||
|
netlist.getGroups().add(tipGroup);
|
||||||
|
netlist.getGroups().add(sleeveGroup);
|
||||||
|
Tree tree = new GuitarDiagramAnalyzer().constructTree(netlist);
|
||||||
|
String s = tree.toString();
|
||||||
|
assertEquals("((Pickup.South<-) || (Pickup.North<-))", s);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testOneHumbuckerParallelOutOfPhase() throws TreeException {
|
||||||
|
OpenJack1_4 jack = new OpenJack1_4();
|
||||||
|
HumbuckerPickup pickup = new HumbuckerPickup();
|
||||||
|
pickup.setName("Pickup");
|
||||||
|
Netlist netlist = new Netlist();
|
||||||
|
Group tipGroup = new Group().connect(jack, 0).connect(pickup, 0).connect(pickup, 3);
|
||||||
|
Group sleeveGroup = new Group().connect(jack, 1).connect(pickup, 1).connect(pickup, 2);
|
||||||
|
netlist.getGroups().add(tipGroup);
|
||||||
|
netlist.getGroups().add(sleeveGroup);
|
||||||
|
Tree tree = new GuitarDiagramAnalyzer().constructTree(netlist);
|
||||||
|
String s = tree.toString();
|
||||||
|
assertEquals("((Pickup.North<-) || (Pickup.South->))", s);
|
||||||
|
}
|
||||||
|
}
|
||||||
Binary file not shown.
Binary file not shown.
@@ -2470,6 +2470,18 @@
|
|||||||
<releaseDate>2019-02-03 00:00:00.000 CET</releaseDate>
|
<releaseDate>2019-02-03 00:00:00.000 CET</releaseDate>
|
||||||
<name></name>
|
<name></name>
|
||||||
<changes>
|
<changes>
|
||||||
|
<org.diylc.appframework.update.Change>
|
||||||
|
<changeType>NEW_FEATURE</changeType>
|
||||||
|
<description>"Create Netlist" feature added under File -> Analyze</description>
|
||||||
|
</org.diylc.appframework.update.Change>
|
||||||
|
<org.diylc.appframework.update.Change>
|
||||||
|
<changeType>NEW_FEATURE</changeType>
|
||||||
|
<description>"Analyze Guitar Wiring" feature added under File -> Analyze</description>
|
||||||
|
</org.diylc.appframework.update.Change>
|
||||||
|
<org.diylc.appframework.update.Change>
|
||||||
|
<changeType>NEW_FEATURE</changeType>
|
||||||
|
<description>Guitar pickups now have separate terminals for start and finish point of each coil. Single coil pickups have polarity property added</description>
|
||||||
|
</org.diylc.appframework.update.Change>
|
||||||
<org.diylc.appframework.update.Change>
|
<org.diylc.appframework.update.Change>
|
||||||
<changeType>NEW_FEATURE</changeType>
|
<changeType>NEW_FEATURE</changeType>
|
||||||
<description>Added center-OFF options for "Mini Toggle Switch"</description>
|
<description>Added center-OFF options for "Mini Toggle Switch"</description>
|
||||||
|
|||||||
Reference in New Issue
Block a user