Package com.google.gwt.junit.viewer.client

Examples of com.google.gwt.junit.viewer.client.Trial


    for (int i = 0; i < comparativeResults.size(); ++i) {
      Result r = (Result) comparativeResults.get(i);
      List resultTrials = r.getTrials();

      for (int j = 0; j < resultTrials.size(); ++j) {
        Trial t = (Trial) resultTrials.get(j);
        maxTime = Math.max(maxTime, t.getRunTimeMillis());
      }
    }

    // Determine the number of variables in this benchmark method
    List trials = result.getTrials();
    Trial firstTrial = (Trial) trials.get(0);
    int numVariables = firstTrial.getVariables().size();

    // Display the trial data.
    //
    // First, pick the domain and series variables for our graph.
    // Right now we only handle up to two "user" variables.
    // We set the domain variable to the be the one containing the most unique
    // values.
    // This might be easier if the results had meta information telling us
    // how many total variables there are, what types they are of, etc....

    String domainVariable = null;
    String seriesVariable = null;

    Map/* <String,Set<String>> */variableValues = null;

    if (numVariables == 1) {
      domainVariable = (String) firstTrial.getVariables().keySet().iterator().next();
    } else {
      // TODO(tobyr): Do something smarter, like allow the user to specify which
      // variables are domain and series, along with the variables which are
      // held constant.

      variableValues = new HashMap();

      for (int i = 0; i < trials.size(); ++i) {
        Trial trial = (Trial) trials.get(i);
        Map variables = trial.getVariables();

        for (Iterator it = variables.entrySet().iterator(); it.hasNext();) {
          Map.Entry entry = (Map.Entry) it.next();
          String variable = (String) entry.getKey();
          String value = (String) entry.getValue();
          Set set = (Set) variableValues.get(variable);
          if (set == null) {
            set = new TreeSet();
            variableValues.put(variable, set);
          }
          set.add(value);
        }
      }

      TreeMap numValuesMap = new TreeMap();

      for (Iterator it = variableValues.entrySet().iterator(); it.hasNext();) {
        Map.Entry entry = (Map.Entry) it.next();
        String variable = (String) entry.getKey();
        Set values = (Set) entry.getValue();
        Integer numValues = new Integer(values.size());
        List variables = (List) numValuesMap.get(numValues);
        if (variables == null) {
          variables = new ArrayList();
          numValuesMap.put(numValues, variables);
        }
        variables.add(variable);
      }

      if (numValuesMap.values().size() > 0) {
        domainVariable = (String) ((List) numValuesMap.get(numValuesMap.lastKey())).get(0);
        seriesVariable = (String) ((List) numValuesMap.get(numValuesMap.firstKey())).get(0);
      }
    }

    String valueTitle = "time (ms)"; // This axis is time across all charts.

    if (numVariables == 0) {
      // Show a bar graph, with a single centered simple bar
      // 0 variables means there is only 1 trial
      Trial trial = (Trial) trials.iterator().next();

      DefaultCategoryDataset data = new DefaultCategoryDataset();
      data.addValue(trial.getRunTimeMillis(), "result", "result");

      JFreeChart chart = ChartFactory.createBarChart(title, testName,
          valueTitle, data, PlotOrientation.VERTICAL, false, false, false);
      CategoryPlot p = chart.getCategoryPlot();
      ValueAxis axis = p.getRangeAxis();
      axis.setUpperBound(maxTime + maxTime * 0.1);
      return chart;
    } else if (numVariables == 1) {

      // Show a line graph with only 1 series
      // Or.... choose between a line graph and a bar graph depending upon
      // whether the type of the domain is numeric.

      XYSeriesCollection data = new XYSeriesCollection();

      XYSeries series = new XYSeries(domainVariable);

      for (Iterator it = trials.iterator(); it.hasNext();) {
        Trial trial = (Trial) it.next();
        if (trial.getException() != null) {
          continue;
        }
        double time = trial.getRunTimeMillis();
        String domainValue = (String) trial.getVariables().get(domainVariable);
        series.add(Double.parseDouble(domainValue), time);
      }

      data.addSeries(series);

      JFreeChart chart = ChartFactory.createXYLineChart(title, domainVariable,
          valueTitle, data, PlotOrientation.VERTICAL, false, false, false);
      XYPlot plot = chart.getXYPlot();
      plot.getRangeAxis().setUpperBound(maxTime + maxTime * 0.1);
      double maxDomainValue = getMaxValue(comparativeResults, domainVariable);
      plot.getDomainAxis().setUpperBound(maxDomainValue + maxDomainValue * 0.1);
      return chart;
    } else if (numVariables == 2) {
      // Show a line graph with two series
      XYSeriesCollection data = new XYSeriesCollection();

      Set seriesValues = (Set) variableValues.get(seriesVariable);

      for (Iterator it = seriesValues.iterator(); it.hasNext();) {
        String seriesValue = (String) it.next();
        XYSeries series = new XYSeries(seriesValue);

        for (Iterator trialsIt = trials.iterator(); trialsIt.hasNext();) {
          Trial trial = (Trial) trialsIt.next();
          if (trial.getException() != null) {
            continue;
          }
          Map variables = trial.getVariables();
          if (variables.get(seriesVariable).equals(seriesValue)) {
            double time = trial.getRunTimeMillis();
            String domainValue = (String) trial.getVariables().get(
                domainVariable);
            series.add(Double.parseDouble(domainValue), time);
          }
        }
        data.addSeries(series);
View Full Code Here


    for (int i = 0; i < results.size(); ++i) {
      Result r = (Result) results.get(i);
      List resultTrials = r.getTrials();

      for (int j = 0; j < resultTrials.size(); ++j) {
        Trial t = (Trial) resultTrials.get(j);
        Map variables = t.getVariables();
        value = Math.max(value,
            Double.parseDouble((String) variables.get(variable)));
      }
    }
View Full Code Here

    // Display the trial data - we might need meta information from the result
    // that tells us how many total variables there are, what types they are of,
    // etc....
    List trials = result.getTrials();
    Trial firstTrial = (Trial) trials.get(0);

    // Pick the domain and series variables for our graph.
    // Right now we only handle up to two "user" variables.
    // We set the domain variable to the be the one containing the most unique
    // values.
    int numVariables = firstTrial.getVariables().size();

    String domainVariable = null;
    String seriesVariable = null;

    Map/* <String,Set<String>> */variableValues = null;

    if (numVariables == 1) {
      domainVariable = (String) firstTrial.getVariables().keySet().iterator().next();
    } else {
      // TODO(tobyr): Do something smarter, like allow the user to specify which
      // variables
      // are domain and series, along with the variables which are held
      // constant.

      variableValues = new HashMap();

      for (int i = 0; i < trials.size(); ++i) {
        Trial trial = (Trial) trials.get(i);
        Map variables = trial.getVariables();

        for (Iterator it = variables.entrySet().iterator(); it.hasNext();) {
          Map.Entry entry = (Map.Entry) it.next();
          String variable = (String) entry.getKey();
          String value = (String) entry.getValue();
          Set set = (Set) variableValues.get(variable);
          if (set == null) {
            set = new TreeSet();
            variableValues.put(variable, set);
          }
          set.add(value);
        }
      }

      TreeMap numValuesMap = new TreeMap();

      for (Iterator it = variableValues.entrySet().iterator(); it.hasNext();) {
        Map.Entry entry = (Map.Entry) it.next();
        String variable = (String) entry.getKey();
        Set values = (Set) entry.getValue();
        Integer numValues = new Integer(values.size());
        List variables = (List) numValuesMap.get(numValues);
        if (variables == null) {
          variables = new ArrayList();
          numValuesMap.put(numValues, variables);
        }
        variables.add(variable);
      }

      if (numValuesMap.values().size() > 0) {
        domainVariable = (String) ((List) numValuesMap.get(numValuesMap.lastKey())).get(0);
        seriesVariable = (String) ((List) numValuesMap.get(numValuesMap.firstKey())).get(0);
      }
    }

    String valueTitle = "time (ms)"; // This axis is time across all charts.

    if (numVariables == 0) {
      // Show a bar graph, with a single centered simple bar
      // 0 variables means there is only 1 trial
      Trial trial = (Trial) trials.iterator().next();

      DefaultCategoryDataset data = new DefaultCategoryDataset();
      data.addValue(trial.getRunTimeMillis(), "result", "result");

      return ChartFactory.createBarChart(title, testName, valueTitle, data,
          PlotOrientation.VERTICAL, false, false, false);
    } else if (numVariables == 1) {

      // Show a line graph with only 1 series
      // Or.... choose between a line graph and a bar graph depending upon
      // whether the
      // type of the domain is numeric.

      XYSeriesCollection data = new XYSeriesCollection();

      XYSeries series = new XYSeries(domainVariable);

      for (Iterator it = trials.iterator(); it.hasNext();) {
        Trial trial = (Trial) it.next();
        if (trial.getException() != null) {
          continue;
        }
        double time = trial.getRunTimeMillis();
        String domainValue = (String) trial.getVariables().get(domainVariable);
        series.add(Double.parseDouble(domainValue), time);
      }

      data.addSeries(series);

      return ChartFactory.createXYLineChart(title, domainVariable, valueTitle,
          data, PlotOrientation.VERTICAL, false, false, false);
    } else if (numVariables == 2) {
      // Show a line graph with multiple series
      XYSeriesCollection data = new XYSeriesCollection();

      Set seriesValues = (Set) variableValues.get(seriesVariable);

      for (Iterator it = seriesValues.iterator(); it.hasNext();) {
        String seriesValue = (String) it.next();
        XYSeries series = new XYSeries(seriesValue);

        for (Iterator trialsIt = trials.iterator(); trialsIt.hasNext();) {
          Trial trial = (Trial) trialsIt.next();
          if (trial.getException() != null) {
            continue;
          }
          Map variables = trial.getVariables();
          if (variables.get(seriesVariable).equals(seriesValue)) {
            double time = trial.getRunTimeMillis();
            String domainValue = (String) trial.getVariables().get(
                domainVariable);
            series.add(Double.parseDouble(domainValue), time);
          }
        }
        data.addSeries(series);
View Full Code Here

*
*/
class TrialXml {

  public static Trial fromXml(Element element) {
    Trial trial = new Trial();

    String timing = element.getAttribute("timing");

    if (timing != null) {
      trial.setRunTimeMillis(Double.parseDouble(timing));
    }

    Element exception = ReportXml.getElementChild(element, "exception");
    if (exception != null) {
      trial.setException(ReportXml.getText(exception));
    }

    List elements = ReportXml.getElementChildren(element, "variable");

    Map variables = trial.getVariables();

    for (Iterator it = elements.iterator(); it.hasNext();) {
      Element e = (Element) it.next();
      String name = e.getAttribute("name");
      String value = e.getAttribute("value");
View Full Code Here

TOP

Related Classes of com.google.gwt.junit.viewer.client.Trial

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.