Answered step by step
Verified Expert Solution
Question
1 Approved Answer
marked as read only Current file: LabProgram.java // Ites aujucemcyrucrixurupri secoma AdjacencyMatrixGraph graph2 = new AdjacencyMatrixGraph(); System.out.print( ); System.out.print(AdjacencyMatrixGraph: ); System.out.print( ); boolean matPass =
marked as read only Current file: LabProgram.java // Ites aujucemcyrucr"ixur"upri secoma AdjacencyMatrixGraph graph2 = new AdjacencyMatrixGraph(); System.out.print(" "); System.out.print("AdjacencyMatrixGraph: "); System.out.print(" "); boolean matPass = testGraph(testFeedback, graph2); testFeedback.flush(); // Print test results System.out.print(" "); System.out.print("Summary:"); System.out.print(" "); System.out.print(" AdjacencyListGraph: "); System.out.print((adjPass ? "PASS" : "FAIL")); System.out.print(" "); System.out.print(" AdjacencyMatrixGraph: "); System.out.print((matPass ? "PASS" : "FAIL")); System.out.print(" ); testFeedback.close(); \} public static boolean testGraph(PrintWriter testFeedback, DirectedGraph graph) \{ ArrayList> commands = new ArrayList>(){ \{ add(new AddVertexCommand("A", true)); add(new AddVertexCommand("B", true)); // Verify that vertices A and B exist, but not C,D, or E add(new GetVertexCommand("C", false)); add(new GetVertexCommand("A", true)); add(new GetVertexCommand("B", true)); add(new GetVertexCommand("E", false)); add(new GetVertexCommand("D", false)); // Add remaining vertices add(new AddVertexCommand("C", true)); add(new AddVertexCommand("D", true)); add(new AddVertexCommand("E", true)); // Add edges add(new AddEdgeCommand("B", "C", true)); add(new AddEdgeCommand("C", "A", true)); add(new AddEdgeCommand("C", "D", true)); add(new AddEdgeCommand("C", "E", true)); add(new AddEdgeCommand("D", "C", true)); add(new AddEdgeCommand("E", "A", true)); add(new AddEdgeCommand("E", "D", true)); // Attempts to add a duplicate edge should fail add(new AddEdgeCommand("C", "E", false)); add(new AddEdgeCommand("D", "C", false)); add(new VerifyEdgesFromCommand("A", (new ArrayList(Arrays.asList())))); add(new VerifyEdgesFromCommand("B", (new ArrayList(Arrays.asList("C"))))); add(new VerifyEdgesFromCommand("C", (new ArrayList(Arrays.asList("A", "D", "E"))))); add(new VerifyEdgesFromCommand("D", (new ArrayList(Arrays.asList("C"))))); add(new VerifyEdgesFromCommand("E", (new ArrayList(Arrays.asList("A", "D"))))); add(new VerifyEdgesToCommand("A", (new ArrayList(Arrays.asList("C", "E"))))); add(new VerifyEdgesToCommand("B", (new ArrayList(Arrays.asList())))); add(new VerifyEdgesToCommand("C", (new ArrayList(Arrays.asList("B", "D"))))); add(new VerifyEdgesToCommand("D", (new ArrayList(Arrays.asList("C", "E"))))); add(new VerifyEdgesToCommand("E", (new ArrayList(Arrays.asList("C"))))); // Verify some edges add(new HasEdgeCommand("A", "C", false)); add(new HasEdgeCommand("A", "E", false)); add(new HasEdgeCommand ("B", "C", true)); add(new HasEdgeCommand("C", "A", true)); add(new HasEdgeCommand ("C", "A", true)) ; add(new HasEdgeCommand ("C", "B", false)); add(new HasEdgeCommand ("C", "D", true)); add(new HasEdgeCommand ("C", "E", true)); add(new HasEdgeCommand ("D", "C", true)); add(new HasEdgeCommand("E", "A", true)); add(new HasEdgeCommand("E", "C", false)); add(new HasEdgeCommand("E", "D", true)); \} \} ; // Execute each test command, stopping if any command fails for (DirectedGraphTestCommand command : commands) \{ boolean pass = command. execute(testFeedback, graph); command = null; if (!pass) \{ return false; \} \} return true; \} \} File is marked as read only Current file: import java.io.*; public class Vertex \{ protected String label =""; public Vertex(String vertexLabel) \{ label = vertexLabel; \} public String getLabel() \{ return label; \} // Prints this vertex's label public void print(Printwriter output) \{ output.write(label); \} public void setLabel(String newLabel) \{ label = newLabel; \} \} is marked as read only Current file: Edge.java import java.io.*; public class Edge \{ public Vertex fromVertex; public Vertex toVertex; public Edge(Vertex from, Vertex to) \{ fromvertex = from; tovertex = to; \} public boolean equalsTo(Edge other) \{ return fromvertex == other. fromvertex \&\& toVertex == other.toVertex; \} public boolean notEqualsTo(Edge other) \{ return !(this.equalsTo(other)); \} // Prints this edge in the form "A to B ", where " A " is fromvertex's label // and " B " is tovertex's label. public void print(Printwriter output) \{ fromvertex.print(output); output.write(" to "); tovertex.print(output); \} \} import java.util.*; // Abstract base class for a directed, non-weighted graph public abstract class DirectedGraph \{ // Creates and adds a new vertex to the graph, provided a vertex with the // same label doesn't already exist in the graph. Returns the new vertex on // success, null on failure. public abstract Vertex addVertex(String newVertexLabel); // Adds a directed edge from the first to the second vertex. No change is // made and false is returned if the edge already exists in the graph. // Otherwise the new edge is added and true is returned. public abstract boolean addDirectedEdge(Vertex fromVertex, Vertex toVertex); // Returns an Arraylist of edges with the specified fromvertex. public abstract ArrayList getEdgesFrom(Vertex fromVertex); // Returns an ArrayList of edges with the specified tovertex public abstract ArrayList getEdgesTo(Vertex toVertex); // Returns a vertex with a matching label, or null if no such vertex // exists public abstract Vertex getVertex(String vertexLabel); // Returns true if this graph has an edge from fromvertex to tovertex public abstract boolean hasEdge(Vertex fromVertex, Vertex toVertex); \} import java.util.*; public class AdjacencyListVertex extends Vertex \{ // Arraylist of vertices adjacent to this vertex. For each vertex V in this // Arraylist, V is adjacent to this vertex, meaning an edge from this vertex to //V exists in the graph. public ArrayList Vertex > adjacent = new ArrayList Vertex >(); public AdjacencyListVertex(String label) \{ super(label); \} \} file: import java.util.*; public class AdjacencyListGraph extends DirectedGraph \{ protected ArrayList vertices = new ArrayList= new Vertex(newNertexLabel); if (!vertices.contains(newVertex)) \{ vertices.add (newVertex); adjacencyList.add(new ArrayList()); return newVertex; \} return null; \} // Adds a directed edge from the first to the second vertex. If the edge // already exists in the graph, no change is made and false is returned. // Otherwise the new edge is added and true is returned. @override public boolean addDirectedEdge(Vertex fromVertex, Vertex toVertex) \{ if (fromVertex == null || toVertex == null) \{ return false; \} Edge newEdge = new Edge(fromVertex, toVertex); if (!adjacencyList.get(vertices.indexOf(fromVertex)).contains(newEdge)) \{ adjacencyList.get(vertices.indexOf(fromVertex)).add(newEdge); return true; \} return false; \} // Returns an ArrayList of edges with the specified fromVertex. @override public ArrayList getEdgesFrom(Vertex fromVertex) \{ if (fromvertex == null ! vertices.contains(fromVertex)) \{ return new ArrayList(); \} return adjacencyList.get(vertices.indexof(fromVertex)); \} // Returns an Arraylist of edges with the specified tovertex. @override public ArrayList getEdgesTo(Vertex toVertex) \{ if (toVertex == null || ! vertices.contains(toVertex)) \{ return new ArrayList(); \} ArrayList edgesToVertex = new ArrayList(); for (ArrayList edges : adjacencyList) \{ for (Edge edge : edges) \{ if (edge.toVertex.equals(toVertex)) \{ edgesToVertex.add(edge); \} \} \} return edgesToVertex; \} // Returns a vertex with a matching label, or null if no such vertex // exists @override public Vertex getVertex(String vertexLabel) \{ for (Vertex vertex : vertices) \{ if (vertex.getLabel().equals(vertexLabel)) \{ if (vertex.getLabel().equals(vertexLabel)) \{ return vertex; \} \} return null; \} // Returns true if this graph has an edge from fromvertex to tovertex @override public boolean hasEdge(Vertex fromVertex, Vertex toVertex) \{ if (fromvertex == null || toVertex == null) \{ return false; \} Edge testEdge = new Edge(fromVertex, toVertex); return adjacencyList.get(vertices.indexOf(fromVertex)).contains(testEdge); \} \} file: Load default templa import java.util.*; public class AdjacencyMatrixGraph extends DirectedGraph \{ protected ArrayList Vertex > vertices = new ArrayList Vertex >(); // If matrixRows [X][Y] is true, then an edge exists from vertices [X] to // vertices [Y] protected ArrayList> matrixRows = new ArrayList>(); // Your additional code here, if desired // Creates and adds a new vertex to the graph, provided a vertex with the // same label doesn't already exist in the graph. Returns the new vertex on // success, null on failure. @override public Vertex addVertex(String newNertexLabel) \{ Vertex newVertex = new Vertex (newVertexLabel); if (!vertices.contains(newVertex)) \{ vertices.add (newVertex); // Add a new row in the matrix ArrayList newRow = new ArrayList(Collections.nCopies(vertices.size(), false)); matrixRows . add (newRow); // Update existing rows with a new column for (ArrayList row : matrixRows) \{ row.add(false); \} return newVertex; \} return null; \} // Adds a directed edge from the first to the second vertex. If the edge // already exists in the graph, no change is made and false is returned. // Otherwise the new edge is added and true is returned. @override public boolean addDirectedEdge(Vertex fromVertex, Vertex toVertex) \{ if (fromVertex == null || toVertex == null) \{ return false; \} int fromIndex = vertices.indexOf(fromVertex); int toIndex = vertices.indexOf(tovertex); if (fromIndex != -1 \&\& toIndex != -1 \&\& !matrixRows.get(fromIndex).get(toIndex)) \{ matrixRows.get(fromIndex).set(toIndex, true); return true; \} return false; \} // Returns an Arraylist of edges with the specified fromvertex. @override public ArrayList getEdgesFrom(Vertex fromVertex) \{ ArrayList edgesToVertex = new ArrayList(); int toIndex = vertices.indexof(toVertex); if (toIndex !=1 ) \{ for (int fromIndex =0; fromIndex = vertices.get (fromIndex); edgesToVertex.add(new Edge(fromVertex, toVertex)); \} \} \} // Returns an Arraylist of edges with the specified tovertex. @override public ArrayList getEdgesTo(Vertex toVertex) \{ // Your code here (remove placeholder line below) return new ArrayList(); \} // Returns a vertex with a matching label, or null if no such vertex // exists @override public Vertex getVertex(String vertexLabel) \{ for (Vertex vertex : vertices) \{ if (vertex.getLabel().equals(vertexLabel)) \{ return vertex; \} \} return null; \} // Returns true if this graph has an edge from fromvertex to tovertex @override public boolean hasEdge(Vertex fromVertex, Vertex toVertex) \{ int fromIndex = vertices.indexof(fromVertex); int toIndex = vertices.indexOf(toVertex); return fromIndex !=1 \&\& toIndex !=1 \&\& matrixRows.get(fromIndex).get(to Inde \} \} file: import java.util.*; import java.io.*; bublic abstract class DirectedGraphTestCommand \{ // Returns true if the test passes, false if the test fails public abstract boolean execute(PrintWriter testFeedback, DirectedGraph graph); // Utility function that checks if an Arraylist of edges has a particular edge public boolean hasEdge(ArrayList edges, Vertex fromVertex, Vertex toVertex) \{ // Iterate through the ArrayList's edges for (Edge edge : edges) \{ if (edge.fromVertex == fromVertex \&\& edge.toVertex == toVertex) \{ return true; \} \} return false; \} public void printEdges(PrintWriter output, ArrayList edges, String separator, String prefix, String suffix) // Print the prefix string first output.write(prefix); // Print edges if (edges.size() !=0){ edges.get ( ) print(output); for (int i=1;i(toVertexLabels); \} @override public boolean execute(PrintWriter testFeedback, DirectedGraph graph) \{ // Find fromvertex Vertex fromVertex = graph.getVertex(fromLabel); if (fromvertex == null) \{ testFeedback.write("FAIL: getVertex(\"" + fromLabel + "\") returned "); testFeedback.write("null for a vertex that should exist" + " "); return false; \} // Ask the graph for edges from fromvertex ArrayList actual = graph.getEdgesFrom(fromVertex); boolean pass = true; if (actual.size () == toLabels.size()) \{ for (String toLabel : toLabels) \{ // Get the expected to-vertex Vertex expectedTo = graph.getVertex(toLabel); // If the actual Arraylist of vertices does not have the edge then the // test fails if (!hasEdge(actual, fromVertex, expectedTo)) \{ pass = false; break; \} \} \} else \{ pass = false; \} // Print pass or fail message along with actual and expected collections testFeedback.write((pass ? "PASS" : "FAIL")); testFeedback.write(": Get edges from \""+ fromLabel + "\"" + " "); printEdges(testFeedback, actual,",", " Actual: {","} " ); testFeedback.write(" Expected: \{"); if (toLabels.size() !=0){ testFeedback.write(fromLabel + " to " + toLabels.get( ) ); for (int i=1;i commands = new ArrayList>(){ \{ add(new AddVertexCommand("A", true)); add(new AddVertexCommand("B", true)); // Verify that vertices A and B exist, but not C,D, or E add(new GetVertexCommand("C", false)); add(new GetVertexCommand("A", true)); add(new GetVertexCommand("B", true)); add(new GetVertexCommand("E", false)); add(new GetVertexCommand("D", false)); // Add remaining vertices add(new AddVertexCommand("C", true)); add(new AddVertexCommand("D", true)); add(new AddVertexCommand("E", true)); // Add edges add(new AddEdgeCommand("B", "C", true)); add(new AddEdgeCommand("C", "A", true)); add(new AddEdgeCommand("C", "D", true)); add(new AddEdgeCommand("C", "E", true)); add(new AddEdgeCommand("D", "C", true)); add(new AddEdgeCommand("E", "A", true)); add(new AddEdgeCommand("E", "D", true)); // Attempts to add a duplicate edge should fail add(new AddEdgeCommand("C", "E", false)); add(new AddEdgeCommand("D", "C", false)); add(new VerifyEdgesFromCommand("A", (new ArrayList(Arrays.asList())))); add(new VerifyEdgesFromCommand("B", (new ArrayList(Arrays.asList("C"))))); add(new VerifyEdgesFromCommand("C", (new ArrayList(Arrays.asList("A", "D", "E"))))); add(new VerifyEdgesFromCommand("D", (new ArrayList(Arrays.asList("C"))))); add(new VerifyEdgesFromCommand("E", (new ArrayList(Arrays.asList("A", "D"))))); add(new VerifyEdgesToCommand("A", (new ArrayList(Arrays.asList("C", "E"))))); add(new VerifyEdgesToCommand("B", (new ArrayList(Arrays.asList())))); add(new VerifyEdgesToCommand("C", (new ArrayList(Arrays.asList("B", "D"))))); add(new VerifyEdgesToCommand("D", (new ArrayList(Arrays.asList("C", "E"))))); add(new VerifyEdgesToCommand("E", (new ArrayList(Arrays.asList("C"))))); // Verify some edges add(new HasEdgeCommand("A", "C", false)); add(new HasEdgeCommand("A", "E", false)); add(new HasEdgeCommand ("B", "C", true)); add(new HasEdgeCommand("C", "A", true)); add(new HasEdgeCommand ("C", "A", true)) ; add(new HasEdgeCommand ("C", "B", false)); add(new HasEdgeCommand ("C", "D", true)); add(new HasEdgeCommand ("C", "E", true)); add(new HasEdgeCommand ("D", "C", true)); add(new HasEdgeCommand("E", "A", true)); add(new HasEdgeCommand("E", "C", false)); add(new HasEdgeCommand("E", "D", true)); \} \} ; // Execute each test command, stopping if any command fails for (DirectedGraphTestCommand command : commands) \{ boolean pass = command. execute(testFeedback, graph); command = null; if (!pass) \{ return false; \} \} return true; \} \} File is marked as read only Current file: import java.io.*; public class Vertex \{ protected String label =""; public Vertex(String vertexLabel) \{ label = vertexLabel; \} public String getLabel() \{ return label; \} // Prints this vertex's label public void print(Printwriter output) \{ output.write(label); \} public void setLabel(String newLabel) \{ label = newLabel; \} \} is marked as read only Current file: Edge.java import java.io.*; public class Edge \{ public Vertex fromVertex; public Vertex toVertex; public Edge(Vertex from, Vertex to) \{ fromvertex = from; tovertex = to; \} public boolean equalsTo(Edge other) \{ return fromvertex == other. fromvertex \&\& toVertex == other.toVertex; \} public boolean notEqualsTo(Edge other) \{ return !(this.equalsTo(other)); \} // Prints this edge in the form "A to B ", where " A " is fromvertex's label // and " B " is tovertex's label. public void print(Printwriter output) \{ fromvertex.print(output); output.write(" to "); tovertex.print(output); \} \} import java.util.*; // Abstract base class for a directed, non-weighted graph public abstract class DirectedGraph \{ // Creates and adds a new vertex to the graph, provided a vertex with the // same label doesn't already exist in the graph. Returns the new vertex on // success, null on failure. public abstract Vertex addVertex(String newVertexLabel); // Adds a directed edge from the first to the second vertex. No change is // made and false is returned if the edge already exists in the graph. // Otherwise the new edge is added and true is returned. public abstract boolean addDirectedEdge(Vertex fromVertex, Vertex toVertex); // Returns an Arraylist of edges with the specified fromvertex. public abstract ArrayList getEdgesFrom(Vertex fromVertex); // Returns an ArrayList of edges with the specified tovertex public abstract ArrayList getEdgesTo(Vertex toVertex); // Returns a vertex with a matching label, or null if no such vertex // exists public abstract Vertex getVertex(String vertexLabel); // Returns true if this graph has an edge from fromvertex to tovertex public abstract boolean hasEdge(Vertex fromVertex, Vertex toVertex); \} import java.util.*; public class AdjacencyListVertex extends Vertex \{ // Arraylist of vertices adjacent to this vertex. For each vertex V in this // Arraylist, V is adjacent to this vertex, meaning an edge from this vertex to //V exists in the graph. public ArrayList Vertex > adjacent = new ArrayList Vertex >(); public AdjacencyListVertex(String label) \{ super(label); \} \} file: import java.util.*; public class AdjacencyListGraph extends DirectedGraph \{ protected ArrayList vertices = new ArrayList= new Vertex(newNertexLabel); if (!vertices.contains(newVertex)) \{ vertices.add (newVertex); adjacencyList.add(new ArrayList()); return newVertex; \} return null; \} // Adds a directed edge from the first to the second vertex. If the edge // already exists in the graph, no change is made and false is returned. // Otherwise the new edge is added and true is returned. @override public boolean addDirectedEdge(Vertex fromVertex, Vertex toVertex) \{ if (fromVertex == null || toVertex == null) \{ return false; \} Edge newEdge = new Edge(fromVertex, toVertex); if (!adjacencyList.get(vertices.indexOf(fromVertex)).contains(newEdge)) \{ adjacencyList.get(vertices.indexOf(fromVertex)).add(newEdge); return true; \} return false; \} // Returns an ArrayList of edges with the specified fromVertex. @override public ArrayList getEdgesFrom(Vertex fromVertex) \{ if (fromvertex == null ! vertices.contains(fromVertex)) \{ return new ArrayList(); \} return adjacencyList.get(vertices.indexof(fromVertex)); \} // Returns an Arraylist of edges with the specified tovertex. @override public ArrayList getEdgesTo(Vertex toVertex) \{ if (toVertex == null || ! vertices.contains(toVertex)) \{ return new ArrayList(); \} ArrayList edgesToVertex = new ArrayList(); for (ArrayList edges : adjacencyList) \{ for (Edge edge : edges) \{ if (edge.toVertex.equals(toVertex)) \{ edgesToVertex.add(edge); \} \} \} return edgesToVertex; \} // Returns a vertex with a matching label, or null if no such vertex // exists @override public Vertex getVertex(String vertexLabel) \{ for (Vertex vertex : vertices) \{ if (vertex.getLabel().equals(vertexLabel)) \{ if (vertex.getLabel().equals(vertexLabel)) \{ return vertex; \} \} return null; \} // Returns true if this graph has an edge from fromvertex to tovertex @override public boolean hasEdge(Vertex fromVertex, Vertex toVertex) \{ if (fromvertex == null || toVertex == null) \{ return false; \} Edge testEdge = new Edge(fromVertex, toVertex); return adjacencyList.get(vertices.indexOf(fromVertex)).contains(testEdge); \} \} file: Load default templa import java.util.*; public class AdjacencyMatrixGraph extends DirectedGraph \{ protected ArrayList Vertex > vertices = new ArrayList Vertex >(); // If matrixRows [X][Y] is true, then an edge exists from vertices [X] to // vertices [Y] protected ArrayList> matrixRows = new ArrayList>(); // Your additional code here, if desired // Creates and adds a new vertex to the graph, provided a vertex with the // same label doesn't already exist in the graph. Returns the new vertex on // success, null on failure. @override public Vertex addVertex(String newNertexLabel) \{ Vertex newVertex = new Vertex (newVertexLabel); if (!vertices.contains(newVertex)) \{ vertices.add (newVertex); // Add a new row in the matrix ArrayList newRow = new ArrayList(Collections.nCopies(vertices.size(), false)); matrixRows . add (newRow); // Update existing rows with a new column for (ArrayList row : matrixRows) \{ row.add(false); \} return newVertex; \} return null; \} // Adds a directed edge from the first to the second vertex. If the edge // already exists in the graph, no change is made and false is returned. // Otherwise the new edge is added and true is returned. @override public boolean addDirectedEdge(Vertex fromVertex, Vertex toVertex) \{ if (fromVertex == null || toVertex == null) \{ return false; \} int fromIndex = vertices.indexOf(fromVertex); int toIndex = vertices.indexOf(tovertex); if (fromIndex != -1 \&\& toIndex != -1 \&\& !matrixRows.get(fromIndex).get(toIndex)) \{ matrixRows.get(fromIndex).set(toIndex, true); return true; \} return false; \} // Returns an Arraylist of edges with the specified fromvertex. @override public ArrayList getEdgesFrom(Vertex fromVertex) \{ ArrayList edgesToVertex = new ArrayList(); int toIndex = vertices.indexof(toVertex); if (toIndex !=1 ) \{ for (int fromIndex =0; fromIndex = vertices.get (fromIndex); edgesToVertex.add(new Edge(fromVertex, toVertex)); \} \} \} // Returns an Arraylist of edges with the specified tovertex. @override public ArrayList getEdgesTo(Vertex toVertex) \{ // Your code here (remove placeholder line below) return new ArrayList(); \} // Returns a vertex with a matching label, or null if no such vertex // exists @override public Vertex getVertex(String vertexLabel) \{ for (Vertex vertex : vertices) \{ if (vertex.getLabel().equals(vertexLabel)) \{ return vertex; \} \} return null; \} // Returns true if this graph has an edge from fromvertex to tovertex @override public boolean hasEdge(Vertex fromVertex, Vertex toVertex) \{ int fromIndex = vertices.indexof(fromVertex); int toIndex = vertices.indexOf(toVertex); return fromIndex !=1 \&\& toIndex !=1 \&\& matrixRows.get(fromIndex).get(to Inde \} \} file: import java.util.*; import java.io.*; bublic abstract class DirectedGraphTestCommand \{ // Returns true if the test passes, false if the test fails public abstract boolean execute(PrintWriter testFeedback, DirectedGraph graph); // Utility function that checks if an Arraylist of edges has a particular edge public boolean hasEdge(ArrayList edges, Vertex fromVertex, Vertex toVertex) \{ // Iterate through the ArrayList's edges for (Edge edge : edges) \{ if (edge.fromVertex == fromVertex \&\& edge.toVertex == toVertex) \{ return true; \} \} return false; \} public void printEdges(PrintWriter output, ArrayList edges, String separator, String prefix, String suffix) // Print the prefix string first output.write(prefix); // Print edges if (edges.size() !=0){ edges.get ( ) print(output); for (int i=1;i(toVertexLabels); \} @override public boolean execute(PrintWriter testFeedback, DirectedGraph graph) \{ // Find fromvertex Vertex fromVertex = graph.getVertex(fromLabel); if (fromvertex == null) \{ testFeedback.write("FAIL: getVertex(\"" + fromLabel + "\") returned "); testFeedback.write("null for a vertex that should exist" + " "); return false; \} // Ask the graph for edges from fromvertex ArrayList actual = graph.getEdgesFrom(fromVertex); boolean pass = true; if (actual.size () == toLabels.size()) \{ for (String toLabel : toLabels) \{ // Get the expected to-vertex Vertex expectedTo = graph.getVertex(toLabel); // If the actual Arraylist of vertices does not have the edge then the // test fails if (!hasEdge(actual, fromVertex, expectedTo)) \{ pass = false; break; \} \} \} else \{ pass = false; \} // Print pass or fail message along with actual and expected collections testFeedback.write((pass ? "PASS" : "FAIL")); testFeedback.write(": Get edges from \""+ fromLabel + "\"" + " "); printEdges(testFeedback, actual,",", " Actual: {","} " ); testFeedback.write(" Expected: \{"); if (toLabels.size() !=0){ testFeedback.write(fromLabel + " to " + toLabels.get( ) ); for (int i=1;i
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started