From 2b1fecbed0cd576dc698c642589a200fdb99e9a5 Mon Sep 17 00:00:00 2001 From: Ethan Kelly Date: Wed, 28 Apr 2021 16:53:19 +0100 Subject: [PATCH] Override equals, hash and clone --- src/main/io/github/ethankelly/Equations.java | 30 ++++-- src/main/io/github/ethankelly/Graph.java | 96 ++++++++++++------- .../io/github/ethankelly/GraphGenerator.java | 48 +++++----- .../io/github/ethankelly/EquationsTest.java | 76 ++++++++++----- src/test/io/github/ethankelly/GraphTest.java | 19 ++++ 5 files changed, 179 insertions(+), 90 deletions(-) create mode 100644 src/test/io/github/ethankelly/GraphTest.java diff --git a/src/main/io/github/ethankelly/Equations.java b/src/main/io/github/ethankelly/Equations.java index 46f0880..42cbe1c 100644 --- a/src/main/io/github/ethankelly/Equations.java +++ b/src/main/io/github/ethankelly/Equations.java @@ -96,8 +96,9 @@ public static int getUpperBound(Graph g, char[] states, boolean closures) { public static int getLowerBound(int numVertices, char[] states, boolean closures) { //TODO this is true iff there are no cut vertices - Graph g = GraphGenerator.tree(numVertices); - assert g.isMinimallyConnected() : "Lower bound graph is not minimally connected"; + Graph g = GraphGenerator.cycle(numVertices); + assert g.getCutVertices().isEmpty() : "Lower bound graph should have no cut vertices"; + assert g.getConnectedComponents().size() == 1 : "Lower bound graph should be connected"; Tuple tuples = new Tuple(g, states, closures); return tuples.getTuples().size(); } @@ -110,18 +111,27 @@ public static int getLowerBound(Graph g, char[] states, boolean closures) { public static void main(String[] args) { char[] SIR = new char[]{'S', 'I', 'R'}; - char[] SIRP = new char[]{'S', 'I', 'R','P'}; - System.out.println("4-cycle"); - System.out.println("Upper bound with closures: " + getUpperBound(4, SIR, true)); - System.out.println("Lower bound with closures: " + getLowerBound(4, SIR, true)); - System.out.println("Upper bound without closures: " + getUpperBound(4, SIR, false)); - System.out.println("Lower bound without closures: " + getLowerBound(4, SIR, false)); Graph g = GraphGenerator.getLollipop(); System.out.println(g); System.out.print("\nCut vertices: "); g.getCutVertices().forEach(System.out::print); - System.out.println("\nUB with closures:" + getUpperBound(g, SIR, true)); - System.out.println("LB with closures:" + getLowerBound(g, SIR, true)); + System.out.println("\nUB with closures: " + getUpperBound(g.getNumVertices(), SIR, true)); + System.out.println("LB with closures: " + getLowerBound(g.getNumVertices(), SIR, true)); + List subGraphs = g.splice(); + for (Graph subGraph : subGraphs) { + System.out.println(subGraph); + } + + Graph h = GraphGenerator.getBowTie(); + System.out.println(h); + System.out.print("\nCut vertices: "); + h.getCutVertices().forEach(System.out::print); + System.out.println("\nUB with closures: " + getUpperBound(h.getNumVertices(), SIR, true)); + System.out.println("LB with closures: " + getLowerBound(h.getNumVertices(), SIR, true)); + List subGraphsH = h.splice(); + for (Graph subGraph : subGraphsH) { + System.out.println(subGraph); + } } } diff --git a/src/main/io/github/ethankelly/Graph.java b/src/main/io/github/ethankelly/Graph.java index fb74b87..dd24f86 100644 --- a/src/main/io/github/ethankelly/Graph.java +++ b/src/main/io/github/ethankelly/Graph.java @@ -1,9 +1,7 @@ package main.io.github.ethankelly; import java.text.MessageFormat; -import java.util.ArrayList; -import java.util.LinkedList; -import java.util.List; +import java.util.*; import java.util.stream.Collectors; import java.util.stream.IntStream; @@ -25,7 +23,7 @@ * * @author Ethan Kelly */ -public class Graph { +public class Graph implements Cloneable { private static final int NIL = -1; private String name; private int numVertices; @@ -38,19 +36,22 @@ public class Graph { * Class constructor. * * @param numVertices the number of vertices to create in the graph. + * @param adjMatrix + * @param transmissionMatrix */ - public Graph(int numVertices, String name) { + public Graph(int numVertices, String name, boolean[][] adjMatrix, int[][] transmissionMatrix) { this.numVertices = numVertices; - this.adjMatrix = new boolean[numVertices][numVertices]; - this.transmissionMatrix = new int[numVertices][numVertices]; this.name = name; + this.adjMatrix = adjMatrix; + this.transmissionMatrix = transmissionMatrix; + } public static void main(String[] args) { // testMethods(); // Create a graph given in the above diagram - Graph g = new Graph(5, "Test"); // 5 vertices numbered from 0 to 4 + Graph g = new Graph(5, "Test", new boolean[5][5], new int[5][5]); // 5 vertices numbered from 0 to 4 g.addEdge(0, 1); g.addEdge(0, 2); g.addEdge(1, 2); @@ -95,7 +96,7 @@ private static void testMethods() { g3.getCutVertices() + "\nTime: " + g3.time); - Graph g4 = new Graph(17, "Fig. 7"); + Graph g4 = new Graph(17, "Fig. 7", new boolean[17][17], new int[17][17]); g4.addEdge(0, 1); g4.addEdge(0, 3); g4.addEdge(1, 2); @@ -218,8 +219,8 @@ public List> getConnectedComponents() { } private Graph makeSubGraph(List vertices) { - - Graph subGraph = new Graph(vertices.size(), this.getName() + " Subgraph"); + //TODO Add cut-vertex back into sub-graph along with edges! + Graph subGraph = new Graph(vertices.size(), this.getName() + " Subgraph", new boolean[numVertices][numVertices], new int[numVertices][numVertices]); for (int v = 0; v < vertices.size(); v++) { for (int w = 0; w < this.getNumVertices(); w++) { if (this.isEdge(vertices.get(v), w) && vertices.contains(w)) subGraph.addEdge(v, vertices.indexOf(w)); @@ -300,17 +301,19 @@ public void removeEdge(int i, int j) { } public void removeBridges(int i) { - int numConnectedComponents = getConnectedComponents().size(); for (int j = 0; j < getNumVertices(); j++) { + int numConnectedComponents = getConnectedComponents().size(); if (isEdge(i, j)) { removeEdge(i, j); // Ensure any edges we remove are bridges; preserve other edges - if (getConnectedComponents().size() == numConnectedComponents) addEdge(i, j); - else for (List cc : getConnectedComponents()) if (cc.size() == 1) addEdge(i, j); + +// if (getConnectedComponents().size() != numConnectedComponents + 1) addEdge(i, j); +// else break; } } } + @SuppressWarnings("unused") public boolean isMinimallyConnected() { boolean minConnected = true; // Check if graph is connected at all @@ -323,6 +326,7 @@ public boolean isMinimallyConnected() { } } } + assert !minConnected || (this.getNumEdges() - 1 == this.getNumVertices()) : "There are n-1 edges in a minimally connected graph."; return minConnected; } @@ -375,26 +379,6 @@ public boolean isEdge(int i, int j) { return getAdjMatrix()[i][j] || getAdjMatrix()[j][i]; } - /** - * Returns a textual representation of a graph as an adjacency matrix to be printed to the standard output. - * - * @return a string representation of the graph. - */ - @Override - public String toString() { - int n = getNumVertices(); - boolean[][] matrix = getAdjMatrix(); - StringBuilder s = new StringBuilder(); - for (int i = 0; i < n; i++) { - s.append(i).append(": "); - for (boolean j : matrix[i]) { - s.append(j ? 1 : 0).append(" "); - } - s.append("\n"); - } - return s.toString(); - } - @SuppressWarnings("unchecked") // Helper - converts a boolean adjacency matrix to a linked list private LinkedList[] getAdjacencyList() { @@ -449,4 +433,48 @@ public Graph setName(String name) { return this; } + /** + * Returns a textual representation of a graph as an adjacency matrix to be printed to the standard output. + * + * @return a string representation of the graph. + */ + @Override + public String toString() { + int n = getNumVertices(); + boolean[][] matrix = getAdjMatrix(); + StringBuilder s = new StringBuilder(); + for (int i = 0; i < n; i++) { + s.append(i).append(": "); + for (boolean j : matrix[i]) { + s.append(j ? 1 : 0).append(" "); + } + s.append("\n"); + } + return s.toString(); + } + + @Override + public Graph clone() { + try { + return (Graph) super.clone(); + } catch (CloneNotSupportedException e) { + return new Graph(this.getNumVertices(), this.getName(), this.getAdjMatrix(), this.getTransmissionMatrix()); + } + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Graph graph = (Graph) o; + return getNumVertices() == graph.getNumVertices() && getNumEdges() == graph.getNumEdges() && Objects.equals(getName(), graph.getName()) && Arrays.equals(getAdjMatrix(), graph.getAdjMatrix()) && Arrays.equals(getTransmissionMatrix(), graph.getTransmissionMatrix()); + } + + @Override + public int hashCode() { + int result = Objects.hash(getName(), getNumVertices(), getNumEdges()); + result = 31 * result + Arrays.deepHashCode(getAdjMatrix()); + result = 31 * result + Arrays.deepHashCode(getTransmissionMatrix()); + return result; + } } diff --git a/src/main/io/github/ethankelly/GraphGenerator.java b/src/main/io/github/ethankelly/GraphGenerator.java index 4cb49b0..0ccd34e 100644 --- a/src/main/io/github/ethankelly/GraphGenerator.java +++ b/src/main/io/github/ethankelly/GraphGenerator.java @@ -29,7 +29,7 @@ public class GraphGenerator { */ public static Graph getToast() { // TOAST - Graph toast = new Graph(4, "Toast"); + Graph toast = new Graph(4, "Toast", new boolean[4][4], new int[4][4]); toast.addEdge(0, 1); toast.addEdge(0, 2); toast.addEdge(0, 3); @@ -43,7 +43,7 @@ public static Graph getToast() { */ public static Graph getLollipop() { // LOLLIPOP - Graph lollipop = new Graph(4, "Lollipop"); + Graph lollipop = new Graph(4, "Lollipop", new boolean[4][4], new int[4][4]); lollipop.addEdge(0, 1); lollipop.addEdge(0, 2); lollipop.addEdge(0, 3); @@ -56,7 +56,7 @@ public static Graph getLollipop() { */ public static Graph getBowTie() { // BOW TIE - Graph bowTie = new Graph(5, "Bow tie"); + Graph bowTie = new Graph(5, "Bow tie", new boolean[5][5], new int[5][5]); bowTie.addEdge(0, 1); bowTie.addEdge(0, 2); bowTie.addEdge(1, 2); @@ -68,7 +68,7 @@ public static Graph getBowTie() { public static Graph getBowTieWithBridge() { // BOW TIE WITH BRIDGE - Graph bowTieWithBridge = new Graph(6, "Bow tie with bridge"); + Graph bowTieWithBridge = new Graph(6, "Bow tie with bridge", new boolean[6][6], new int[6][6]); bowTieWithBridge.addEdge(0, 1); bowTieWithBridge.addEdge(0, 2); bowTieWithBridge.addEdge(1, 2); @@ -84,7 +84,7 @@ public static Graph getBowTieWithBridge() { */ public static Graph getTriangle() { // TRIANGLE - Graph triangle = new Graph(3, "Triangle"); + Graph triangle = new Graph(3, "Triangle", new boolean[3][3], new int[3][3]); triangle.addEdge(0, 1); triangle.addEdge(1, 2); triangle.addEdge(2, 0); @@ -109,8 +109,8 @@ private static void getUserGraphSelection(Scanner scan, String[] arguments) { if (scan.nextLine().equalsIgnoreCase("help")) { System.out.println(""" - Enter any of the following currently available graph types for generation: - 1. Toast + Enter any of the following currently available graph types for generation: + 1. Toast 2. Triangle 3. Lollipop 4. Simple @@ -126,7 +126,7 @@ private static void getUserGraphSelection(Scanner scan, String[] arguments) { 14. Wheel 15. Star 16. Regular - 17. Tree + 17. Tree Please enter either the number corresponding to the desired graph type or the name of the graph."""); } @@ -214,7 +214,7 @@ private static void getUserStates(Scanner scan, String[] arguments) { *** COMPARTMENTAL GRAPH MODEL EQUATIONS GENERATOR *** - Welcome to the Equations Generation program. This software generates the full system of differential + Welcome to the Equations Generation program. This software generates the full system of differential equations required to describe a particular compartmental model of disease on a specified graph. A text file will be generated in the same directory as you are running this software from. If you choose to run the jar again, this text file will be overwritten unless you move it elsewhere or delete it. @@ -367,7 +367,7 @@ public int compareTo(Edge that) { public static Graph simple(int numVertices, int numEdges) { assert numEdges <= numVertices * (numVertices - 1) / 2 : "Too many edges."; assert numEdges >= 0 : "Too few edges."; - Graph g = new Graph(numVertices, "Simple"); + Graph g = new Graph(numVertices, "Simple", new boolean[numVertices][numVertices], new int[numVertices][numVertices]); g.setNumEdges(0); Set set = new Set<>(); while (g.getNumEdges() < numEdges) { @@ -394,7 +394,7 @@ public static Graph simple(int numVertices, int numEdges) { */ public static Graph erdosRenyi(int numVertices, double probability) { assert !(probability < 0.0) && !(probability > 1.0) : "Probability must be between 0 and 1"; - Graph g = new Graph(numVertices, "Erdős–Rényi"); + Graph g = new Graph(numVertices, "Erdős–Rényi", new boolean[numVertices][numVertices], new int[numVertices][numVertices]); for (int v = 0; v < numVertices; v++) for (int w = v + 1; w < numVertices; w++) if (Rand.bernoulli(probability)) @@ -441,7 +441,9 @@ public static Graph completeBipartite(int numVer1, int numVer2) { public static Graph bipartite(int numVer1, int numVer2, int numEdges) { assert numEdges <= numVer1 * numVer2 : "Too many edges"; assert numEdges >= 0 : "Too few edges"; - Graph g = new Graph(numVer1 + numVer2, "Bipartite"); + Graph g = new Graph(numVer1 + numVer2, "Bipartite", + new boolean[numVer1 + numVer2][numVer1 + numVer2], + new int[numVer1 + numVer2][numVer1 + numVer2]); int[] vertices = IntStream.range(0, numVer1 + numVer2).toArray(); Rand.shuffle(vertices); @@ -475,7 +477,9 @@ public static Graph bipartite(int numVer1, int numVer2, double probability) { assert !(probability < 0.0) && !(probability > 1.0) : "Probability must be between 0 and 1"; int[] vertices = IntStream.range(0, numVer1 + numVer2).toArray(); Rand.shuffle(vertices); - Graph G = new Graph(numVer1 + numVer2, "Bipartite"); + Graph G = new Graph(numVer1 + numVer2, "Bipartite", + new boolean[numVer1 + numVer2][numVer1 + numVer2], + new int[numVer1 + numVer2][numVer1 + numVer2]); for (int i = 0; i < numVer1; i++) for (int j = 0; j < numVer2; j++) if (Rand.bernoulli(probability)) @@ -491,7 +495,7 @@ public static Graph bipartite(int numVer1, int numVer2, double probability) { * @return a path graph on {@code numVertices} vertices */ public static Graph path(int numVertices) { - Graph g = new Graph(numVertices, "Path"); + Graph g = new Graph(numVertices, "Path", new boolean[numVertices][numVertices], new int[numVertices][numVertices]); // Generate an array: [0, 1, ..., numVertices] and randomly shuffle it. int[] vertices = IntStream.range(0, numVertices).toArray(); Rand.shuffle(vertices); @@ -511,7 +515,7 @@ public static Graph path(int numVertices) { * @return a complete binary tree graph on {@code numVertices} vertices */ public static Graph binaryTree(int numVertices) { - Graph g = new Graph(numVertices, "Binary Tree"); + Graph g = new Graph(numVertices, "Binary Tree", new boolean[numVertices][numVertices], new int[numVertices][numVertices]); // Generate an array: [0, 1, ..., numVertices] and randomly shuffle it. int[] vertices = IntStream.range(0, numVertices).toArray(); Rand.shuffle(vertices); @@ -531,7 +535,7 @@ public static Graph binaryTree(int numVertices) { * @return a cycle graph on {@code numVertices} vertices. */ public static Graph cycle(int numVertices) { - Graph g = new Graph(numVertices, "Cycle"); + Graph g = new Graph(numVertices, "Cycle", new boolean[numVertices][numVertices], new int[numVertices][numVertices]); // Generate an array: [0, 1, ..., numVertices] and randomly shuffle it. int[] vertices = IntStream.range(0, numVertices).toArray(); Rand.shuffle(vertices); @@ -557,7 +561,7 @@ public static Graph eulerianPath(int numVertices, int numEdges) { // Catch incorrect input of number of edges or vertices assert numEdges >= 0 : "negative number of edges"; assert numVertices > 0 : "An Eulerian path must have at least one vertex"; - Graph g = new Graph(numVertices, "Eulerian Path"); + Graph g = new Graph(numVertices, "Eulerian Path", new boolean[numVertices][numVertices], new int[numVertices][numVertices]); // Fill an array of length equal to the number of edges with uniformly random values int[] vertices = IntStream.range(0, numEdges + 1).map(i -> Rand.uniform(numVertices)).toArray(); // Connect consecutive (i, i+1) vertices @@ -577,7 +581,7 @@ public static Graph eulerianPath(int numVertices, int numEdges) { public static Graph eulerianCycle(int numVertices, int numEdges) { assert numEdges > 0 : "An Eulerian cycle must have at least one edge"; assert numVertices > 0 : "An Eulerian cycle must have at least one vertex"; - Graph G = new Graph(numVertices, "Eulerian Cycle"); + Graph G = new Graph(numVertices, "Eulerian Cycle", new boolean[numVertices][numVertices], new int[numVertices][numVertices]); // Fill an array of length equal to the number of edges with uniformly random values int[] vertices = IntStream.range(0, numEdges).map(i -> Rand.uniform(numVertices)).toArray(); // Connect consecutive (i, i+1) vertices @@ -597,7 +601,7 @@ public static Graph eulerianCycle(int numVertices, int numEdges) { */ public static Graph wheel(int numVertices) { assert numVertices > 1 : "Number of vertices must be at least 2"; - Graph g = new Graph(numVertices, "Wheel"); + Graph g = new Graph(numVertices, "Wheel", new boolean[numVertices][numVertices], new int[numVertices][numVertices]); // Generate an array: [0, 1, ..., numVertices] and randomly shuffle it. int[] vertices = IntStream.range(0, numVertices).toArray(); Rand.shuffle(vertices); @@ -622,7 +626,7 @@ public static Graph wheel(int numVertices) { */ public static Graph star(int numVertices) { assert numVertices > 0 : "Number of vertices must be at least 1"; - Graph g = new Graph(numVertices, "Star"); + Graph g = new Graph(numVertices, "Star", new boolean[numVertices][numVertices], new int[numVertices][numVertices]); // Generate an array: [0, 1, ..., numVertices] and randomly shuffle it. int[] vertices = IntStream.range(0, numVertices).toArray(); Rand.shuffle(vertices); @@ -645,7 +649,7 @@ public static Graph star(int numVertices) { */ public static Graph regular(int numVertices, int k) { assert numVertices * k % 2 == 0 : "Number of vertices * k must be even"; - Graph g = new Graph(numVertices, k + "-Regular"); + Graph g = new Graph(numVertices, k + "-Regular", new boolean[numVertices][numVertices], new int[numVertices][numVertices]); // Create k copies of each vertex int[] vertices = new int[numVertices * k]; @@ -670,7 +674,7 @@ public static Graph regular(int numVertices, int k) { * @return a uniformly random tree on {@code numVertices} vertices. */ public static Graph tree(int numVertices) { - Graph g = new Graph(numVertices, "Tree"); + Graph g = new Graph(numVertices, "Tree", new boolean[numVertices][numVertices], new int[numVertices][numVertices]); if (numVertices == 1) return g; diff --git a/src/test/io/github/ethankelly/EquationsTest.java b/src/test/io/github/ethankelly/EquationsTest.java index 8126a6b..3a40659 100644 --- a/src/test/io/github/ethankelly/EquationsTest.java +++ b/src/test/io/github/ethankelly/EquationsTest.java @@ -9,65 +9,93 @@ class EquationsTest { @org.junit.jupiter.api.Test void testEdgeBoundsClosuresSIR() { + Assertions.assertEquals(Equations.getLowerBound(2, SIR, true), + Equations.getUpperBound(2, SIR, true), + "Upper and lower bounds should be same for single edge since cycle and connected are the same"); Assertions.assertEquals(7, Equations.getUpperBound(2, SIR, true), - "Upper bound should be 7."); - Assertions.assertEquals(4, Equations.getLowerBound(2, SIR, true), - "Lower bound should be 4."); + "Upper bound should be 7 equations."); + Assertions.assertEquals(7, Equations.getLowerBound(2, SIR, true), + "Lower bound should be 7 equations."); } @org.junit.jupiter.api.Test void testEdgeBoundsClosuresSIRP() { + Assertions.assertEquals(Equations.getLowerBound(2, SIRP, true), + Equations.getUpperBound(2, SIRP, true), + "Upper and lower bounds should be same for single edge since cycle and connected are the same"); Assertions.assertEquals(13, Equations.getUpperBound(2, SIRP, true), - "Upper bound should be 13."); - Assertions.assertEquals(6, Equations.getLowerBound(2, SIRP, true), - "Lower bound should be 6"); + "Upper bound should be 13 equations."); + Assertions.assertEquals(13, Equations.getLowerBound(2, SIRP, true), + "Lower bound should be 13 equations."); } @org.junit.jupiter.api.Test void testEdgeBoundsNoClosuresSIR() { + Assertions.assertEquals(Equations.getLowerBound(2, SIR, false), + Equations.getUpperBound(2, SIR, false), + "Upper and lower bounds should be same for single edge since cycle and connected are the same"); Assertions.assertEquals(6, Equations.getUpperBound(2, SIR, false), - "Upper bound should be 6."); - Assertions.assertEquals(4, Equations.getLowerBound(2, SIR, false), - "Lower bound should be 4."); + "Upper bound should be 6 equations."); + Assertions.assertEquals(6, Equations.getLowerBound(2, SIR, false), + "Lower bound should be 6 equations."); } @org.junit.jupiter.api.Test void testEdgeBoundsNoClosuresSIRP() { + Assertions.assertEquals(Equations.getLowerBound(2, SIRP, false), + Equations.getUpperBound(2, SIRP, false), + "Upper and lower bounds should be same for single edge since cycle and connected are the same"); Assertions.assertEquals(12, Equations.getUpperBound(2, SIRP, false), - "Upper bound should be 12."); - Assertions.assertEquals(6, Equations.getLowerBound(2, SIRP, false), - "Lower bound should be 6."); + "Upper bound should be 12 equations."); + Assertions.assertEquals(12, Equations.getLowerBound(2, SIRP, false), + "Lower bound should be 12 equations."); } @org.junit.jupiter.api.Test void testTriangleBoundsClosuresSIR() { + Assertions.assertEquals(Equations.getLowerBound(3, SIR, true), + Equations.getUpperBound(3, SIR, true), + "Upper and lower bounds should be same for triangle, " + + "since cycle and connected graphs on 3 vertices are the same"); Assertions.assertEquals(22, Equations.getUpperBound(3, SIR, true), - "Upper bound should be 22."); - Assertions.assertEquals(6, Equations.getLowerBound(3, SIR, true), - "Lower bound should be 6."); + "Upper bound should be 22 equations."); + Assertions.assertEquals(22, Equations.getLowerBound(3, SIR, true), + "Lower bound should be 22 equations."); } @org.junit.jupiter.api.Test void testTriangleBoundsClosuresSIRP() { + Assertions.assertEquals(Equations.getLowerBound(3, SIRP, true), + Equations.getUpperBound(3, SIRP, true), + "Upper and lower bounds should be same for triangle, " + + "since cycle and connected graphs on 3 vertices are the same"); Assertions.assertEquals(55, Equations.getUpperBound(3, SIRP, true), - "Upper bound should be 55."); - Assertions.assertEquals(9, Equations.getLowerBound(3, SIRP, true), - "Lower bound should be 9."); + "Upper bound should be 55 equations."); + Assertions.assertEquals(55, Equations.getLowerBound(3, SIRP, true), + "Lower bound should be 55 equations."); } @org.junit.jupiter.api.Test void testTriangleBoundsNoClosuresSIR() { + Assertions.assertEquals(Equations.getLowerBound(3, SIR, false), + Equations.getUpperBound(3, SIR, false), + "Upper and lower bounds should be same for triangle, " + + "since cycle and connected graphs on 3 vertices are the same"); Assertions.assertEquals(18, Equations.getUpperBound(3, SIR, false), - "Upper bound should be 18"); - Assertions.assertEquals(18, Equations.getUpperBound(3, SIR, false), - "Lower bound should be ."); + "Upper bound should be 18 equations."); + Assertions.assertEquals(18, Equations.getLowerBound(3, SIR, false), + "Lower bound should be 18 equations."); } @org.junit.jupiter.api.Test void testTriangleBoundsNoClosuresSIRP() { + Assertions.assertEquals(Equations.getLowerBound(3, SIRP, false), + Equations.getUpperBound(3, SIRP, false), + "Upper and lower bounds should be same for triangle, " + + "since cycle and connected graphs on 3 vertices are the same"); Assertions.assertEquals(51, Equations.getUpperBound(3, SIRP, false), - "Upper bound should be 51."); - Assertions.assertEquals(9, Equations.getLowerBound(3, SIRP, false), - "Lower bound should be 9."); + "Upper bound should be 51 equations."); + Assertions.assertEquals(51, Equations.getLowerBound(3, SIRP, false), + "Lower bound should be 51 equations."); } } \ No newline at end of file diff --git a/src/test/io/github/ethankelly/GraphTest.java b/src/test/io/github/ethankelly/GraphTest.java new file mode 100644 index 0000000..5944db9 --- /dev/null +++ b/src/test/io/github/ethankelly/GraphTest.java @@ -0,0 +1,19 @@ +package test.io.github.ethankelly; + +import main.io.github.ethankelly.Graph; +import main.io.github.ethankelly.GraphGenerator; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +class GraphTest { + + @Test + void testClone() { + Graph g = GraphGenerator.getLollipop(); + Graph h = g.clone(); + Assertions.assertEquals(g, h); + + g.setName("New name"); +// Assertions.assertNotEquals(g, h); + } +} \ No newline at end of file