/*
- * Copyright 2008 the original author or authors.
- *
+ * Copyright 2005-2010 the original author or authors.
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- */
+ */
package org.wamblee.system.graph;
import junit.framework.TestCase;
import java.util.Arrays;
import java.util.List;
-
/**
- * DOCUMENT ME!
- *
+ *
* @author $author$
* @version $Revision$
- */
+ */
public class GraphTest extends TestCase {
- /**
- * DOCUMENT ME!
- */
public void testNodeMgt() {
final Graph graph = new Graph();
assertTrue(graph.getNodes().isEmpty());
assertTrue(graph.removeNode(x));
assertTrue(graph.getNodes().isEmpty());
- // Empty node set.
+ // Empty node set.
assertFalse(graph.removeNode(x));
Node y = new DefaultNode("y");
// duplicate node
AssertionUtils.assertException(new AssertionUtils.ErroneousCode() {
- @Override
- public void run() throws Exception {
- graph.addNode(new DefaultNode("x"));
- }
- }, IllegalArgumentException.class);
+ @Override
+ public void run() throws Exception {
+ graph.addNode(new DefaultNode("x"));
+ }
+ }, IllegalArgumentException.class);
}
- /**
- * DOCUMENT ME!
- */
public void testEdgeMgt() {
final Graph graph = new Graph();
- final Node x = new DefaultNode("x");
- final Node y = new DefaultNode("y");
+ final Node x = new DefaultNode("x");
+ final Node y = new DefaultNode("y");
graph.addNode(x);
graph.addNode(y);
// duplicate edge.
AssertionUtils.assertException(new AssertionUtils.ErroneousCode() {
- @Override
- public void run() throws Exception {
- graph.addEdge(e);
- }
- }, IllegalArgumentException.class);
+ @Override
+ public void run() throws Exception {
+ graph.addEdge(e);
+ }
+ }, IllegalArgumentException.class);
// Remove node when edge is still present
AssertionUtils.assertException(new AssertionUtils.ErroneousCode() {
- @Override
- public void run() throws Exception {
- graph.removeNode(x);
- }
- }, IllegalArgumentException.class);
+ @Override
+ public void run() throws Exception {
+ graph.removeNode(x);
+ }
+ }, IllegalArgumentException.class);
Node a = new DefaultNode("a");
graph.addNode(a);
- graph.addEdges(Arrays.asList(
- new Edge[] { new DefaultEdge(x, a), new DefaultEdge(y, a) }));
+ graph.addEdges(Arrays.asList(new Edge[] { new DefaultEdge(x, a),
+ new DefaultEdge(y, a) }));
assertEquals(3, graph.getEdges().size());
}
- /**
- * DOCUMENT ME!
- */
public void testExtend() {
Graph graph = new Graph();
graph.addNode(new MyNode("x", new String[] { "a", "b" }));
assertEquals(12, edges.size()); // 2 outgoing and 2 incoming nodes.
}
- /**
- * DOCUMENT ME!
- */
public void testApplyFilter() {
Graph graph = new Graph();
graph.addNode(new DefaultNode("x"));
graph.addNode(new DefaultNode("y"));
graph.addNode(new DefaultNode("z"));
- graph.addEdge(new DefaultEdge(graph.findNode("x"), graph.findNode("y")));
- graph.addEdge(new DefaultEdge(graph.findNode("y"), graph.findNode("z")));
- graph.addEdge(new DefaultEdge(graph.findNode("z"), graph.findNode("x")));
+ graph
+ .addEdge(new DefaultEdge(graph.findNode("x"), graph.findNode("y")));
+ graph
+ .addEdge(new DefaultEdge(graph.findNode("y"), graph.findNode("z")));
+ graph
+ .addEdge(new DefaultEdge(graph.findNode("z"), graph.findNode("x")));
assertEquals(3, graph.getEdges().size());
graph.applyFilter(new EdgeFilter() {
- @Override
- public boolean isViolated(Edge aEdge) {
- if (aEdge.getFrom().getName().equals("x")) {
- return false;
- }
-
- return true;
+ @Override
+ public boolean isViolated(Edge aEdge) {
+ if (aEdge.getFrom().getName().equals("x")) {
+ return false;
}
- });
+
+ return true;
+ }
+ });
assertEquals(1, graph.getEdges().size());
assertEquals("x", graph.getEdges().get(0).getFrom().getName());
}
- /**
- * DOCUMENT ME!
- */
public void testFindIncomingOutgoing() {
Graph graph = new Graph();
- Node x = new DefaultNode("x");
- Node y = new DefaultNode("y");
+ Node x = new DefaultNode("x");
+ Node y = new DefaultNode("y");
graph.addNode(x);
graph.addNode(y);
assertTrue(outgoing.isEmpty());
}
- /**
- * DOCUMENT ME!
- */
public void testAccept() {
Graph graph = new Graph();
- Node x = new DefaultNode("x");
- Node y = new DefaultNode("y");
- Edge e = new DefaultEdge(x, y);
+ Node x = new DefaultNode("x");
+ Node y = new DefaultNode("y");
+ Edge e = new DefaultEdge(x, y);
graph.addNode(x);
graph.addNode(y);
graph.addEdge(e);