Example #1
0
  @org.junit.Test
  public void testDigraph2() {

    SAP sap = loadDigraph(digraph2);
    assertEquals(2, sap.length(1, 5));
    assertEquals(0, sap.ancestor(1, 5));
  }
Example #2
0
 // do unit testing of this class
 public static void main(String[] args) {
   In in = new In(args[0]);
   Digraph G = new Digraph(in);
   SAP sap = new SAP(G);
   while (!StdIn.isEmpty()) {
     int v = StdIn.readInt();
     int w = StdIn.readInt();
     int length = sap.length(v, w);
     int ancestor = sap.ancestor(v, w);
     StdOut.printf("length = %d, ancestor = %d\n", length, ancestor);
   }
 }
Example #3
0
 /* do unit testing of this class */
 public static void main(String[] args) {
   System.out.println("Test started file name " + args[0]);
   In in = new In(args[0]);
   Digraph G = new Digraph(in);
   System.out.println("Graph vertices " + G.V() + " graph edges " + G.E());
   System.out.println(G.toString());
   SAP sap = new SAP(G);
   while (!StdIn.isEmpty()) {
     int v = StdIn.readInt();
     int w = StdIn.readInt();
     int length = sap.length(v, w);
     int ancestor = sap.ancestor(v, w);
     StdOut.printf("length = %d, ancestor = %d\n", length, ancestor);
   }
 }
 // distance between nounA and nounB (defined below)
 public int distance(String nounA, String nounB) {
   ifNullThrowException(nounA);
   ifNullThrowException(nounB);
   ifNounNotInThrowException(nounA);
   ifNounNotInThrowException(nounB);
   return sap.length(st.get(nounA), st.get(nounB));
 }
 // a synset (second field of synsets.txt)
 // that is the common ancestor of nounA and nounB
 // in a shortest ancestral path (defined below)
 public String sap(String nounA, String nounB) {
   ifNullThrowException(nounA);
   ifNullThrowException(nounB);
   ifNounNotInThrowException(nounA);
   ifNounNotInThrowException(nounB);
   int No = sap.ancestor(st.get(nounA), st.get(nounB));
   return keys[No];
 }
Example #6
0
  @org.junit.Test
  public void testDigraph1() {

    SAP sap = loadDigraph(digraph1);
    assertEquals(4, sap.length(3, 11));
    assertEquals(1, sap.ancestor(3, 11));

    assertEquals(3, sap.length(9, 12));
    assertEquals(5, sap.ancestor(9, 12));

    assertEquals(4, sap.length(7, 2));
    assertEquals(0, sap.ancestor(7, 2));

    assertEquals(-1, sap.ancestor(1, 6));
    assertEquals(-1, sap.length(1, 6));
  }
Example #7
0
 @org.junit.Test
 public void testDigraph1Trial91() {
   SAP sap = loadDigraph(digraph1);
   assertEquals(3, sap.length(12, 1));
 }
Example #8
0
 @org.junit.Test
 public void testDigraph2Trial7() {
   SAP sap = loadDigraph(digraph2);
   assertEquals(2, sap.length(1, 3));
 }
Example #9
0
 @org.junit.Test(expected = IndexOutOfBoundsException.class)
 public void testLengthBoundaries() {
   SAP sap = loadDigraph(digraph1);
   sap.length(3, 14);
 }
Example #10
0
 @org.junit.Test
 public void testDigraph1SameNode() {
   SAP sap = loadDigraph(digraph1);
   assertEquals(0, sap.length(3, 3));
 }