Skip to content

Commit a98aa53

Browse files
committed
Tree isomorphism tests
1 parent 2c72e1b commit a98aa53

File tree

2 files changed

+14
-20
lines changed

2 files changed

+14
-20
lines changed

com/williamfiset/algorithms/graphtheory/treealgorithms/TreeIsomorphism.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ public static String encode(TreeNode node) {
143143
return "(" + sb.toString() + ")";
144144
}
145145

146-
/* Graph/Tree creation helper methods. */
146+
/* Graph/Tree creation helper methods. */
147147

148148
// Create a graph as a adjacency list
149149
public static List<List<Integer>> createGraph(int n) {
@@ -157,7 +157,7 @@ public static void addUndirectedEdge(List<List<Integer>> graph, int from, int to
157157
graph.get(to).add(from);
158158
}
159159

160-
/* Example usage */
160+
/* Example usage */
161161

162162
public static void main(String[] args) {
163163
simpleIsomorphismTest();
@@ -199,7 +199,8 @@ private static void testEncodingTreeFromSlides() {
199199

200200
TreeNode root0 = rootTree(tree, 0);
201201

202-
System.out.println("Tree from slides encoding:");
203-
System.out.println(encode(root0));
202+
if (!encode(root0).equals("(((())())(()())(()))")) {
203+
System.out.println("Tree encoding is wrong: " + encode(root0));
204+
}
204205
}
205206
}

javatests/com/williamfiset/algorithms/graphtheory/treealgorithms/TreeIsomorphismWithBfsTest.java

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
package javatests.com.williamfiset.algorithms.graphtheory.treealgorithms;
77

88
import static com.google.common.truth.Truth.assertThat;
9+
import static com.williamfiset.algorithms.graphtheory.treealgorithms.TreeIsomorphism.TreeNode;
910
import static com.williamfiset.algorithms.graphtheory.treealgorithms.TreeIsomorphismWithBfs.addUndirectedEdge;
1011
import static com.williamfiset.algorithms.graphtheory.treealgorithms.TreeIsomorphismWithBfs.createEmptyTree;
1112
import static com.williamfiset.algorithms.graphtheory.treealgorithms.TreeIsomorphismWithBfs.encodeTree;
1213
import static com.williamfiset.algorithms.graphtheory.treealgorithms.TreeIsomorphismWithBfs.treesAreIsomorphic;
13-
import static com.williamfiset.algorithms.graphtheory.treealgorithms.TreeIsomorphism.TreeNode;
1414

1515
import java.util.*;
1616
import org.junit.*;
@@ -147,37 +147,30 @@ public void t() {
147147
node2.addChildren(node6, node7);
148148
node3.addChildren(node8);
149149

150-
System.out.println(com.williamfiset.algorithms.graphtheory.treealgorithms.TreeIsomorphism.encode(node0));
151-
150+
// TODO(william): finish this test to check for "(((())())(()())(()))" encoding
151+
// System.out.println(
152+
// com.williamfiset.algorithms.graphtheory.treealgorithms.TreeIsomorphism.encode(node0));
153+
152154
// (((())())(()())(()))
153-
// ((())())
155+
// ((())())
154156
// (()())
155157
// (())
156-
//
158+
//
157159

158160
// (()())
159161
// (())
160162
// (())
161163

162164
// ((()())(()))
163165
// ((())())
164-
//
166+
//
165167
// ((()())(()))((())())
166168

167-
168169
// (((()())(()))((())()))
169170
// (()())
170171
// (())
171-
//
172+
//
172173
// ((())())
173174
//
174175
}
175176
}
176-
177-
178-
179-
180-
181-
182-
183-

0 commit comments

Comments
 (0)