package graph; import junit.framework.TestCase; public class NodeTest extends TestCase { public void testLinkSuccess() throws Exception { Node root = new Node(1); Node n2 = new Node(2); assertTrue("The link is successful:\n 1 -> 2",root.link(n2)); Node n3 = new Node(3); assertTrue("The link is successful:\n 1 -> 2 -> 3",n2.link(n3)); } public void testLinkFail() throws Exception { Node root = new Node(1); Node n2 = new Node(2); assertTrue("The link is successful:\n 1 -> 2",root.link(n2)); Node n3 = new Node(3); assertTrue("The link is successful:\n 1 -> 2 -> 3",n2.link(n3)); assertFalse("The creation of cycle should fail:\n 1 -> 2 -> 3 -> 1",n3.link(root)); } public void testLinkBranchesFail() throws Exception { Node root = new Node(1); Node n2 = new Node(2); assertTrue("The link is successful:\n 1 -> 2",root.link(n2)); Node n3 = new Node(3); assertTrue("The link is successful:\n 1 -> 2 -> 3",n2.link(n3)); Node n50 = new Node(50); assertTrue("The link is successful:\n 50 -> 2 -> 3, 1 -> 2 -> 3",n50.link(n2)); assertTrue("The link is successful:\n 50 -> 1 -> 2 -> 3; 50 -> 2 -> 3; 1 -> 2 -> 3",n50.link(root)); assertFalse("The creation of cycle should fail:\n 3 -> 50 -> 1 -> 2 -> 3; 3 -> 50 -> 2 -> 3; 1 -> 2 -> 3",n3.link(n50)); } }