Last active
December 22, 2018 10:08
-
-
Save arwankhoiruddin/2fa1db8b1de740a3af6e21eaef08dc4d to your computer and use it in GitHub Desktop.
Basic structure of graph for testing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sun.awt.image.ImageWatched; | |
import java.util.Iterator; | |
import java.util.LinkedList; | |
public class NodeBasedTests { | |
public static void main(String[] args) { | |
PartA partA = new PartA(); | |
PartB partB = new PartB(); | |
PartC partC = new PartC(); | |
PartD partD = new PartD(); | |
PartE partE = new PartE(); | |
PartF partF = new PartF(); | |
TestGraph testGraph = new TestGraph(); | |
testGraph.addVertex(partA); | |
testGraph.addVertex(partB); | |
testGraph.addVertex(partC); | |
testGraph.addVertex(partD); | |
testGraph.addVertex(partE); | |
testGraph.addVertex(partF); | |
testGraph.addEdge(partA, partD); | |
testGraph.addEdge(partB, partD); | |
testGraph.addEdge(partB, partC); | |
System.out.println(); | |
testGraph.printConnected(partA); | |
System.out.println(); | |
testGraph.printConnected(partB); | |
} | |
} | |
class TestGraph { | |
private LinkedList<LinkedList<TestComponent>> testComponents = new LinkedList<>(); | |
public void addVertex(TestComponent vertex) { | |
LinkedList<TestComponent> vertexList = new LinkedList<>(); | |
vertexList.add(vertex); | |
testComponents.add(vertexList); | |
} | |
public void addEdge(TestComponent source, TestComponent dest) { | |
LinkedList tmp; | |
Iterator iterator = testComponents.iterator(); | |
while (iterator.hasNext()) { | |
tmp = (LinkedList) iterator.next(); | |
if (tmp.getFirst().getClass().isInstance(source)) { | |
System.out.println(source.getClass()); | |
tmp.add(dest); | |
break; | |
} | |
} | |
} | |
public void printConnected(TestComponent vertex) { | |
LinkedList tmp; | |
Iterator iterator = testComponents.iterator(); | |
while (iterator.hasNext()) { | |
tmp = (LinkedList) iterator.next(); | |
TestComponent first = (TestComponent) tmp.getFirst(); | |
if (first.getClass().isInstance(vertex)) { | |
Iterator vertexIterator = tmp.iterator(); | |
while (vertexIterator.hasNext()) { | |
TestComponent v = (TestComponent) vertexIterator.next(); | |
System.out.println(v.getClass()); | |
} | |
break; | |
} | |
} | |
} | |
} | |
interface TestComponent { | |
public void nowTesting(); | |
} | |
class PartA implements TestComponent { | |
@Override | |
public void nowTesting() { | |
} | |
} | |
class PartB implements TestComponent { | |
@Override | |
public void nowTesting() { | |
} | |
} | |
class PartC implements TestComponent { | |
@Override | |
public void nowTesting() { | |
} | |
} | |
class PartD implements TestComponent { | |
@Override | |
public void nowTesting() { | |
} | |
} | |
class PartE implements TestComponent { | |
@Override | |
public void nowTesting() { | |
} | |
} | |
class PartF implements TestComponent { | |
@Override | |
public void nowTesting() { | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment