/**
   * Instantiate and populate a node object from the next item in the result set of a node query.
   *
   * @param query string
   * @return Node
   */
  protected Node nodeFromQueryRS(String query) throws DatabaseException {
    Node node = null;

    if (dbr.psRSNext(query)) {
      // String columns = org.apache.commons.lang.StringUtils.join(dbr.psRSColumnNames(query), ",
      // ");
      // System.out.println("columns: [" + columns + "]");

      node = new Node();

      Long id = dbr.psRSGetBigInt(query, "ID");
      String name = dbr.psRSGetVarChar(query, "NAME");
      String type = dbr.psRSGetVarChar(query, "TYPE");
      Double longitude = dbr.psRSGetDouble(query, "X");
      Double latitude = dbr.psRSGetDouble(query, "Y");

      node.setId(id);
      node.setName(name);
      node.setType(type);
      node.setLongitude(longitude);
      node.setLatitude(latitude);
    }

    return node;
  }
示例#2
0
  @Before
  public void setup() {
    nw = new Network();
    nw.setName("test network");

    dp = new DensityMap();

    nw.setNodes(new ArrayList<edu.berkeley.path.model_elements_base.Node>());
    nw.setLinks(new ArrayList<edu.berkeley.path.model_elements_base.Link>());

    Node nd1;
    Node nd2;
    Link ln;

    nd1 = new Node();
    nd1.setId(1L);
    nd1.setName("one");
    nd1.setType("Highway");
    nw.getNodes().add(nd1);

    nd2 = new Node();
    nd2.setId(2L);
    nd2.setName("two");
    nd2.setType("Highway");
    nw.getNodes().add(nd2);

    ln = new Link();
    ln.setId(3L);
    ln.setName("three");
    ln.setType("Highway");
    ln.setLaneCount(4.0);
    ln.setLength(1000.0);

    ln.setBegin(nd1);
    ln.setEnd(nd2);

    nw.getLinks().add(ln);
  }
示例#3
0
 @Test
 public void constructorTestNode() {
   Node n = new Node(Type.ROOM);
   n.setDir(DoorDirection.NORTH);
   ZoneModel zm = new ZoneModel(n);
   assertEquals(zm.getType(), Type.ROOM);
   assertTrue(zm.hasDoor(0));
   n.setDir(DoorDirection.EAST);
   zm = new ZoneModel(n);
   assertTrue(zm.hasDoor(1));
   n.setDir(DoorDirection.SOUTH);
   zm = new ZoneModel(n);
   assertTrue(zm.hasDoor(2));
   n.setDir(DoorDirection.WEST);
   zm = new ZoneModel(n);
   assertTrue(zm.hasDoor(3));
   n.setType(Type.CORRIDOR);
   zm = new ZoneModel(n);
   assertFalse(zm.hasDoor(0));
   assertFalse(zm.hasDoor(1));
   assertFalse(zm.hasDoor(2));
   assertFalse(zm.hasDoor(3));
 }
示例#4
0
  /**
   * *************************************************** Helper methods
   * ***************************************************
   */
  private Node createNode() throws InterruptedException {
    Comboitem item = typeBox.getSelectedItem();
    if (item == null) {
      Messagebox.show("Node type is required.");
      return null;
    }

    String nodeType = GeneralUtil.getNodeDescriptionByLabel(ntds, item.getLabel()).get("type");
    String firstName = firstNameBox.getValue().trim();
    String lastName = lastNameBox.getValue().trim();
    String midName = midNameBox.getValue().trim();
    String label = labelBox.getValue().trim();
    String username;
    if (nodeType.equals(Constants.NODE_TYPE_USER)) {
      if (firstName.isEmpty()) {
        Messagebox.show("First Name is required.");
        return null;
      } else if (firstName.length() > 80) {
        Messagebox.show("First Name cannot be longer than 80.");
        return null;
      } else if (GeneralUtil.containSpecialCharacter(firstName)) {
        Messagebox.show("First Name cannot contain special characters.");
        return null;
      }

      if (lastName.isEmpty()) {
        Messagebox.show("Last Name is required.");
        return null;
      } else if (lastName.length() > 80) {
        Messagebox.show("Last Name cannot be longer than 80.");
        return null;
      } else if (GeneralUtil.containSpecialCharacter(lastName)) {
        Messagebox.show("Last Name cannot contain special characters.");
        return null;
      }

      username = firstName.replace(" ", "_") + "__" + lastName.replace(" ", "_");
    } else {
      if (label.isEmpty()) {
        Messagebox.show("Label is required.");
        return null;
      } else if (label.length() > 255) {
        Messagebox.show("Label cannot be longer than 255.");
        return null;
      }
      username = GeneralUtil.replaceSpecialCharacter(label, "_").replace(" ", "_");
    }

    if (nodeDao.findByUsername(username) != null) {
      Messagebox.show("Username: "******" has already been used.");
      return null;
    }

    Survey survey = surveyDao.findById(1L);
    Node node = new Node();
    node.setType(nodeType);
    node.setUsername(username);
    node.setLabel(label);
    if (nodeType.equals(Constants.NODE_TYPE_USER)) {
      node.setFirstName(firstName);
      node.setLastName(lastName);
      node.setMidName(midName);
    }

    String defaultPassword = survey.getAttribute(Constants.SURVEY_DEFAULT_PASSWORD);
    if (defaultPassword == null) {
      defaultPassword = "******";
    }
    if (defaultPassword.equals("rAnDoM")) {
      RandomString rs = new RandomString(8);
      defaultPassword = rs.nextString();
    }
    node.setPassword(defaultPassword);

    node.setAttribute(
        Constants.NODE_LOGIN_MODE, survey.getAttribute(Constants.SURVEY_DEFAULT_LOGIN_MODE));

    // role
    node.getRoles().add(roleDao.findByName(Constants.ROLE_USER));

    // groups
    Set<Group> groups = new HashSet<Group>();
    AbstractQuestionRelation p = (AbstractQuestionRelation) getParent();
    groups.addAll(p.getQuestion().getAvailableGroups());
    groups.add(groupDao.findByName(Constants.GROUP_ALL));

    if (nodeType.equals(Constants.NODE_TYPE_USER)) {
      groups.add(groupDao.findByName(Constants.GROUP_USER));
    } else {
      String groupName = Constants.GROUP_NODE_TYPE_PREFIX + nodeType;
      Group group = groupDao.findByName(groupName);
      if (group == null) {
        group = new Group();
        group.setName(groupName);
        groupDao.save(group);
        logger.info("created new group: " + group.getName());
      }
      groups.add(group);
    }

    node.setGroups(groups);

    // save
    nodeDao.save(node);
    logger.debug("Node created: " + username);

    return node;
  }
示例#5
0
 /**
  * set the type of PhysicalNode. It must override the method that make sure the PhysicalNode has
  * right type.
  *
  * @see XMMConstants for more detailed info.
  * @param type the type of PhysicalNode.
  */
 public void setType(String type) {
   // To prohibit be set to other value. But can't prevent set value from
   // super class.
   super.setType(XMMConstants.PHYSICAL_NODE_TYPE);
 }
示例#6
0
 private void init() {
   super.setType(XMMConstants.PHYSICAL_NODE_TYPE);
 }
  /**
   * Read Node config from file config.nodeConfigFileName, including available nodes and their
   * possible connections
   */
  public NodeFactory(Config config, ProblemData problemData) {
    this.config = config;
    this.problemData = problemData;
    try {
      FileInputStream in = new FileInputStream(config.nodeConfigFileName);
      Properties props = new Properties();
      props.load(in);
      in.close();

      String separator = "\\s*,\\s*";

      String tmp = props.getProperty("sets");
      String[] sets = tmp.split(separator);

      nodeSets = new NodeSet[sets.length];

      int i, j, k;
      for (i = 0; i < sets.length; i++) {
        nodeSets[i] = new NodeSet(sets[i]);
        String[] nodes;
        tmp = props.getProperty(sets[i] + "Functions");
        if (tmp == null)
          Logger.log(
              "Warning: when reading "
                  + config.nodeConfigFileName
                  + ", no functions found for set "
                  + sets[i]);
        else {
          nodes = tmp.split(separator);
          for (j = 0; j < nodes.length; j++) {
            Class cl = Class.forName("gpalta.nodes." + nodes[j]);
            java.lang.reflect.Constructor co = cl.getConstructor();
            nodeSets[i].addFunction((Node) co.newInstance());
          }
        }
        tmp = props.getProperty(sets[i] + "Terminals");
        if (tmp == null)
          Logger.log(
              "Warning: when reading "
                  + config.nodeConfigFileName
                  + ", no terminals found for set "
                  + sets[i]);
        else {
          nodes = tmp.split(separator);
          for (j = 0; j < nodes.length; j++) {
            Class cl = Class.forName("gpalta.nodes." + nodes[j]);
            if (nodes[j].contains("Var")) {
              for (k = 0; k < problemData.nVars; k++) {
                java.lang.reflect.Constructor[] co = cl.getConstructors();
                nodeSets[i].addTerminal((Node) co[0].newInstance(k + 1));
              }
            } else if (nodes[j].contains("Angle")) {
              for (k = 0; k < problemData.nVars - 1; k++) {
                java.lang.reflect.Constructor[] co = cl.getConstructors();
                nodeSets[i].addTerminal((Node) co[0].newInstance(k + 1));
              }
            } else {
              java.lang.reflect.Constructor co = cl.getConstructor();
              nodeSets[i].addTerminal((Node) co.newInstance());
            }
          }
        }
      }

      for (i = 0; i < nodeSets.length; i++) {
        for (Node n : nodeSets[i].getAll()) {
          n.setType(nodeSets[i]);
        }
      }

      for (i = 0; i < nodeSets.length; i++) {
        for (Node n : nodeSets[i].getAll()) {
          tmp = props.getProperty("kids" + n.getClass().getSimpleName());
          if (tmp != null) {
            String[] kids = tmp.split(separator);
            if (kids.length != n.nKids()) {
              Logger.log(
                  "Error reading "
                      + config.nodeConfigFileName
                      + ": must specify "
                      + n.nKids()
                      + " kids for "
                      + n.getClass().getSimpleName());
            }
            for (j = 0; j < n.nKids(); j++) {
              for (k = 0; k < nodeSets.length; k++) {
                if (nodeSets[k].getName().equals(kids[j])) {
                  n.setTypeOfKids(j, nodeSets[k]);
                  break;
                }
              }
              if (k == nodeSets.length)
                Logger.log(
                    "Error reading "
                        + config.nodeConfigFileName
                        + ": Setting kids for "
                        + n.getClass().getSimpleName()
                        + ", "
                        + kids[j]
                        + " doesn't match any set name");
            }
          } else for (j = 0; j < n.nKids(); j++) n.setTypeOfKids(j, nodeSets[i]);
        }
      }
      tmp = props.getProperty("treeRoot");
      if (tmp == null) {
        Logger.log(
            "Error reading " + config.nodeConfigFileName + ": property \"treeRoot\" not present");
      }
      for (i = 0; i < nodeSets.length; i++) {
        if (nodeSets[i].getName().equals(tmp)) {
          treeRoot = nodeSets[i];
          break;
        }
      }
      if (i == nodeSets.length)
        Logger.log(
            "Error reading "
                + config.nodeConfigFileName
                + ": Setting treeRoot, "
                + tmp
                + " doesn't match any set name");
    } catch (IOException e) {
      Logger.log("Error reading " + config.nodeConfigFileName + ":");
      Logger.log(e);
    } catch (ClassNotFoundException e) {
      Logger.log("Error reading " + config.nodeConfigFileName + ":");
      Logger.log(e);
    } catch (NoSuchMethodException e) {
      Logger.log("Error reading " + config.nodeConfigFileName + ":");
      Logger.log(e);
    } catch (InstantiationException e) {
      Logger.log("Error reading " + config.nodeConfigFileName + ":");
      Logger.log(e);
    } catch (IllegalAccessException e) {
      Logger.log("Error reading " + config.nodeConfigFileName + ":");
      Logger.log(e);
    } catch (InvocationTargetException e) {
      Logger.log("Error reading " + config.nodeConfigFileName + ":");
      Logger.log(e);
    }
  }
示例#8
0
 /*  47:    */
 /*  48:    */ private void transformCompilationUnit_r(
     ScriptNode tree, Node parent, Scope scope, boolean createScopeObjects, boolean inStrictMode)
       /*  49:    */ {
   /*  50:104 */ Node node = null;
   /*  51:    */ for (; ; )
   /*  52:    */ {
     /*  53:107 */ Node previous = null;
     /*  54:108 */ if (node == null)
     /*  55:    */ {
       /*  56:109 */ node = parent.getFirstChild();
       /*  57:    */ }
     /*  58:    */ else
     /*  59:    */ {
       /*  60:111 */ previous = node;
       /*  61:112 */ node = node.getNext();
       /*  62:    */ }
     /*  63:114 */ if (node == null) {
       /*  64:    */ break;
       /*  65:    */ }
     /*  66:118 */ int type = node.getType();
     /*  67:119 */ if ((createScopeObjects)
         && ((type == 129) || (type == 132) || (type == 157))
         && ((node instanceof Scope)))
     /*  68:    */ {
       /*  69:124 */ Scope newScope = (Scope) node;
       /*  70:125 */ if (newScope.getSymbolTable() != null)
       /*  71:    */ {
         /*  72:128 */ Node let = new Node(type == 157 ? 158 : 153);
         /*  73:    */
         /*  74:130 */ Node innerLet = new Node(153);
         /*  75:131 */ let.addChildToBack(innerLet);
         /*  76:132 */ for (String name : newScope.getSymbolTable().keySet()) {
           /*  77:133 */ innerLet.addChildToBack(Node.newString(39, name));
           /*  78:    */ }
         /*  79:135 */ newScope.setSymbolTable(null);
         /*  80:136 */ Node oldNode = node;
         /*  81:137 */ node = replaceCurrent(parent, previous, node, let);
         /*  82:138 */ type = node.getType();
         /*  83:139 */ let.addChildToBack(oldNode);
         /*  84:    */ }
       /*  85:    */ }
     /*  86:143 */ switch (type)
     /*  87:    */ {
         /*  88:    */ case 114:
         /*  89:    */ case 130:
         /*  90:    */ case 132:
         /*  91:148 */ this.loops.push(node);
         /*  92:149 */ this.loopEnds.push(((Jump) node).target);
         /*  93:150 */ break;
         /*  94:    */ case 123:
         /*  95:154 */ this.loops.push(node);
         /*  96:155 */ Node leave = node.getNext();
         /*  97:156 */ if (leave.getType() != 3) {
           /*  98:157 */ Kit.codeBug();
           /*  99:    */ }
         /* 100:159 */ this.loopEnds.push(leave);
         /* 101:160 */ break;
         /* 102:    */ case 81:
         /* 103:165 */ Jump jump = (Jump) node;
         /* 104:166 */ Node finallytarget = jump.getFinally();
         /* 105:167 */ if (finallytarget != null)
         /* 106:    */ {
           /* 107:168 */ this.hasFinally = true;
           /* 108:169 */ this.loops.push(node);
           /* 109:170 */ this.loopEnds.push(finallytarget);
           /* 110:    */ }
         /* 111:    */ break;
         /* 112:    */ case 3:
         /* 113:    */ case 131:
         /* 114:177 */ if ((!this.loopEnds.isEmpty()) && (this.loopEnds.peek() == node))
         /* 115:    */ {
           /* 116:178 */ this.loopEnds.pop();
           /* 117:179 */ this.loops.pop();
           /* 118:    */ }
         /* 119:    */ break;
         /* 120:    */ case 72:
         /* 121:184 */ ((FunctionNode) tree).addResumptionPoint(node);
         /* 122:185 */ break;
         /* 123:    */ case 4:
         /* 124:189 */ boolean isGenerator =
             (tree.getType() == 109) && (((FunctionNode) tree).isGenerator());
         /* 125:191 */ if (isGenerator) {
           /* 126:192 */ node.putIntProp(20, 1);
           /* 127:    */ }
         /* 128:201 */ if (this.hasFinally)
         /* 129:    */ {
           /* 130:203 */ Node unwindBlock = null;
           /* 131:204 */ for (int i = this.loops.size() - 1; i >= 0; i--)
           /* 132:    */ {
             /* 133:205 */ Node n = (Node) this.loops.get(i);
             /* 134:206 */ int elemtype = n.getType();
             /* 135:207 */ if ((elemtype == 81) || (elemtype == 123))
             /* 136:    */ {
               /* 137:    */ Node unwind;
               /* 138:    */ Node unwind;
               /* 139:209 */ if (elemtype == 81)
               /* 140:    */ {
                 /* 141:210 */ Jump jsrnode = new Jump(135);
                 /* 142:211 */ Node jsrtarget = ((Jump) n).getFinally();
                 /* 143:212 */ jsrnode.target = jsrtarget;
                 /* 144:213 */ unwind = jsrnode;
                 /* 145:    */ }
               /* 146:    */ else
               /* 147:    */ {
                 /* 148:215 */ unwind = new Node(3);
                 /* 149:    */ }
               /* 150:217 */ if (unwindBlock == null) {
                 /* 151:218 */ unwindBlock = new Node(129, node.getLineno());
                 /* 152:    */ }
               /* 153:221 */ unwindBlock.addChildToBack(unwind);
               /* 154:    */ }
             /* 155:    */ }
           /* 156:224 */ if (unwindBlock != null)
           /* 157:    */ {
             /* 158:225 */ Node returnNode = node;
             /* 159:226 */ Node returnExpr = returnNode.getFirstChild();
             /* 160:227 */ node = replaceCurrent(parent, previous, node, unwindBlock);
             /* 161:228 */ if ((returnExpr == null) || (isGenerator))
             /* 162:    */ {
               /* 163:229 */ unwindBlock.addChildToBack(returnNode);
               continue;
               /* 164:    */ }
             /* 165:231 */ Node store = new Node(134, returnExpr);
             /* 166:232 */ unwindBlock.addChildToFront(store);
             /* 167:233 */ returnNode = new Node(64);
             /* 168:234 */ unwindBlock.addChildToBack(returnNode);
             /* 169:    */
             /* 170:236 */ transformCompilationUnit_r(
                 tree, store, scope, createScopeObjects, inStrictMode);
             /* 171:    */ }
           /* 172:    */ }
         /* 173:241 */ break;
         /* 174:    */ case 120:
         /* 175:    */ case 121:
         /* 176:249 */ Jump jump = (Jump) node;
         /* 177:250 */ Jump jumpStatement = jump.getJumpStatement();
         /* 178:251 */ if (jumpStatement == null) {
           /* 179:251 */ Kit.codeBug();
           /* 180:    */ }
         /* 181:253 */ int i = this.loops.size();
         /* 182:    */ for (; ; )
         /* 183:    */ {
           /* 184:254 */ if (i == 0) {
             /* 185:258 */ throw Kit.codeBug();
             /* 186:    */ }
           /* 187:260 */ i--;
           /* 188:261 */ Node n = (Node) this.loops.get(i);
           /* 189:262 */ if (n == jumpStatement) {
             /* 190:    */ break;
             /* 191:    */ }
           /* 192:266 */ int elemtype = n.getType();
           /* 193:267 */ if (elemtype == 123)
           /* 194:    */ {
             /* 195:268 */ Node leave = new Node(3);
             /* 196:269 */ previous = addBeforeCurrent(parent, previous, node, leave);
             /* 197:    */ }
           /* 198:271 */ else if (elemtype == 81)
           /* 199:    */ {
             /* 200:272 */ Jump tryNode = (Jump) n;
             /* 201:273 */ Jump jsrFinally = new Jump(135);
             /* 202:274 */ jsrFinally.target = tryNode.getFinally();
             /* 203:275 */ previous = addBeforeCurrent(parent, previous, node, jsrFinally);
             /* 204:    */ }
           /* 205:    */ }
         /* 206:280 */ if (type == 120) {
           /* 207:281 */ jump.target = jumpStatement.target;
           /* 208:    */ } else {
           /* 209:283 */ jump.target = jumpStatement.getContinue();
           /* 210:    */ }
         /* 211:285 */ jump.setType(5);
         /* 212:    */
         /* 213:287 */ break;
         /* 214:    */ case 38:
         /* 215:291 */ visitCall(node, tree);
         /* 216:292 */ break;
         /* 217:    */ case 30:
         /* 218:295 */ visitNew(node, tree);
         /* 219:296 */ break;
         /* 220:    */ case 153:
         /* 221:    */ case 158:
         /* 222:300 */ Node child = node.getFirstChild();
         /* 223:301 */ if (child.getType() == 153)
         /* 224:    */ {
           /* 225:304 */ boolean createWith =
               (tree.getType() != 109) || (((FunctionNode) tree).requiresActivation());
           /* 226:    */
           /* 227:306 */ node = visitLet(createWith, parent, previous, node);
           /* 228:    */ }
         /* 229:307 */ break;
         /* 230:    */ case 122:
         /* 231:    */ case 154:
         /* 232:316 */ Node result = new Node(129);
         /* 233:317 */ for (Node cursor = node.getFirstChild(); cursor != null; )
         /* 234:    */ {
           /* 235:320 */ Node n = cursor;
           /* 236:321 */ cursor = cursor.getNext();
           /* 237:322 */ if (n.getType() == 39)
           /* 238:    */ {
             /* 239:323 */ if (!n.hasChildren()) {
               /* 240:    */ continue;
               /* 241:    */ }
             /* 242:325 */ Node init = n.getFirstChild();
             /* 243:326 */ n.removeChild(init);
             /* 244:327 */ n.setType(49);
             /* 245:328 */ n = new Node(type == 154 ? 155 : 8, n, init);
             /* 246:    */ }
           /* 247:335 */ else if (n.getType() != 158)
           /* 248:    */ {
             /* 249:336 */ throw Kit.codeBug();
             /* 250:    */ }
           /* 251:338 */ Node pop = new Node(133, n, node.getLineno());
           /* 252:339 */ result.addChildToBack(pop);
           /* 253:    */ }
         /* 254:341 */ node = replaceCurrent(parent, previous, node, result);
         /* 255:342 */ break;
         /* 256:    */ case 137:
         /* 257:346 */ Scope defining = scope.getDefiningScope(node.getString());
         /* 258:347 */ if (defining != null) {
           /* 259:348 */ node.setScope(defining);
           /* 260:    */ }
         /* 261:351 */ break;
         /* 262:    */ case 7:
         /* 263:    */ case 32:
         /* 264:359 */ Node child = node.getFirstChild();
         /* 265:360 */ if (type == 7)
         /* 266:    */ {
           /* 267:361 */ while (child.getType() == 26) {
             /* 268:362 */ child = child.getFirstChild();
             /* 269:    */ }
           /* 270:364 */ if ((child.getType() == 12) || (child.getType() == 13))
           /* 271:    */ {
             /* 272:367 */ Node first = child.getFirstChild();
             /* 273:368 */ Node last = child.getLastChild();
             /* 274:369 */ if ((first.getType() == 39)
                 && (first.getString().equals("undefined"))) {
               /* 275:371 */ child = last;
               /* 276:372 */ } else if ((last.getType() == 39)
                 && (last.getString().equals("undefined"))) {
               /* 277:374 */ child = first;
               /* 278:    */ }
             /* 279:    */ }
           /* 280:    */ }
         /* 281:377 */ if (child.getType() == 33) {
           /* 282:378 */ child.setType(34);
           /* 283:    */ }
         /* 284:    */ break;
         /* 285:    */ case 8:
         /* 286:383 */ if (inStrictMode) {
           /* 287:384 */ node.setType(73);
           /* 288:    */ }
         /* 289:    */ case 31:
         /* 290:    */ case 39:
         /* 291:    */ case 155:
         /* 292:392 */ if (!createScopeObjects)
         /* 293:    */ {
           /* 294:    */ Node nameSource;
           /* 295:    */ Node nameSource;
           /* 296:396 */ if (type == 39)
           /* 297:    */ {
             /* 298:397 */ nameSource = node;
             /* 299:    */ }
           /* 300:    */ else
           /* 301:    */ {
             /* 302:399 */ nameSource = node.getFirstChild();
             /* 303:400 */ if (nameSource.getType() != 49)
             /* 304:    */ {
               /* 305:401 */ if (type == 31) {
                 /* 306:    */ break label1734;
                 /* 307:    */ }
               /* 308:404 */ throw Kit.codeBug();
               /* 309:    */ }
             /* 310:    */ }
           /* 311:407 */ if (nameSource.getScope() == null)
           /* 312:    */ {
             /* 313:410 */ String name = nameSource.getString();
             /* 314:411 */ Scope defining = scope.getDefiningScope(name);
             /* 315:412 */ if (defining != null)
             /* 316:    */ {
               /* 317:413 */ nameSource.setScope(defining);
               /* 318:414 */ if (type == 39)
               /* 319:    */ {
                 /* 320:415 */ node.setType(55);
                 /* 321:    */ }
               /* 322:416 */ else if ((type == 8) || (type == 73))
               /* 323:    */ {
                 /* 324:418 */ node.setType(56);
                 /* 325:419 */ nameSource.setType(41);
                 /* 326:    */ }
               /* 327:420 */ else if (type == 155)
               /* 328:    */ {
                 /* 329:421 */ node.setType(156);
                 /* 330:422 */ nameSource.setType(41);
                 /* 331:    */ }
               /* 332:423 */ else if (type == 31)
               /* 333:    */ {
                 /* 334:425 */ Node n = new Node(44);
                 /* 335:426 */ node = replaceCurrent(parent, previous, node, n);
                 /* 336:    */ }
               /* 337:    */ else
               /* 338:    */ {
                 /* 339:428 */ throw Kit.codeBug();
                 /* 340:    */ }
               /* 341:    */ }
             /* 342:    */ }
           /* 343:    */ }
         /* 344:    */ default:
         /* 345:    */ label1734:
         /* 346:435 */ transformCompilationUnit_r(
             tree,
             node,
             (node instanceof Scope) ? (Scope) node : scope,
             createScopeObjects,
             inStrictMode);
         /* 347:    */ }
     /* 348:    */ }
   /* 349:    */ }
示例#9
0
 /* 354:    */
 /* 355:    */ protected Node visitLet(
     boolean createWith, Node parent, Node previous, Node scopeNode)
       /* 356:    */ {
   /* 357:450 */ Node vars = scopeNode.getFirstChild();
   /* 358:451 */ Node body = vars.getNext();
   /* 359:452 */ scopeNode.removeChild(vars);
   /* 360:453 */ scopeNode.removeChild(body);
   /* 361:454 */ boolean isExpression = scopeNode.getType() == 158;
   /* 362:    */ Node result;
   /* 363:457 */ if (createWith)
   /* 364:    */ {
     /* 365:458 */ Node result = new Node(isExpression ? 159 : 129);
     /* 366:459 */ result = replaceCurrent(parent, previous, scopeNode, result);
     /* 367:460 */ ArrayList<Object> list = new ArrayList();
     /* 368:461 */ Node objectLiteral = new Node(66);
     /* 369:462 */ for (Node v = vars.getFirstChild(); v != null; v = v.getNext())
     /* 370:    */ {
       /* 371:463 */ Node current = v;
       /* 372:464 */ if (current.getType() == 158)
       /* 373:    */ {
         /* 374:466 */ List<?> destructuringNames = (List) current.getProp(22);
         /* 375:    */
         /* 376:468 */ Node c = current.getFirstChild();
         /* 377:469 */ if (c.getType() != 153) {
           /* 378:469 */ throw Kit.codeBug();
           /* 379:    */ }
         /* 380:471 */ if (isExpression) {
           /* 381:472 */ body = new Node(89, c.getNext(), body);
           /* 382:    */ } else {
           /* 383:474 */ body = new Node(129, new Node(133, c.getNext()), body);
           /* 384:    */ }
         /* 385:480 */ if (destructuringNames != null)
         /* 386:    */ {
           /* 387:481 */ list.addAll(destructuringNames);
           /* 388:482 */ for (int i = 0; i < destructuringNames.size(); i++) {
             /* 389:483 */ objectLiteral.addChildToBack(new Node(126, Node.newNumber(0.0D)));
             /* 390:    */ }
           /* 391:    */ }
         /* 392:487 */ current = c.getFirstChild();
         /* 393:    */ }
       /* 394:489 */ if (current.getType() != 39) {
         /* 395:489 */ throw Kit.codeBug();
         /* 396:    */ }
       /* 397:490 */ list.add(ScriptRuntime.getIndexObject(current.getString()));
       /* 398:491 */ Node init = current.getFirstChild();
       /* 399:492 */ if (init == null) {
         /* 400:493 */ init = new Node(126, Node.newNumber(0.0D));
         /* 401:    */ }
       /* 402:495 */ objectLiteral.addChildToBack(init);
       /* 403:    */ }
     /* 404:497 */ objectLiteral.putProp(12, list.toArray());
     /* 405:498 */ Node newVars = new Node(2, objectLiteral);
     /* 406:499 */ result.addChildToBack(newVars);
     /* 407:500 */ result.addChildToBack(new Node(123, body));
     /* 408:501 */ result.addChildToBack(new Node(3));
     /* 409:    */ }
   /* 410:    */ else
   /* 411:    */ {
     /* 412:503 */ result = new Node(isExpression ? 89 : 129);
     /* 413:504 */ result = replaceCurrent(parent, previous, scopeNode, result);
     /* 414:505 */ Node newVars = new Node(89);
     /* 415:506 */ for (Node v = vars.getFirstChild(); v != null; v = v.getNext())
     /* 416:    */ {
       /* 417:507 */ Node current = v;
       /* 418:508 */ if (current.getType() == 158)
       /* 419:    */ {
         /* 420:510 */ Node c = current.getFirstChild();
         /* 421:511 */ if (c.getType() != 153) {
           /* 422:511 */ throw Kit.codeBug();
           /* 423:    */ }
         /* 424:513 */ if (isExpression) {
           /* 425:514 */ body = new Node(89, c.getNext(), body);
           /* 426:    */ } else {
           /* 427:516 */ body = new Node(129, new Node(133, c.getNext()), body);
           /* 428:    */ }
         /* 429:521 */ Scope.joinScopes((Scope) current, (Scope) scopeNode);
         /* 430:    */
         /* 431:523 */ current = c.getFirstChild();
         /* 432:    */ }
       /* 433:525 */ if (current.getType() != 39) {
         /* 434:525 */ throw Kit.codeBug();
         /* 435:    */ }
       /* 436:526 */ Node stringNode = Node.newString(current.getString());
       /* 437:527 */ stringNode.setScope((Scope) scopeNode);
       /* 438:528 */ Node init = current.getFirstChild();
       /* 439:529 */ if (init == null) {
         /* 440:530 */ init = new Node(126, Node.newNumber(0.0D));
         /* 441:    */ }
       /* 442:532 */ newVars.addChildToBack(new Node(56, stringNode, init));
       /* 443:    */ }
     /* 444:534 */ if (isExpression)
     /* 445:    */ {
       /* 446:535 */ result.addChildToBack(newVars);
       /* 447:536 */ scopeNode.setType(89);
       /* 448:537 */ result.addChildToBack(scopeNode);
       /* 449:538 */ scopeNode.addChildToBack(body);
       /* 450:539 */ if ((body instanceof Scope))
       /* 451:    */ {
         /* 452:540 */ Scope scopeParent = ((Scope) body).getParentScope();
         /* 453:541 */ ((Scope) body).setParentScope((Scope) scopeNode);
         /* 454:542 */ ((Scope) scopeNode).setParentScope(scopeParent);
         /* 455:    */ }
       /* 456:    */ }
     /* 457:    */ else
     /* 458:    */ {
       /* 459:545 */ result.addChildToBack(new Node(133, newVars));
       /* 460:546 */ scopeNode.setType(129);
       /* 461:547 */ result.addChildToBack(scopeNode);
       /* 462:548 */ scopeNode.addChildrenToBack(body);
       /* 463:549 */ if ((body instanceof Scope))
       /* 464:    */ {
         /* 465:550 */ Scope scopeParent = ((Scope) body).getParentScope();
         /* 466:551 */ ((Scope) body).setParentScope((Scope) scopeNode);
         /* 467:552 */ ((Scope) scopeNode).setParentScope(scopeParent);
         /* 468:    */ }
       /* 469:    */ }
     /* 470:    */ }
   /* 471:556 */ return result;
   /* 472:    */ }
 public static LoadBalancer generateLoadBalancer() {
   LoadBalancer loadBalancer = new LoadBalancer();
   loadBalancer.setPort(port);
   Set<AccessList> accessLists = new HashSet<AccessList>();
   AccessList item = new AccessList();
   item.setUserName(username);
   item.setId(id);
   item.setIpAddress(ipv42);
   item.setType(AccessListType.DENY);
   item.setLoadbalancer(loadBalancer);
   accessLists.add(item);
   loadBalancer.setAccessLists(accessLists);
   loadBalancer.setAccountId(accountId);
   loadBalancer.setAlgorithm(LoadBalancerAlgorithm.ROUND_ROBIN);
   ConnectionLimit limit = new ConnectionLimit();
   limit.setId(id);
   limit.setUserName(username);
   limit.setLoadBalancer(loadBalancer);
   limit.setMaxConnectionRate(maxConnectRate);
   limit.setMaxConnections(maxConnections);
   limit.setMinConnections(minConnections);
   limit.setRateInterval(rateInterval);
   loadBalancer.setConnectionLimit(limit);
   loadBalancer.setConnectionLogging(active);
   loadBalancer.setContentCaching(active);
   loadBalancer.setCreated(Calendar.getInstance());
   loadBalancer.setUpdated(Calendar.getInstance());
   loadBalancer.setHalfClosed(active);
   HealthMonitor monitor = new HealthMonitor();
   monitor.setUserName(username);
   monitor.setId(id);
   monitor.setAttemptsBeforeDeactivation(numAttempts);
   monitor.setBodyRegex(regex);
   monitor.setDelay(delay);
   monitor.setHostHeader(header);
   monitor.setLoadbalancer(loadBalancer);
   monitor.setStatusRegex(regex);
   monitor.setPath(path);
   monitor.setTimeout(timeout);
   monitor.setType(HealthMonitorType.CONNECT);
   loadBalancer.setHealthMonitor(monitor);
   loadBalancer.setHost(new Host());
   loadBalancer.setName(name);
   Set<Node> nodes = new HashSet<Node>();
   Node node = new Node();
   node.setId(id);
   node.setPort(port);
   node.setLoadbalancer(loadBalancer);
   node.setCondition(NodeCondition.ENABLED);
   node.setIpAddress(ipv43);
   List<NodeMeta> nodeMetadata = new ArrayList<NodeMeta>();
   NodeMeta nodeMeta = new NodeMeta();
   nodeMeta.setKey(metaKey);
   nodeMeta.setNode(node);
   nodeMeta.setValue(metaValue);
   nodeMeta.setId(id);
   nodeMeta.setUserName(username);
   nodeMetadata.add(nodeMeta);
   node.setNodeMetadata(nodeMetadata);
   node.setStatus(NodeStatus.ONLINE);
   node.setType(NodeType.PRIMARY);
   node.setWeight(weight);
   nodes.add(node);
   node = new Node();
   node.setId(id + 1);
   node.setPort(port);
   node.setLoadbalancer(loadBalancer);
   node.setCondition(NodeCondition.ENABLED);
   node.setIpAddress(ipv44);
   nodeMetadata = new ArrayList<NodeMeta>();
   nodeMeta = new NodeMeta();
   nodeMeta.setKey(metaKey);
   nodeMeta.setNode(node);
   nodeMeta.setValue(metaValue);
   nodeMeta.setId(id + 1);
   nodeMeta.setUserName(username);
   nodeMetadata.add(nodeMeta);
   node.setNodeMetadata(nodeMetadata);
   node.setStatus(NodeStatus.ONLINE);
   node.setType(NodeType.PRIMARY);
   node.setWeight(weight);
   nodes.add(node);
   loadBalancer.setNodes(nodes);
   Set<LoadbalancerMeta> lbMetadata = new HashSet<LoadbalancerMeta>();
   LoadbalancerMeta lbMeta = new LoadbalancerMeta();
   lbMeta.setUserName(username);
   lbMeta.setId(id);
   lbMeta.setKey(metaKey);
   lbMeta.setValue(metaValue);
   lbMeta.setLoadbalancer(loadBalancer);
   lbMetadata.add(lbMeta);
   loadBalancer.setLoadbalancerMetadata(lbMetadata);
   loadBalancer.setProtocol(LoadBalancerProtocol.HTTP);
   RateLimit limits = new RateLimit();
   limits.setLoadbalancer(loadBalancer);
   limits.setId(id);
   limits.setUserName(username);
   limits.setExpirationTime(Calendar.getInstance());
   limits.setMaxRequestsPerSecond(maxRequests);
   Ticket ticket = new Ticket();
   ticket.setUserName(username);
   ticket.setId(id);
   ticket.setLoadbalancer(loadBalancer);
   ticket.setComment(comment);
   ticket.setTicketId(ticketId);
   limits.setTicket(ticket);
   loadBalancer.setRateLimit(limits);
   loadBalancer.setSessionPersistence(SessionPersistence.HTTP_COOKIE);
   SslTermination termination = new SslTermination();
   termination.setId(id);
   termination.setEnabled(active);
   termination.setUserName(username);
   termination.setSecurePort(securePort);
   termination.setCertificate(cert);
   termination.setPrivatekey(key);
   termination.setSecureTrafficOnly(inactive);
   termination.setLoadbalancer(loadBalancer);
   loadBalancer.setSslTermination(termination);
   loadBalancer.setStatus(LoadBalancerStatus.ACTIVE);
   loadBalancer.setSticky(inactive);
   Suspension suspension = new Suspension();
   suspension.setUserName(username);
   suspension.setId(id);
   suspension.setLoadbalancer(loadBalancer);
   suspension.setUser(user);
   suspension.setReason(reason);
   suspension.setTicket(ticket);
   loadBalancer.setSuspension(suspension);
   Set<Ticket> tickets = new HashSet<Ticket>();
   tickets.add(ticket);
   loadBalancer.setTickets(tickets);
   loadBalancer.setTimeout(timeout);
   UserPages pages = new UserPages();
   pages.setLoadbalancer(loadBalancer);
   pages.setId(id);
   pages.setUserName(username);
   pages.setErrorpage(errorPage);
   loadBalancer.setUserPages(pages);
   loadBalancer.setId(id);
   loadBalancer.setUserName(username);
   Set<LoadBalancerJoinVip> vipList = spy(new HashSet<LoadBalancerJoinVip>());
   VirtualIp vip = new VirtualIp();
   vip.setId(1234);
   vip.setIpAddress("10.69.0.60");
   LoadBalancerJoinVip loadBalancerJoinVip = new LoadBalancerJoinVip();
   loadBalancerJoinVip.setVirtualIp(vip);
   vipList.add(loadBalancerJoinVip);
   loadBalancer.setLoadBalancerJoinVipSet(vipList);
   return loadBalancer;
 }
示例#11
0
  public static void main(String[] args) {

    System.out.println("Start Graph Tests");

    System.out.println("Test 1 START: Basic Node and edge methods");

    // Graph creation and deletion
    Graph g1 = new Graph();
    Node nX = new Node("nY");
    Node nY = new Node("nX");
    if (!g1.addNode(nX)) {
      System.out.println("Test1.0.1 Fail");
    }
    if (!g1.addNode(nY)) {
      System.out.println("Test1.0.2 Fail");
    }
    if (g1.addNode(nY)) {
      System.out.println("Test1.0.3 Fail");
    }
    Edge eX = new Edge(nX, nY);
    if (!g1.addEdge(eX)) {
      System.out.println("Test1.0.4 Fail");
    }
    if (g1.addEdge(eX)) {
      System.out.println("Test1.0.5 Fail");
    }

    // test the consistency checker
    if (!g1.consistent()) {
      System.out.println("Test1.0.6 Fail");
    }

    ArrayList<Edge> nYTo = nY.getEdgesTo();
    nYTo.remove(eX);
    if (g1.consistent()) {
      System.out.println("Test1.0.7 Fail");
    }
    nYTo.add(eX);
    if (!g1.consistent()) {
      System.out.println("Test1.0.8 Fail");
    }
    ArrayList<Edge> g1Edges = g1.getEdges();
    g1Edges.remove(eX);
    if (g1.consistent()) {
      System.out.println("Test1.0.9 Fail");
    }
    g1Edges.add(eX);
    if (!g1.consistent()) {
      System.out.println("Test1.0.10 Fail");
    }

    Node nOutside = new Node();
    eX.setFrom(nOutside);
    if (g1.consistent()) {
      System.out.println("Test1.0.11 Fail");
    }
    eX.setFrom(nX);
    if (!g1.consistent()) {
      System.out.println("Test1.0.12 Fail");
    }

    g1 = new Graph("G");
    if (!g1.getLabel().equals("G")) {
      System.out.println("Test1.0.13 Fail");
    }
    g1.setLabel("H");
    if (!g1.getLabel().equals("H")) {
      System.out.println("Test1.0.14 Fail");
    }
    if (!g1.consistent()) {
      System.out.println("Test1.0.15 Fail");
    }

    /* first real test graph

                   ^e9v
     n1  e1> n2 e2> n3          n6
     e3v    e4^    e5ve6ve7^
      ---n4--- <e8 n5
    */

    // Graph Object creation

    g1.clear();
    Node n1 = new Node("n1");
    if (!g1.addNode(n1)) {
      System.out.println("Test1.1.1 Fail");
    }
    Node n2 = new Node("n2");
    if (!g1.addNode(n2)) {
      System.out.println("Test1.1.2 Fail");
    }
    Node n3 = new Node();
    if (!g1.addNode(n3)) {
      System.out.println("Test1.1.3 Fail");
    }
    Node n4 = new Node("n4");
    if (!g1.addNode(n4)) {
      System.out.println("Test1.1.4 Fail");
    }
    Node n5 = new Node("test");
    if (!g1.addNode(n5)) {
      System.out.println("Test1.1.5 Fail");
    }
    Node n6 = new Node("n6");
    if (!g1.addNode(n6)) {
      System.out.println("Test1.1.6 Fail");
    }

    Edge e1 = new Edge(n6, n6);
    if (!g1.addEdge(e1)) {
      System.out.println("Test1.1.7 Fail");
    }
    Edge e2 = new Edge(n2, n3);
    if (!g1.addEdge(e2)) {
      System.out.println("Test1.1.8 Fail");
    }
    Edge e3 = new Edge(n1, n4);
    if (!g1.addEdge(e3)) {
      System.out.println("Test1.1.9 Fail");
    }
    Edge e4 = new Edge(n4, n2);
    if (!g1.addEdge(e4)) {
      System.out.println("Test1.1.10 Fail");
    }
    Edge e5 = new Edge(n3, n5);
    if (!g1.addEdge(e5)) {
      System.out.println("Test1.1.11 Fail");
    }
    Edge e6 = new Edge(n3, n5);
    if (!g1.addEdge(e6)) {
      System.out.println("Test1.1.12 Fail");
    }
    Edge e7 = new Edge(n3, n5);
    if (!g1.addEdge(e7)) {
      System.out.println("Test1.1.13 Fail");
    }
    Edge e8 = new Edge(n1, n1);
    if (!g1.addEdge(e8)) {
      System.out.println("Test1.1.14 Fail");
    }
    Edge e9 = new Edge(n3, n3);
    if (!g1.addEdge(e9)) {
      System.out.println("Test1.1.15 Fail");
    }

    // oposite end test
    if (e1.getOppositeEnd(n6) != n6) {
      System.out.println("Test1.1.16 Fail");
    }
    if (e2.getOppositeEnd(n2) != n3) {
      System.out.println("Test1.1.17 Fail");
    }
    if (e2.getOppositeEnd(n3) != n2) {
      System.out.println("Test1.1.18 Fail");
    }
    if (e2.getOppositeEnd(n6) != null) {
      System.out.println("Test1.1.19 Fail");
    }

    // changing the connections of edges
    e1.setFromTo(n4, n4);
    e1.setFrom(n5);
    e1.setTo(n5);
    e1.setFromTo(n3, n6);
    e1.setFromTo(n1, n2);
    e8.setFrom(n5);
    e8.setTo(n4);
    e7.reverse();
    e9.reverse();
    // resetting labels
    n3.setLabel("n3");
    n5.setLabel("n5");

    Node tempTo = e1.getTo();
    Node tempFrom = e1.getFrom();

    e1.reverse();
    if (e1.getTo() != tempFrom) {
      System.out.println("Test1.1.20 Fail");
    }

    if (e1.getFrom() != tempTo) {
      System.out.println("Test1.1.21 Fail");
    }

    e1.reverse();

    if (e1.getTo() != tempTo) {
      System.out.println("Test1.1.22 Fail");
    }

    if (e1.getFrom() != tempFrom) {
      System.out.println("Test1.1.23 Fail");
    }

    if (!g1.consistent()) {
      System.out.println("Test1.1.24 Fail");
    }

    // Node connectivity testing
    HashSet<Node> testN = new HashSet<Node>();

    if (!n6.connectingNodes().equals(testN)) {
      System.out.println("Test1.2.1 Fail");
    }
    if (!n6.unvisitedConnectingNodes().equals(testN)) {
      System.out.println("Test1.2.2 Fail");
    }
    if (!n6.connectingEdges().equals(testN)) {
      System.out.println("Test1.2.4 Fail");
    }

    testN = new HashSet<Node>();
    testN.add(n5);
    testN.add(n3);
    testN.add(n2);

    if (!n3.connectingNodes().equals(testN)) {
      System.out.println("Test1.2.5 Fail");
    }

    if (!n3.unvisitedConnectingNodes().equals(testN)) {
      System.out.println("Test1.2.7 Fail");
    }

    // Node visited flag testing

    n2.setVisited(true);

    if (!n3.connectingNodes().equals(testN)) {
      System.out.println("Test1.3.1 Fail");
    }
    testN.remove(n2);
    if (!n3.unvisitedConnectingNodes().equals(testN)) {
      System.out.println("Test1.3.3 Fail");
    }

    g1.setNodesVisited(true);
    testN = new HashSet<Node>();

    if (!n3.unvisitedConnectingNodes().equals(testN)) {
      System.out.println("Test1.3.4 Fail");
    }

    n2.setVisited(false);
    testN.add(n2);

    if (!n3.unvisitedConnectingNodes().equals(testN)) {
      System.out.println("Test1.3.5 Fail");
    }

    testN.remove(n2);

    n2.setVisited(true);
    testN = new HashSet<Node>();
    if (!n3.unvisitedConnectingNodes().equals(testN)) {
      System.out.println("Test1.3.6 Fail");
    }

    testN = new HashSet<Node>();
    testN.add(n5);
    testN.add(n3);
    testN.add(n2);
    if (!n3.connectingNodes().equals(testN)) {
      System.out.println("Test1.3.7 Fail");
    }
    g1.setNodesVisited();

    // Edge visited flag testing

    HashSet<Edge> testE = new HashSet<Edge>();

    testE = new HashSet<Edge>();
    testE.add(e3);
    testE.add(e1);
    if (!n1.connectingEdges().equals(testE)) {
      System.out.println("Test1.5.1 Fail");
    }
    if (!n1.unvisitedConnectingEdges().equals(testE)) {
      System.out.println("Test1.5.2 Fail");
    }

    testE.remove(e1);
    e1.setVisited(true);
    if (!n1.unvisitedConnectingEdges().equals(testE)) {
      System.out.println("Test1.5.3 Fail");
    }
    e1.setVisited(false);
    e2.setVisited(false);

    g1.setEdgesVisited(true);
    testE = new HashSet<Edge>();
    if (!n1.unvisitedConnectingEdges().equals(testE)) {
      System.out.println("Test1.5.4 Fail");
    }
    e1.setVisited(true);
    e2.setVisited(true);
    g1.setEdgesVisited(false);
    testE = new HashSet<Edge>();
    testE.add(e3);
    testE.add(e1);
    if (!n1.connectingEdges().equals(testE)) {
      System.out.println("Test1.5.5 Fail");
    }
    if (!n1.unvisitedConnectingEdges().equals(testE)) {
      System.out.println("Test1.5.6 Fail");
    }

    System.out.print("Test 1 END");

    // test dynamic graph stuff
    System.out.println(" | Test 2 START: Object removal");
    Node nd1 = new Node("nd1");
    Node nd2 = new Node("nd2");
    Node nd3 = new Node("nd3");

    Graph g2 = new Graph("g2");
    g2.addNode(nd1);
    g2.addNode(nd2);
    g2.addNode(nd3);

    Edge ed1 = new Edge(nd1, nd2);
    Edge ed2 = new Edge(nd1, nd2);
    Edge ed3 = new Edge(nd2, nd1);
    Edge ed4 = new Edge(nd1, nd1);
    Edge ed5 = new Edge(nd3, nd2);
    g2.addEdge(ed1);
    g2.addEdge(ed2);
    g2.addEdge(ed3);
    g2.addEdge(ed4);
    g2.addEdge(ed5);

    g2.removeNode("nd1");

    ArrayList<Node> testNodeAL;
    ArrayList<Edge> testEdgeAL;
    testEdgeAL = new ArrayList<Edge>();
    testEdgeAL.add(ed5);
    if (!g2.getEdges().equals(testEdgeAL)) {
      System.out.println("Test2.1 Fail");
    }
    g2.addNode(nd3);
    if (!g2.getEdges().equals(testEdgeAL)) {
      System.out.println("Test2.2 Fail");
    }
    g2.removeNode(nd2);
    testEdgeAL = new ArrayList<Edge>();
    if (!g2.getEdges().equals(testEdgeAL)) {
      System.out.println("Test2.3 Fail");
    }
    testNodeAL = new ArrayList<Node>();
    testNodeAL.add(nd3);
    if (!g2.getNodes().equals(testNodeAL)) {
      System.out.println("Test2.4 Fail");
    }
    testEdgeAL = new ArrayList<Edge>();
    if (!g2.getEdges().equals(testEdgeAL)) {
      System.out.println("Test2.5 Fail");
    }

    if (!g2.consistent()) {
      System.out.println("Test2.5.0 Fail");
    }

    g2.clear();

    Node dyNode1 = new Node("dyNode1");
    Node dyNode2 = new Node("dyNode2");
    g2.addNode(dyNode1);
    g2.addNode(dyNode2);

    Edge dyEdge1 = new Edge(dyNode1, dyNode2, "dyEdge2");
    g2.addEdge(dyEdge1);

    g2.removeEdge(dyEdge1);

    if (dyEdge1.getFrom() != null) {
      System.out.println("Test2.5.1 Fail");
    }
    if (dyEdge1.getTo() != null) {
      System.out.println("Test2.5.2 Fail");
    }

    HashSet dyTest = new HashSet();

    if (dyNode1.getEdgesFrom().equals(dyTest) == false) {
      System.out.println("Test2.5.3 Fail");
    }
    if (dyNode1.getEdgesTo().equals(dyTest) == false) {
      System.out.println("Test2.5.4 Fail");
    }
    if (dyNode2.getEdgesFrom().equals(dyTest) == false) {
      System.out.println("Test2.5.5 Fail");
    }
    if (dyNode2.getEdgesTo().equals(dyTest) == false) {
      System.out.println("Test2.5.6 Fail");
    }
    if (!g2.consistent()) {
      System.out.println("Test2.5.7 Fail");
    }

    g2.clear();
    g2.addNode(nd1);
    g2.addNode(nd2);
    g2.addNode(nd3);

    ed1 = new Edge(nd1, nd2, "A", 1.1);
    ed2 = new Edge(nd1, nd2, "B");
    ed3 = new Edge(nd2, nd1, 1);
    ed4 = new Edge(nd1, nd1);
    ed5 = new Edge(nd3, nd2);
    g2.addEdge(ed1);
    g2.addEdge(ed2);
    g2.addEdge(ed3);
    g2.addEdge(ed4);
    g2.addEdge(ed5);

    // edge label and weight testing
    if (!ed1.getLabel().equals("A")) {
      System.out.println("Test2.5.1 Fail");
    }
    ed1.setLabel("C");
    if (!ed1.getLabel().equals("C")) {
      System.out.println("Test2.5.2 Fail");
    }
    if (!ed2.getLabel().equals("B")) {
      System.out.println("Test2.5.3 Fail");
    }
    if (ed1.getWeight() != 1.1) {
      System.out.println("Test2.5.4 Fail");
    }
    ed1.setWeight(2.2);
    if (ed1.getWeight() != 2.2) {
      System.out.println("Test2.5.5 Fail");
    }
    if (ed3.getWeight() != 1) {
      System.out.println("Test2.5.6 Fail");
    }

    g2.removeEdge(ed2);
    testEdgeAL = new ArrayList<Edge>();
    testEdgeAL.add(ed1);
    testEdgeAL.add(ed3);
    testEdgeAL.add(ed4);
    testEdgeAL.add(ed5);
    if (!g2.getEdges().equals(testEdgeAL)) {
      System.out.println("Test2.6 Fail");
    }
    ArrayList<Node> testNodeAL2;

    testNodeAL2 = new ArrayList<Node>();
    testNodeAL2.add(nd1);
    testNodeAL2.add(nd2);
    testNodeAL2.add(nd3);
    if (!g2.getNodes().equals(testNodeAL2)) {
      System.out.println("Test2.7 Fail");
    }

    g2.removeEdge(ed4);

    testEdgeAL.remove(ed4);
    if (!g2.getEdges().equals(testEdgeAL)) {
      System.out.println("Test2.8 Fail");
    }
    if (!g2.getNodes().equals(testNodeAL2)) {
      System.out.println("Test2.9 Fail");
    }

    ed4 = new Edge(nd3, nd3);
    g2.addEdge(ed4);
    testEdgeAL.add(ed4);
    if (!g2.getEdges().equals(testEdgeAL)) {
      System.out.println("Test2.10 Fail");
    }
    if (!g2.getNodes().equals(testNodeAL2)) {
      System.out.println("Test2.11 Fail");
    }

    if (!g2.consistent()) {
      System.out.println("Test2.11.0 Fail");
    }

    g2.clear();

    testEdgeAL = new ArrayList<Edge>();
    if (!g2.getEdges().equals(testEdgeAL)) {
      System.out.println("Test2.12 Fail");
    }
    if (!g2.getNodes().equals(testEdgeAL)) {
      System.out.println("Test2.13 Fail");
    }

    ed4 = new Edge(nd2, nd1);
    g2.addNode(nd1);
    g2.addNode(nd2);
    g2.addNode(nd3);
    g2.addEdge(ed4);

    g2.removeEdge(ed4);

    if (!g2.getEdges().equals(testEdgeAL)) {
      System.out.println("Test2.14 Fail");
    }
    if (!g2.getNodes().equals(testNodeAL2)) {
      System.out.println("Test2.15 Fail");
    }

    if (!g2.consistent()) {
      System.out.println("Test2.15.0 Fail");
    }

    // score field testing
    Graph gScore = new Graph();

    Node ns1 = new Node("A");
    Node ns2 = new Node();
    Node ns3 = new Node("C");
    Node ns4 = new Node("D");

    gScore.addNode(ns1);
    gScore.addNode(ns2);
    gScore.addNode(ns3);
    gScore.addNode(ns4);

    Edge es1 = new Edge(ns1, ns2, "A", 1.1);
    Edge es2 = new Edge(ns4, ns1);
    Edge es3 = new Edge(ns1, ns3);

    gScore.addEdge(es1);
    gScore.addEdge(es2);
    gScore.addEdge(es3);

    if (ns1.getScore() != 0.0) {
      System.out.println("Test2.16.1 Fail");
    }

    if (es1.getScore() != 0.0) {
      System.out.println("Test2.16.2 Fail");
    }

    ns1.setScore(1.3);
    es1.setScore(2.4);

    if (ns1.getScore() != 1.3) {
      System.out.println("Test2.16.3 Fail");
    }

    if (es1.getScore() != 2.4) {
      System.out.println("Test2.16.4 Fail");
    }

    ArrayList<Node> alNodeScore = new ArrayList<Node>();
    ArrayList<Edge> alEdgeScore = new ArrayList<Edge>();
    gScore.setNodesScores(alNodeScore, 3.5);
    gScore.setEdgesScores(alEdgeScore, 4.6);

    if (ns1.getScore() != 1.3) {
      System.out.println("Test2.16.5 Fail");
    }

    if (es1.getScore() != 2.4) {
      System.out.println("Test2.16.6 Fail");
    }

    alNodeScore.add(ns1);
    alNodeScore.add(ns2);
    gScore.setNodesScores(alNodeScore, 5.7);
    alNodeScore.remove(ns1);
    alNodeScore.remove(ns2);
    alEdgeScore.add(es1);
    alEdgeScore.add(es2);
    gScore.setEdgesScores(alEdgeScore, 6.8);

    if (ns1.getScore() != 5.7) {
      System.out.println("Test2.16.7 Fail");
    }
    if (ns3.getScore() != 0.0) {
      System.out.println("Test2.16.8 Fail");
    }

    if (es1.getScore() != 6.8) {
      System.out.println("Test2.16.9 Fail");
    }
    if (es3.getScore() != 0.0) {
      System.out.println("Test2.16.10 Fail");
    }

    gScore.setNodesScores(7.9);
    gScore.setEdgesScores(8.01);

    if (ns1.getScore() != 7.9) {
      System.out.println("Test2.16.11 Fail");
    }
    if (ns3.getScore() != 7.9) {
      System.out.println("Test2.16.12 Fail");
    }

    if (es1.getScore() != 8.01) {
      System.out.println("Test2.16.13 Fail");
    }
    if (es3.getScore() != 8.01) {
      System.out.println("Test2.16.14 Fail");
    }

    Graph testChangeGraph = new Graph();

    if (testChangeGraph.moveNodeToEnd(n1)) {
      System.out.println("Test2.17.1 Fail");
    }
    if (testChangeGraph.moveEdgeToEnd(e1)) {
      System.out.println("Test2.17.2 Fail");
    }

    ArrayList<Node> testChangeNodeAL = new ArrayList<Node>();

    Node changeNode1 = new Node("c1");
    testChangeGraph.addNode(changeNode1);

    if (testChangeGraph.moveNodeToEnd(n1)) {
      System.out.println("Test2.17.3 Fail");
    }

    testChangeGraph.moveNodeToEnd(changeNode1);

    testChangeNodeAL = new ArrayList<Node>();
    testChangeNodeAL.add(changeNode1);

    if (!testChangeGraph.getNodes().equals(testChangeNodeAL)) {
      System.out.println("Test2.17.4 Fail");
    }

    Node changeNode2 = new Node("c2");
    Node changeNode3 = new Node("c3");

    Edge changeEdge1 = new Edge(changeNode1, changeNode2);
    Edge changeEdge2 = new Edge(changeNode3, changeNode2);
    Edge changeEdge3 = new Edge(changeNode1, changeNode3);

    testChangeGraph.addNode(changeNode2);
    testChangeGraph.addNode(changeNode3);

    testChangeGraph.addEdge(changeEdge1);
    testChangeGraph.addEdge(changeEdge2);
    testChangeGraph.addEdge(changeEdge3);

    testChangeNodeAL = new ArrayList<Node>();
    testChangeNodeAL.add(changeNode1);
    testChangeNodeAL.add(changeNode3);
    testChangeNodeAL.add(changeNode2);

    testChangeGraph.moveNodeToEnd(changeNode2);

    if (!testChangeGraph.getNodes().equals(testChangeNodeAL)) {
      System.out.println("Test2.17.5 Fail");
    }

    ArrayList<Edge> testChangeEdgeAL = new ArrayList<Edge>();
    testChangeEdgeAL.add(changeEdge2);
    testChangeEdgeAL.add(changeEdge3);
    testChangeEdgeAL.add(changeEdge1);

    testChangeGraph.moveEdgeToEnd(changeEdge1);

    if (!testChangeGraph.getEdges().equals(testChangeEdgeAL)) {
      System.out.println("Test2.17.6 Fail");
    }

    System.out.print("Test 2 END");

    System.out.println(" | Test 3 START: Shortest path");

    ArrayList<Node> path = new ArrayList<Node>();
    path.add(n5);
    path.add(n4);
    path.add(n1);
    if (!g1.unweightedShortest(n5, n1).equals(path)) {
      System.out.println("Test3.1 Fail");
    }
    path = new ArrayList<Node>();
    path.add(n3);
    if (!g1.unweightedShortest(n3, n3).equals(path)) {
      System.out.println("Test3.2 Fail");
    }
    if (g1.unweightedShortest(n4, n6) != null) {
      System.out.println("Test3.3 Fail");
    }

    System.out.print("Test 3 END");

    // Adjacency Edge Graph creation stuff

    System.out.println(" | Test 4 START: Adjacency Graph");

    // finding or adding a node from a label
    Node nA = g1.addAdjacencyNode("nA");
    testNodeAL = new ArrayList<Node>();
    testNodeAL.add(n1);
    testNodeAL.add(n2);
    testNodeAL.add(n3);
    testNodeAL.add(n4);
    testNodeAL.add(n5);
    testNodeAL.add(n6);
    testNodeAL.add(nA);
    if (!g1.getNodes().equals(testNodeAL)) {
      System.out.println("Test4.1 Fail");
    }

    if (g1.addAdjacencyNode("n2") != n2) {
      System.out.println("Test4.2 Fail");
    }
    if (!g1.getNodes().equals(testNodeAL)) {
      System.out.println("Test4.3 Fail");
    }

    Node nDuplicate = new Node("n1");
    g1.addNode(nDuplicate);
    if (g1.addAdjacencyNode("n1") != null) {
      System.out.println("Test4.4 Fail");
    }
    g1.removeNode(nDuplicate);

    if (!g1.consistent()) {
      System.out.println("Test4.4.0 Fail");
    }

    // adding an adjacency edge
    Edge eZ1 = g1.addAdjacencyEdge("n3", "n3");

    Edge[] tempArray = {e1, e2, e3, e4, e5, e6, e7, e8, e9, eZ1};
    ArrayList<Edge> testEdgeAL2 = new ArrayList<Edge>(Arrays.asList(tempArray));

    if (!g1.getEdges().equals(testEdgeAL2)) {
      System.out.println("Test4.5 Fail");
    }
    if (!g1.getNodes().equals(testNodeAL)) {
      System.out.println("Test4.6 Fail");
    }

    g1.addAdjacencyEdge("nB", "");
    if (g1.getNodes().size() != 8) {
      System.out.println("Test4.7 Fail");
    }

    Edge eZ3 = g1.addAdjacencyEdge("nB", "n1");

    Edge[] tempArray2 = {e1, e2, e3, e4, e5, e6, e7, e8, e9, eZ1, eZ3};
    testEdgeAL2 = new ArrayList<Edge>(Arrays.asList(tempArray2));

    if (!g1.getEdges().equals(testEdgeAL2)) {
      System.out.println("Test4.8 Fail");
    }

    g1.addAdjacencyEdge("", "");
    Edge eZ4 = g1.addAdjacencyEdge("nC", "nD");

    Edge[] tempArray3 = {e1, e2, e3, e4, e5, e6, e7, e8, e9, eZ1, eZ3, eZ4};
    testEdgeAL2 = new ArrayList<Edge>(Arrays.asList(tempArray3));

    if (!g1.getEdges().equals(testEdgeAL2)) {
      System.out.println("Test4.9 Fail");
    }
    if (g1.getNodes().size() != 10) {
      System.out.println("Test4.10 Fail");
    }

    System.out.print("Test 4 END");

    System.out.println(" | Test 5 START: Connected");

    if (g1.connected()) {
      System.out.println("Test5.1 Fail");
    }
    g1.addEdge(new Edge(nA, n6));
    if (g1.connected()) {
      System.out.println("Test5.2 Fail");
    }
    g1.addAdjacencyEdge("nA", "nD");
    g1.addAdjacencyEdge("nA", "n4");
    if (!g1.connected()) {
      System.out.println("Test5.3 Fail");
    }

    if (!g1.consistent()) {
      System.out.println("Test5.3.0 Fail");
    }

    Graph g4 = new Graph("g4");
    if (!g4.connected()) {
      System.out.println("Test5.4 Fail");
    }
    g4.addNode(new Node("z1"));
    if (!g4.connected()) {
      System.out.println("Test5.5 Fail");
    }
    g4.addNode(new Node("z2"));
    if (g4.connected()) {
      System.out.println("Test5.6 Fail");
    }
    g4.addAdjacencyEdge("z1", "z2");
    if (!g4.connected()) {
      System.out.println("Test5.7 Fail");
    }
    g4.addAdjacencyEdge("z2", "z3");
    if (!g4.connected()) {
      System.out.println("Test5.8 Fail");
    }
    g4.removeNode("z2");
    if (g4.connected()) {
      System.out.println("Test5.9 Fail");
    }

    System.out.print("Test 5 END");

    System.out.println(" | Test 6 START: Equality by label testing");

    Graph gc1 = new Graph("gc1");
    Graph gc2 = new Graph("gc2");

    if (!gc1.equalsByNodeLabel(gc2)) {
      System.out.println("Test6.1 Fail");
    }

    gc1.addNode(new Node("A"));
    if (gc1.equalsByNodeLabel(gc2)) {
      System.out.println("Test6.2 Fail");
    }
    gc2.addNode(new Node("B"));

    if (gc2.equalsByNodeLabel(gc1)) {
      System.out.println("Test6.3 Fail");
    }

    gc2.addNode(new Node("A"));

    if (gc1.equalsByNodeLabel(gc2)) {
      System.out.println("Test6.4 Fail");
    }

    gc1.addNode(new Node("B"));

    if (!gc1.equalsByNodeLabel(gc2)) {
      System.out.println("Test6.5 Fail");
    }

    gc1.addNode(new Node("C"));
    gc2.addNode(new Node("C"));

    if (!gc1.equalsByNodeLabel(gc2)) {
      System.out.println("Test6.6 Fail");
    }

    gc1.addAdjacencyEdge("A", "B");

    if (gc1.equalsByNodeLabel(gc2)) {
      System.out.println("Test6.7 Fail");
    }

    gc2.addAdjacencyEdge("A", "B");

    if (!gc1.equalsByNodeLabel(gc2)) {
      System.out.println("Test6.8 Fail");
    }

    gc1.addAdjacencyEdge("C", "B");
    gc2.addAdjacencyEdge("C", "B");

    if (!gc1.equalsByNodeLabel(gc2)) {
      System.out.println("Test6.9 Fail");
    }

    gc1.addAdjacencyEdge("C", "A");
    gc2.addAdjacencyEdge("A", "C");

    if (gc1.equalsByNodeLabel(gc2)) {
      System.out.println("Test6.10 Fail");
    }

    // this test is two non isomorphic graphs for which the comparison succeeds.

    gc1.clear();
    gc2.clear();

    Node gcn1 = new Node("");
    Node gcn2 = new Node("");
    Node gcn3 = new Node("");
    Node gcn4 = new Node("");
    gc1.addNode(gcn1);
    gc1.addNode(gcn2);
    gc2.addNode(gcn3);
    gc2.addNode(gcn4);

    gc1.addEdge(new Edge(gcn1, gcn2));

    gc2.addEdge(new Edge(gcn3, gcn3));

    if (!gc1.equalsByNodeLabel(gc2)) {
      System.out.println("Test6.11 Fail");
    }

    // dispite the equal labels these graphs are not equal due to the extra edge
    gc2.addEdge(new Edge(gcn4, gcn3));

    if (gc1.equalsByNodeLabel(gc2)) {
      System.out.println("Test6.12 Fail");
    }

    gc1.addEdge(new Edge(gcn1, gcn2));

    if (!gc1.equalsByNodeLabel(gc2)) {
      System.out.println("Test6.13 Fail");
    }

    if (!gc1.consistent()) {
      System.out.println("Test6.13.0 Fail");
    }

    System.out.print("Test 6 END");

    // Adjacency file testing. This test creates a file called test.adj
    // It will crash with an exception if it cant create the file.

    System.out.println(" | Test 7 START: Adjacency file - needs to read and write test.adj");

    g4.generateRandomGraph(10, 15);
    g4.saveAdjacencyFile("test.adj");
    Graph g5 = new Graph("g5");
    g5.loadAdjacencyFile("test.adj");

    if (!g4.equalsByNodeLabel(g5)) {
      System.out.println("Test7.1 Fail");
    }

    if (!g4.consistent()) {
      System.out.println("Test7.1.0 Fail");
    }
    if (!g5.consistent()) {
      System.out.println("Test7.1.1 Fail");
    }

    g4.clear();
    g4.saveAdjacencyFile("test.adj");
    g5.clear();
    g5.generateRandomGraph(10, 15);
    g4.loadAdjacencyFile("test.adj");
    if (g4.equalsByNodeLabel(g5)) {
      System.out.println("Test7.2 Fail");
    }
    g4.generateRandomGraph(20, 30);
    g4.addNode(n1);
    g4.saveAdjacencyFile("test.adj");
    g5.generateRandomGraph(10, 15);
    g5.loadAdjacencyFile("test.adj");
    g4.loadAdjacencyFile("test.adj");
    if (!g5.equalsByNodeLabel(g4)) {
      System.out.println("Test7.3 Fail");
    }
    g4.clear();
    g4.saveAdjacencyFile("test.adj");
    g4.addNode(n1);
    g4.loadAdjacencyFile("test.adj");
    if (!g4.equalsByNodeLabel(new Graph())) {
      System.out.println("Test7.4 Fail");
    }

    if (!g4.consistent()) {
      System.out.println("Test7.4.0 Fail");
    }

    System.out.print("Test 7 END");

    // partial node and edge access

    System.out.println(" | Test 8 START: visited and path fields");

    Graph g = new Graph();
    HashSet<Node> testa = new HashSet<Node>();
    HashSet<Node> testb = new HashSet<Node>();

    if (!g.unvisitedNodes().equals(testa)) {
      System.out.println("Test8.1 Fail");
    }
    if (!g.visitedNodes().equals(testb)) {
      System.out.println("Test8.2 Fail");
    }

    g.addNode(n1);
    g.addNode(n2);
    g.addNode(n3);
    g.addNode(n4);

    Edge eV1 = new Edge(n1, n2);
    Edge eV2 = new Edge(n3, n2);
    Edge eV3 = new Edge(n4, n4);

    testa.add(n1);
    testa.add(n2);
    testa.add(n3);
    testa.add(n4);

    if (!g.unvisitedNodes().equals(testa)) {
      System.out.println("Test8.5 Fail");
    }
    if (!g.visitedNodes().equals(testb)) {
      System.out.println("Test8.6 Fail");
    }

    n1.setVisited(true);
    n2.setVisited(true);

    testa.remove(n1);
    testa.remove(n2);

    testb.add(n1);
    testb.add(n2);

    if (!g.unvisitedNodes().equals(testa)) {
      System.out.println("Test8.9 Fail");
    }
    if (!g.visitedNodes().equals(testb)) {
      System.out.println("Test8.10 Fail");
    }

    HashSet<Edge> teste1 = new HashSet<Edge>();
    HashSet<Edge> teste2 = new HashSet<Edge>();

    if (!g.unvisitedEdges().equals(teste1)) {
      System.out.println("Test8.13 Fail");
    }
    if (!g.visitedEdges().equals(teste2)) {
      System.out.println("Test8.14 Fail");
    }

    g.addEdge(eV1);
    g.addEdge(eV2);
    g.addEdge(eV3);

    eV1.setVisited(true);
    eV2.setVisited(true);
    eV3.setVisited(true);

    teste2.add(eV1);
    teste2.add(eV2);
    teste2.add(eV3);

    if (!g.unvisitedEdges().equals(teste1)) {
      System.out.println("Test8.15 Fail");
    }
    if (!g.visitedEdges().equals(teste2)) {
      System.out.println("Test8.16 Fail");
    }

    eV3.setVisited(false);

    teste1.add(eV3);
    teste2.remove(eV3);

    if (!g.unvisitedEdges().equals(teste1)) {
      System.out.println("Test8.17 Fail");
    }
    if (!g.visitedEdges().equals(teste2)) {
      System.out.println("Test8.18 Fail");
    }

    System.out.print("Test 8 END");

    // euler tour tests
    System.out.println(" | Test 9 START: Euler Tour - needs to read and write test.euler");

    Graph eg = new Graph();
    ArrayList<Node> tour1 = new ArrayList<Node>();
    eg.saveTour("test.euler", tour1);
    ArrayList<Node> tour2 = eg.loadTour("test.euler");
    if (!eg.eulerTourInGraph(tour2)) {
      System.out.println("Test 9.1 Failed with tour " + tour2 + "\nand graph\n" + eg);
    }
    tour2.add(n1);
    if (eg.eulerTourInGraph(tour2)) {
      System.out.println("Test 9.2 Failed with tour " + tour2 + "\nand graph\n" + eg);
    }
    eg.saveTour("test.euler", tour1, false);
    tour2 = eg.loadTour("test.euler");
    if (eg.eulerTourInGraph(tour2)) {
      System.out.println("Test 9.3 Failed with tour " + tour2 + "\nand graph\n" + eg);
    }

    eg = new Graph();
    eg.generateRandomEulerGraph(5, 7);
    tour1 = eg.euler();
    eg.saveTour("test.euler", tour1);
    tour2 = eg.loadTour("test.euler");
    if (!eg.eulerTourInGraph(tour2)) {
      System.out.println("Test 9.4 Failed with tour " + tour2 + "\nand graph\n" + eg);
    }
    tour2 = eg.eulerSMK(false);
    if (!eg.eulerTourInGraph(tour2)) {
      System.out.println("Test 9.4a Failed with tour " + tour2 + "\nand graph\n" + eg);
    }
    tour2 = eg.eulerSMK(true);
    if (!eg.eulerTourInGraph(tour2)) {
      System.out.println("Test 9.4b Failed with tour " + tour2 + "\nand graph\n" + eg);
    }
    tour2.remove(2);
    if (eg.eulerTourInGraph(tour2)) {
      System.out.println("Test 9.5 Failed with tour " + tour2 + "\nand graph\n" + eg);
    }
    eg.addAdjacencyEdge("1", "2");
    eg.saveTour("test.euler", tour1, false);
    tour2 = eg.loadTour("test.euler");
    if (!eg.eulerTourInGraph(tour2)) {
      System.out.println("Test 9.6 Failed with tour " + tour2 + "\nand graph\n" + eg);
    }

    if (!eg.consistent()) {
      System.out.println("Test 9.6.0 Fail");
    }

    eg.clear();
    eg.addNode(n1);
    tour1 = eg.euler();
    tour2 = new ArrayList<Node>();
    if (!eg.eulerTourInGraph(tour2)) {
      System.out.println("Test 9.6.1 Failed with tour " + tour2 + "\nand graph\n" + eg);
    }
    eg.generateRandomEulerGraph(2, 4);
    tour1 = eg.euler();
    eg.saveTour("test.euler", tour1);
    tour2 = eg.loadTour("test.euler");
    if (!eg.eulerTourInGraph(tour2)) {
      System.out.println("Test 9.7 Failed with tour " + tour2 + "\nand graph\n" + eg);
    }
    tour2 = eg.eulerSMK(false);
    if (!eg.eulerTourInGraph(tour2)) {
      System.out.println("Test 9.7a Failed with tour " + tour2 + "\nand graph\n" + eg);
    }
    tour2 = eg.eulerSMK(true);
    if (!eg.eulerTourInGraph(tour2)) {
      System.out.println("Test 9.7b Failed with tour " + tour2 + "\nand graph\n" + eg);
    }
    tour2 = new ArrayList<Node>();
    if (eg.eulerTourInGraph(tour2)) {
      System.out.println("Test 9.8 Failed with tour " + tour2 + "\nand graph\n" + eg);
    }
    eg.addNode(new Node());
    eg.saveTour("test.euler", tour1, false);
    tour2 = eg.loadTour("test.euler");
    if (!eg.eulerTourInGraph(tour2)) {
      System.out.println("Test 9.9 Failed with tour " + tour2 + "\nand graph\n" + eg);
    }

    if (!eg.consistent()) {
      System.out.println("Test 9.9.0 Fail");
    }

    eg = new Graph();
    eg.generateRandomEulerGraph(20, 30);
    tour2 = eg.euler();
    if (!eg.eulerTourInGraph(tour2)) {
      System.out.println("Test 9.10 Failed with tour " + tour2 + "\nand graph\n" + eg);
    }
    tour2 = eg.eulerSMK(false);
    if (!eg.eulerTourInGraph(tour2)) {
      System.out.println("Test 9.10a Failed with tour " + tour2 + "\nand graph\n" + eg);
    }
    tour2 = eg.eulerSMK(true);
    if (!eg.eulerTourInGraph(tour2)) {
      System.out.println("Test 9.10b Failed with tour " + tour2 + "\nand graph\n" + eg);
    }

    if (!eg.consistent()) {
      System.out.println("Test 9.10.0 Fail");
    }

    Node nX0 = new Node("0");
    Node nX1 = new Node("1");
    Node nX2 = new Node("2");
    Node nX3 = new Node("3");
    Node nX4 = new Node("4");
    eg = new Graph();
    eg.addNode(nX0);
    eg.addNode(nX1);
    eg.addNode(nX2);
    eg.addNode(nX3);
    eg.addNode(nX4);
    eg.addEdge(new Edge(nX0, nX1));
    eg.addEdge(new Edge(nX3, nX2));
    eg.addEdge(new Edge(nX4, nX2));
    eg.addEdge(new Edge(nX0, nX1));
    eg.addEdge(new Edge(nX3, nX0));
    eg.addEdge(new Edge(nX0, nX3));
    eg.addEdge(new Edge(nX3, nX4));
    tour2 = eg.euler();
    if (!eg.eulerTourInGraph(tour2)) {
      System.out.println("Test 9.11 Failed with tour " + tour2 + "\nand graph\n" + eg);
    }
    tour2 = eg.eulerSMK(false);
    if (!eg.eulerTourInGraph(tour2)) {
      System.out.println("Test 9.11a Failed with tour " + tour2 + "\nand graph\n" + eg);
    }
    tour2 = eg.eulerSMK(true);
    if (!eg.eulerTourInGraph(tour2)) {
      System.out.println("Test 9.11b Failed with tour " + tour2 + "\nand graph\n" + eg);
    }

    System.out.print("Test 9 END");

    // test the brute force tsp
    System.out.println(" | Test 10 START: tsp");

    Graph tspGraph = new Graph();

    ArrayList<Edge> tspTest = new ArrayList<Edge>();

    if (!tspGraph.tsp().equals(tspTest)) {
      System.out.println("Test 10.1 Failed");
    }

    Node tspN1 = new Node("A");
    tspGraph.addNode(tspN1);

    if (!tspGraph.tsp().equals(tspTest)) {
      System.out.println("Test 10.2 Failed");
    }

    Node tspN2 = new Node("B");
    tspGraph.addNode(tspN2);

    Edge tspE1 = new Edge(tspN1, tspN2, 2);

    tspGraph.addEdge(tspE1);

    tspTest.add(tspE1);
    tspTest.add(tspE1);

    if (!tspGraph.tsp().equals(tspTest)) {
      System.out.println("Test 10.3 Failed");
    }
    if (tspGraph.sumEdgeWeights(tspGraph.tsp()) != 4.0) {
      System.out.println("Test 10.4 Failed");
    }

    Node tspN3 = new Node("C");
    tspGraph.addNode(tspN3);

    Edge tspE2 = new Edge(tspN1, tspN3, 40);
    Edge tspE3 = new Edge(tspN2, tspN3, 3);

    tspGraph.addEdge(tspE2);
    tspGraph.addEdge(tspE3);

    if (tspGraph.sumEdgeWeights(tspGraph.tsp()) != 10.0) {
      System.out.println("Test 10.5 Failed");
    }

    tspE2.setWeight(4);

    if (tspGraph.sumEdgeWeights(tspGraph.tsp()) != 9.0) {
      System.out.println("Test 10.6 Failed");
    }

    Node tspN4 = new Node("D");
    tspGraph.addNode(tspN4);

    tspGraph.addEdge(new Edge(tspN1, tspN4, 3.5));
    tspGraph.addEdge(new Edge(tspN2, tspN4, 6));
    tspGraph.addEdge(new Edge(tspN4, tspN3, 2.4));

    if (tspGraph.sumEdgeWeights(tspGraph.tsp()) != 10.9) {
      System.out.println("Test 10.7 Failed");
    }

    tspGraph.clear();

    tspGraph.addAdjacencyEdge("A", "H", 17.0);
    tspGraph.addAdjacencyEdge("G", "H", 1.0);
    tspGraph.addAdjacencyEdge("H", "E", 2);
    tspGraph.addAdjacencyEdge("G", "E", 9.0);
    tspGraph.addAdjacencyEdge("E", "D", 20.0);
    tspGraph.addAdjacencyEdge("C", "D", 2.5);
    tspGraph.addAdjacencyEdge("C", "B", 3.0);
    tspGraph.addAdjacencyEdge("D", "B", 4.0);

    if (tspGraph.sumEdgeWeights(tspGraph.tsp()) != 89.5) {
      System.out.println("Test 10.8 Failed");
    }

    tspGraph.clear();

    tspGraph.addAdjacencyEdge("A", "H", "17", 17.0);
    tspGraph.addAdjacencyEdge("G", "H", "1", 1.0);
    tspGraph.addAdjacencyEdge("G", "A", "1", 1.0);
    tspGraph.addAdjacencyEdge("E", "D", "20", 20.0);
    tspGraph.addAdjacencyEdge("C", "D", "2 and a half", 2.5);
    tspGraph.addAdjacencyEdge("C", "B", "3", 3.0);
    tspGraph.addAdjacencyEdge("D", "B", "4", 4.0);

    if (tspGraph.tsp() != null) {
      System.out.println("Test 10.9 Failed");
    }

    System.out.print("Test 10 END");

    System.out.println(" | Test 11 START: Union Find");

    UnionFind uf = new UnionFind(10);

    if (uf.find(9, 4)) {
      System.out.println("Test 11.1 Fail");
    }

    uf.union(1, 2);
    if (uf.getParent()[1] != 2) {
      System.out.println("Test 11.2 Fail");
    }
    if (uf.getParent()[2] != uf.ROOT) {
      System.out.println("Test 11.3 Fail");
    }

    uf.union(3, 2);
    if (!uf.find(3, 2)) {
      System.out.println("Test 11.4 Fail");
    }
    if (uf.find(3, 7)) {
      System.out.println("Test 11.5 Fail");
    }
    if (uf.find(7, 3)) {
      System.out.println("Test 11.6 Fail");
    }
    uf.union(5, 4);
    if (!uf.find(5, 4)) {
      System.out.println("Test 11.7 Fail");
    }
    if (uf.find(3, 4)) {
      System.out.println("Test 11.8 Fail");
    }
    if (uf.find(5, 7)) {
      System.out.println("Test 11.9 Fail");
    }
    uf.union(3, 4);
    if (!uf.find(3, 4)) {
      System.out.println("Test 11.10 Fail");
    }
    uf.union(4, 1);
    if (!uf.find(4, 3)) {
      System.out.println("Test 11.11 Fail");
    }
    uf.union(7, 6);
    uf.union(8, 9);
    uf.union(8, 7);
    if (uf.find(7, 2)) {
      System.out.println("Test 11.12 Fail");
    }
    uf.union(8, 4);
    if (!uf.find(7, 2)) {
      System.out.println("Test 11.13 Fail");
    }
    if (uf.find(7, 10)) {
      System.out.println("Test 11.12 Fail");
    }
    System.out.print("Test 11 END");

    System.out.println(" | Test 12 START: mst");

    Graph mstGraph = new Graph();

    // generating a complete graph
    mstGraph.generateCompleteGraph(0);
    if (mstGraph.getNodes().size() != 0) {
      System.out.println("Test12.1.1 Fail");
    }
    if (mstGraph.getEdges().size() != 0) {
      System.out.println("Test12.1.2 Fail");
    }

    mstGraph.generateCompleteGraph(1);
    if (mstGraph.getNodes().size() != 1) {
      System.out.println("Test12.1.3 Fail");
    }
    if (mstGraph.getEdges().size() != 0) {
      System.out.println("Test12.1.4 Fail");
    }

    if (!mstGraph.consistent()) {
      System.out.println("Test 12.1.4.0 Fail");
    }

    mstGraph.generateCompleteGraph(5);
    if (mstGraph.getNodes().size() != 5) {
      System.out.println("Test12.1.5 Fail");
    }
    if (mstGraph.getEdges().size() != 10) {
      System.out.println("Test12.1.6 Fail");
    }

    mstGraph.generateCompleteGraph(8);
    if (mstGraph.getNodes().size() != 8) {
      System.out.println("Test12.1.7 Fail");
    }
    if (mstGraph.getEdges().size() != 28) {
      System.out.println("Test12.1.8 Fail");
    }

    mstGraph.setEdgesWeights(1.0);
    if (mstGraph.sumEdgeWeights(mstGraph.prim()) != 7) {
      System.out.println("Test12.2.1 Fail");
    }
    if (mstGraph.sumEdgeWeights(mstGraph.kruskal()) != 7) {
      System.out.println("Test12.2.2 Fail");
    }

    mstGraph.clear();

    ArrayList<Edge> mstCompare = new ArrayList<Edge>();

    if (!mstCompare.equals(mstGraph.prim())) {
      System.out.println("Test12.2.3 Fail");
    }
    if (!mstCompare.equals(mstGraph.kruskal())) {
      System.out.println("Test12.2.4 Fail");
    }

    Node mstN1 = new Node("A");
    Node mstN2 = new Node("B");
    Node mstN3 = new Node("C");

    mstGraph.addNode(mstN1);

    if (!mstCompare.equals(mstGraph.prim())) {
      System.out.println("Test12.2.5 Fail");
    }
    if (!mstCompare.equals(mstGraph.kruskal())) {
      System.out.println("Test12.2.6 Fail");
    }

    mstGraph.addNode(mstN2);

    if (mstGraph.prim() != null) {
      System.out.println("Test12.2.7 Fail");
    }
    if (mstGraph.kruskal() != null) {
      System.out.println("Test12.2.8 Fail");
    }

    Edge mstE1 = new Edge(mstN1, mstN2, "A", 1);

    mstGraph.addEdge(mstE1);

    mstCompare.add(mstE1);
    if (!mstCompare.equals(mstGraph.prim())) {
      System.out.println("Test12.2.9 Fail");
    }
    if (!mstCompare.equals(mstGraph.kruskal())) {
      System.out.println("Test12.2.10 Fail");
    }

    mstGraph.addNode(mstN3);
    Edge mstE2 = new Edge(mstN2, mstN3, "B", 5);
    Edge mstE3 = new Edge(mstN3, mstN1, "C", 2);
    Edge mstE4 = new Edge(mstN2, mstN2, "D", 1);

    mstGraph.addEdge(mstE2);
    mstGraph.addEdge(mstE3);
    mstGraph.addEdge(mstE4);

    mstCompare.add(mstE3);

    if (mstGraph.sumEdgeWeights(mstGraph.prim()) != 3) {
      System.out.println("Test12.2.11 Fail");
    }
    if (mstGraph.sumEdgeWeights(mstGraph.kruskal()) != 3) {
      System.out.println("Test12.2.12 Fail");
    }

    // generated graph test - randomly generate graphs of size
    // 1-10 nodes, edges 4-14, and compare prim against kruskal
    // on test fail, the graph should be printed for reference.
    for (int i = 1; i <= 10; i++) {

      mstGraph.generateRandomGraph(i, i + 3);
      mstGraph.randomlyWeightGraph(0, 100);

      ArrayList<Edge> prim = mstGraph.prim();
      double primSum = 0;
      if (prim != null) {
        primSum = mstGraph.sumEdgeWeights(prim);
      }
      ArrayList<Edge> kruskal = mstGraph.kruskal();
      double kruskalSum = 0;
      if (kruskal != null) {
        kruskalSum = mstGraph.sumEdgeWeights(kruskal);
      }

      if (primSum != kruskalSum) {
        System.out.println("Test 12.3." + i + " Failed - mst sums not equal");
        System.out.println("Randomly Generated Graph");
        System.out.println(mstGraph);
      }

      if (!mstGraph.consistent()) {
        System.out.println("Test 12.3." + i + ".0 Failed - graph consistency check failed");
        System.out.println("Randomly Generated Graph");
        System.out.println(mstGraph);
      }
    }

    System.out.print("Test 12 END");

    // test the types
    System.out.println(" | Test 13 START: Node and Edge Types");

    NodeType nt11 = new NodeType("nt11");
    NodeType nt21 = new NodeType("nt21");
    NodeType nt31 = new NodeType("nt31");
    NodeType nt22 = new NodeType("nt22");
    NodeType nt32 = new NodeType("nt32");
    NodeType nt33 = new NodeType("nt33");
    NodeType nt34 = new NodeType("nt34");
    NodeType nt23 = new NodeType("nt23");
    NodeType nt41 = new NodeType("nt41");
    NodeType nt42 = new NodeType("nt42");
    NodeType nt43 = new NodeType("nt43");
    nt21.setParent(nt11);
    nt31.setParent(nt21);
    nt22.setParent(nt11);
    nt32.setParent(nt21);
    nt33.setParent(nt22);
    nt34.setParent(nt21);
    nt23.setParent(nt11);
    nt41.setParent(nt32);
    nt42.setParent(nt32);
    nt43.setParent(nt32);

    nt22.removeParent();
    NodeType ntmove = (NodeType) nt33.getParent();
    nt32.setParent(ntmove);

    if (nt11.setParent(nt31)) {
      System.out.println("Test 13.3.1 FAIL");
    }
    if (!nt11.setParent(nt43)) {
      System.out.println("Test 13.3.2 FAIL");
    }

    if (nt43.setParent(nt43)) {
      System.out.println("Test 13.3.3 FAIL");
    }

    if (nt43.setParent(nt43)) {
      System.out.println("Test 13.3.4 FAIL");
    }

    if (!nt43.ancestor(nt32)) {
      System.out.println("Test 13.3.5 FAIL");
    }
    if (nt41.ancestor(nt41)) {
      System.out.println("Test 13.3.6 FAIL");
    }
    if (!nt33.ancestor(nt22)) {
      System.out.println("Test 13.3.7 FAIL");
    }
    if (nt41.ancestor(nt42)) {
      System.out.println("Test 13.3.8 FAIL");
    }

    if (nt41.root() != nt22) {
      System.out.println("Test 13.3.9 FAIL");
    }
    if (nt22.root() != nt22) {
      System.out.println("Test 13.3.10 FAIL");
    }

    EdgeType et11 = new EdgeType("et11");
    EdgeType et21 = new EdgeType("et21");
    EdgeType et22 = new EdgeType("et22");
    EdgeType et31 = new EdgeType("et31");
    et21.setParent(et11);
    et31.setParent(et22);
    et22.setParent(et11);
    et21.setDirected(true);

    if (!et31.ancestor(et11)) {
      System.out.println("Test 13.4.1 FAIL");
    }
    if (et11.ancestor(et21)) {
      System.out.println("Test 13.4.2 FAIL");
    }
    if (et21.root() != et11) {
      System.out.println("Test 13.4.3 FAIL");
    }
    if (et11.root() != et11) {
      System.out.println("Test 13.4.4 FAIL");
    }

    Node nt1 = new Node("nt1", new Point(100, 100));
    Node nt2 = new Node("nt2", nt32, new Point(110, 100));
    Node nt3 = new Node("nt3", nt11, new Point(200, 200));

    Edge et1 = new Edge(nt1, nt2, "e1", 3.0, et11);
    Edge et2 = new Edge(nt2, nt3, "e2");
    Edge et3 = new Edge(nt1, nt3, "e3", 0.0, et31);

    Graph gt = new Graph("gt1");

    gt.addNode(nt1);
    gt.addNode(nt2);
    gt.addNode(nt3);
    gt.addEdge(et1);
    gt.addEdge(et2);
    gt.addEdge(et3);

    if (nt1.getType() != Graph.DEFAULT_NODE_TYPE) {
      System.out.println("Test 13.5.1 FAIL");
    }

    if (nt2.getType() != nt32) {
      System.out.println("Test 13.5.2 FAIL");
    }

    nt2.setType(nt41);

    if (nt2.getType() != nt41) {
      System.out.println("Test 13.5.3 FAIL");
    }

    if (et2.getType() != Graph.DEFAULT_EDGE_TYPE) {
      System.out.println("Test 13.5.4 FAIL");
    }

    if (et3.getType() != et31) {
      System.out.println("Test 13.5.5 FAIL");
    }

    et3.setType(Graph.DEFAULT_EDGE_TYPE);

    if (et3.getType() != Graph.DEFAULT_EDGE_TYPE) {
      System.out.println("Test 13.5.7 FAIL");
    }

    if (Graph.DEFAULT_EDGE_TYPE.root() != Graph.DEFAULT_EDGE_TYPE) {
      System.out.println("Test 13.5.8 FAIL");
    }

    System.out.println("Test 13 END");

    System.out.println("End Graph Tests");
  }