Exemple #1
0
  /** Verifies any checkcases provided in XML file. */
  public boolean verify() {
    boolean result = true;
    int goodCases = 0;

    if (checkcases == null) { // no checkcases
      return true;
    }

    // run the model with each checkcase
    ArrayList<StaticShot> shots = checkcases.getStaticShots();
    Iterator<StaticShot> shit = shots.iterator();

    if (this.isVerbose()) {
      System.out.println("");
      System.out.println("Verifying " + shots.size() + " check-cases");
      System.out.println("------------------------");
      System.out.println("");
    }

    while (shit.hasNext()) {
      StaticShot shot = shit.next();
      if (this.isVerbose()) {
        System.out.println("");
        System.out.println("Verifying staticShot '" + shot.getName() + "'");
        System.out.println("");
      }
      try {
        VectorInfoArrayList inputVec = m.getInputVector();
        shot.loadInputVector(inputVec); // throws DAVEException if problem

        m.cycle(); // run model with inputs

        VectorInfoArrayList outputVec = m.getOutputVector();
        if (outputVec == null) {
          System.err.println("Null output vector returned from Model.cycle() while verifying.");
          System.exit(exit_failure);
        }
        boolean matched = shot.checkOutputs(outputVec);
        if (!matched) {
          System.err.println("Verification error - can't match case '" + shot.getName() + "'.");
          result = false;
        } else {
          goodCases++;
        }
        if (matched || this.ignoreCheckcases) {
          if (this.createInternalValues) {
            // write internal values to file
            String checkCaseName = this.stubName + "_" + toFileName(shot.getName()) + ".txt";
            FileOutputStream fos = new FileOutputStream(checkCaseName);
            PrintWriter pw = new PrintWriter(fos);
            m.generateInternalValues(pw);
            pw.flush();
            fos.close();
          }
        }

      } catch (Exception e) {
        System.err.println("Problem performing verification - ");
        System.err.println(e.getMessage());
        System.exit(exit_failure);
      }
    }
    System.out.println("Verified " + goodCases + " of " + shots.size() + " embedded checkcases.");
    if (this.createInternalValues) {
      if (!this.ignoreCheckcases) {
        System.out.println("Wrote internal values for each good checkcase.");
      } else {
        System.out.println("Wrote internal values for each checkcase.");
      }
    }
    return result;
  }