示例#1
0
 public void testDart() {
   String S = Formatter.testString; // see formatterString.gif
   Graph G = Graph.getInstance(new Formatter(S));
   Vertex V = null;
   int coupleCount = 0;
   for (Enumeration E = G.vertexEnumeration(); E.hasMoreElements(); /*--*/ ) {
     Vertex W = (Vertex) E.nextElement();
     coupleCount += W.size();
     if (W.size() == 3) V = W;
   }
   jassert(V.size() == 3);
   Face F = V.getAny();
   while (F.size() != 5) F = V.next(F, 1);
   jassert(F.size() == 5);
   Dart C = new Dart(V, F);
   Dart[] list = Dart.getDarts(C, G);
   // compute the expected number of return values;
   jassert(list.length == coupleCount);
   jassert(list[0].getV() == C.getV());
   jassert(list[0].getF() == C.getF());
   // check integrity of each couple.
   for (int i = 0; i < list.length; i++) {
     V = list[i].getV();
     F = list[i].getF();
     jassert(V.next(F, 0) == F);
     jassert(F.next(V, 0) == V);
   }
   // check that all couples are distinct.
   Hashtable table = new Hashtable(); // { V-> set of F }
   for (Enumeration E = G.vertexEnumeration(); E.hasMoreElements(); /*--*/ ) {
     V = (Vertex) E.nextElement();
     table.put(V, new HashSet());
   }
   for (int i = 0; i < list.length; i++) {
     V = list[i].getV();
     F = list[i].getF();
     HashSet H = (HashSet) table.get(V);
     jassert(!H.contains(F));
     H.add(F);
   }
 }