Package nz.ac.waikato.modeljunit.coverage

Examples of nz.ac.waikato.modeljunit.coverage.CoverageMetric


  public static void testResetHigh()
  {
    RandomTester tester = new RandomTester(new FSM());
    tester.buildGraph();
    tester.setResetProbability(0.9);
    CoverageMetric trCover = new TransitionCoverage();
    CoverageHistory hist = new CoverageHistory(trCover,1);
    tester.addListener(hist);
    tester.generate(40);
    // the random walk should choose reset almost all the time
    // so should not get much past the first transition.
    Assert.assertEquals(41, hist.getHistory().size());
    Assert.assertEquals(1, trCover.getCoverage());
  }
View Full Code Here


   */
  public static double allTransitions(Tester tester)
  {
    GraphListener graph = tester.buildGraph(100000);
    //tester.addListener(new VerboseListener()); //if you want to see the tests
    CoverageMetric trans = tester.addCoverageMetric(new TransitionCoverage());
    int total = 0;
    tester.setRandom(new Random(Tester.FIXEDSEED));
    for (int run=0; run<RUNS; run++) {
      int steps = 0;
      trans.clear();
      graph.clearDoneTodo();
      tester.reset();
      while (trans.getPercentage() < 100.0) {     
        tester.generate();
        steps++;
      }
      // Uncomment the next line if you want to see every experiment.
      //System.out.println("coverage = "+trans+" in "+steps+" steps");
View Full Code Here

    GraphListener graph = tester.buildGraph();
    model.setTimeoutProbability(origProb);
    graph.printGraphDot("SimpleTimedLight.dot");
    System.out.println("FSM has " + graph.getGraph().numVertices() + " states and "
        + graph.getGraph().numEdges() + " transitions");
    CoverageMetric metric = tester.addCoverageMetric(new TransitionCoverage());
    for (double prob = 0.1; prob < 0.99; prob += 0.1) {
      model.setTimeoutProbability(prob);
      double totalSteps = 0.0;
      int totalTime = 0; // sum of all the totalTimes.
      for (int seed = 0; seed < experiments; seed++) {
        int testSeqTime = 0;
        int lastTime = 0; // the time after the last transition
        metric.clear();
        tester.reset();
        tester.setRandom(new Random(seed));
        int count = 0;
        while (metric.getPercentage() < 100.0) {
          tester.generate(1);
          if (model.getTime() > lastTime) {
            lastTime = model.getTime();
          } else {
            testSeqTime += lastTime;
View Full Code Here

   * @param length  The number of test steps to do.
   * @param rand    The random number generator used to choose paths.
   */
  public void allRoundTrips(int length, Random rand)
  {
    CoverageMetric state = new StateCoverage();
    this.addCoverageMetric(state);
    int totalLength = 0;
    doReset("Initial", true);
    while (totalLength < length) {
      int taken = doGreedyRandomActionOrReset(rand, true);
      if (taken < 0) {
        System.out.println("reset state coverage");
        state.clear();
      }
      else {
        totalLength++;
        if (state.getDetails().get(getCurrentState()) > 1) {
          doReset("found loop", true);
          state.clear();
        }
      }
    }
    this.printProgress(1, "finished allRoundTrips of " + length
        + " transitions.");
View Full Code Here

    Tester tester = new RandomTester(new ECinema());
    // The guards make this a more difficult graph to explore, but we can
    // increase the default maximum search to complete the exploration.
    GraphListener graph = tester.buildGraph(100000);
    graph.printGraphDot("ecinema.dot");
    CoverageMetric trans = tester.addCoverageMetric(new TransitionCoverage());
    CoverageMetric trpairs = tester.addCoverageMetric(new TransitionPairCoverage());
    CoverageMetric states = tester.addCoverageMetric(new StateCoverage());
    CoverageMetric actions = tester.addCoverageMetric(new ActionCoverage());
    tester.addListener("verbose");
    // this illustrates how to generate tests upto a given level of coverage.
    int steps = 0;
    while (actions.getPercentage() < 100 /* || steps < 1000*/) {
      tester.generate();
      steps++;
    }
    System.out.println("Generated "+steps+" steps.");
    tester.printCoverage();
View Full Code Here

    // build the complete FSM graph for our model, just to ensure
    // that we get accurate model coverage metrics.
    tester.buildGraph();

    // set up our favourite coverage metric
    CoverageMetric trCoverage = new TransitionCoverage();
    tester.addListener(trCoverage);

    // ask to print the generated tests
    tester.addListener("verbose");

    // generate a small test suite of 20 steps (covers 4/5 transitions)
    tester.generate(20);

    tester.getModel().printMessage(trCoverage.getName() + " was "
        + trCoverage.toString());
  }
View Full Code Here

    //tester.addListener(new VerboseListener());
    //tester.addListener(new VerboseListener());
    GraphListener graph = tester.buildGraph();
    System.out.println("FSM has " + graph.getGraph().numVertices() + " states and "
        + graph.getGraph().numEdges() + " transitions");
    CoverageMetric metric = tester.addCoverageMetric(new TransitionCoverage());
    for (double prob = 0.1; prob < 0.99; prob += 0.1) {
      double totalSteps = 0.0;
      int totalTime = 0; // sum of all the totalTimes.
      for (int seed = 0; seed < experiments; seed++) {
        int testSeqTime = 0;
        int lastTime = 0; // the time after the last transition
        metric.clear();
        tester.reset();
        tester.setRandom(new Random(seed));
        int count = 0;
        while (metric.getPercentage() < 100.0) {
          tester.generate(1);
          if (fsm.time > lastTime) {
            lastTime = fsm.time;
          } else {
            testSeqTime += lastTime;
View Full Code Here

        return new Model(TestExeModel.createNewModelInstance(project));
    }

    private void setMaximumCoverage(Project project) {
        GreedyTester tester = new GreedyTester(loadModelClass(project));
        CoverageMetric metric = new TransitionCoverage();
        tester.addCoverageMetric(metric);
        int i = 1;
        while (metric.getMaximum() == -1) {
            tester.generate(i);
            i++;
        }
        mMaximum = metric.getMaximum();
    }
View Full Code Here

    // build the complete FSM graph for our model, just to ensure
    // that we get accurate model coverage metrics.
    tester.buildGraph();

    // set up our favourite coverage metric
    CoverageMetric trCoverage = new TransitionCoverage();
    tester.addListener(trCoverage);

    // ask to print the generated tests
    tester.addListener("verbose");

    // generate a small test suite of 20 steps (covers 4/5 transitions)
    tester.generate(100);

    tester.getModel().printMessage(trCoverage.getName() + " was "
        + trCoverage.toString());
  }
View Full Code Here

    // build the complete FSM graph for our model, just to ensure
    // that we get accurate model coverage metrics.
    tester.buildGraph();

    // set up our favourite coverage metric
    CoverageMetric trCoverage = new TransitionCoverage();
    tester.addListener(trCoverage);

    // ask to print the generated tests
    tester.addListener("verbose");

    // generate a small test suite of 20 steps (covers 4/5 transitions)
    tester.generate(100);

    tester.getModel().printMessage(trCoverage.getName() + " was "
        + trCoverage.toString());
  }
View Full Code Here

TOP

Related Classes of nz.ac.waikato.modeljunit.coverage.CoverageMetric

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.