Package com.google.test.metric

Examples of com.google.test.metric.MethodCost


    assertEquals(0, methodCost.getTotalCost().getGlobalCost());
    assertEquals(0, methodCost.getTotalCost().getCyclomaticComplexityCost());
  }

  public void testStaticTcc4Cost() throws Exception {
    MethodCost methodCost = cost("void methodStaticTcc4()");
    assertEquals(4, methodCost.getCost().getCyclomaticComplexityCost());
    assertEquals(0, methodCost.getCost().getGlobalCost());
    assertEquals(0, methodCost.getTotalCost().getGlobalCost());
    assertEquals(4, methodCost.getTotalCost().getCyclomaticComplexityCost());

    methodCost = cost("void methodTcc4BecauseStaticMethodCalls()");
    assertEquals(0, methodCost.getCost().getCyclomaticComplexityCost());
    assertEquals(0, methodCost.getCost().getGlobalCost());
    assertEquals(0, methodCost.getTotalCost().getGlobalCost());
    // TCC 4 because it doesn't double count for the same offense within one method
    assertEquals(4, methodCost.getTotalCost().getCyclomaticComplexityCost());
  }
View Full Code Here


  private void print(String prefix, ViolationCost line, int maxDepth,
      Set<String> alreadSeen) {
    if (!(line instanceof MethodInvocationCost)) {
      return;
    }
    MethodCost method = ((MethodInvocationCost) line).getMethodCost();
    if (shouldPrint(method, maxDepth, alreadSeen)) {
      out.print(prefix);
      out.print("line ");
      out.print(line.getLocation());
      out.print(": ");
      out.print(method);
      out.println(" " + line.getReason());
      for (ViolationCost child : method.getViolationCosts()) {
        print("  " + prefix, child, maxDepth - 1, alreadSeen);
      }
    }
  }
View Full Code Here

import junit.framework.TestCase;

public class MethodCostTest extends TestCase {

  public void testComputeOverallCost() throws Exception {
    MethodCost cost = new MethodCost("", "a", 0, false, false, false);
    cost.addCostSource(new CyclomaticCost(new SourceLocation(null, 0), Cost.cyclomatic(1)));
    cost.addCostSource(new GlobalCost(new SourceLocation(null, 0), null, Cost.global(1)));
    MethodCost cost3 = new MethodCost("", "b", 0, false, false, false);
    cost3.addCostSource(new CyclomaticCost(new SourceLocation(null, 0), Cost.cyclomatic(1)));
    cost3.addCostSource(new CyclomaticCost(new SourceLocation(null, 0), Cost.cyclomatic(1)));
    cost3.addCostSource(new CyclomaticCost(new SourceLocation(null, 0), Cost.cyclomatic(1)));
    cost.addCostSource(new MethodInvocationCost(new SourceLocation(null, 0), cost3,
        IMPLICIT_STATIC_INIT, Cost.cyclomatic(3)));
    CostModel costModel = new CostModel(2, 10, 1);
    cost.link();
View Full Code Here

  }

  public void testImplicitSetterCostShouldNotBeDoubleCounted() throws Exception {
    MetricComputer computer = new MetricComputer(new JavaClassRepository(), null, new RegExpWhiteList(), 1);
    ClassCost cost = computer.compute(Setters.class.getCanonicalName());
    MethodCost cost1 = cost.getMethodCost("void setFoo(java.lang.String)");
    assertEquals(1, cost1.getTotalCost().getCyclomaticComplexityCost());
  }
View Full Code Here

        "getGlobalId()Ljava/lang/String;");
    assertEquals(0, cost.getTotalGlobalCost());
  }

  public void testAccessingANonFinalFieldCountsAgainstYou() throws Exception {
    MethodCost cost = cost(GlobalExample.class, "getGlobalCount()I");
    assertEquals(1, cost.getTotalGlobalCost());
  }
View Full Code Here

    MethodCost cost = cost(GlobalExample.class, "getGlobalCount()I");
    assertEquals(1, cost.getTotalGlobalCost());
  }

  public void testWritingANonFinalFieldCountsAgainstYou() throws Exception {
    MethodCost cost = cost(GlobalExample.class, "globalIncrement()I");
    assertEquals(1, cost.getTotalGlobalCost());
  }
View Full Code Here

    assertEquals(buf.toString(), out.toString());
  }

  private ClassCost classCost(String name, int cost) {
    List<MethodCost> methods = new ArrayList<MethodCost>();
    methods.add(new MethodCost("method_" + cost, 1, cost));
    ClassCost classCost = new ClassCost(name, methods);
    classCost.link(new CostModel(1, 1));
    return classCost;
  }
View Full Code Here

import junit.framework.TestCase;

public class MethodCostTest extends TestCase {

  public void testComputeOverallCost() throws Exception {
    MethodCost cost = new MethodCost("a", 0, 1);
    cost.addGlobalCost(0, null);
    cost.addMethodCost(0, new MethodCost("b", 0, 3));
    CostModel context = new CostModel(2, 10);
    cost.link(context);

    assertEquals((long) 2 * (3 + 1) + 10 * 1, cost.getOverallCost());
  }
View Full Code Here

  private final CostModel context = new CostModel();

  public void testSimpleCost() throws Exception {
    DrillDownReport printer =
      new DrillDownReport(new PrintStream(out), null, MAX_VALUE, 0);
    MethodCost costOnlyMethod1 = new MethodCost("c.g.t.A.method1()V", 0, 1);
    costOnlyMethod1.addGlobalCost(0, null);
    costOnlyMethod1.link(context);
    printer.print("", costOnlyMethod1, Integer.MAX_VALUE);
    assertStringEquals("c.g.t.A.method1()V [1, 1 / 1, 1]\n", out.toString());
  }
View Full Code Here

  private MethodCost cost(Class<?> clazz, String method) {
    return computer.compute(clazz, method);
  }

  public void testAccessingAFinalStaticIsOK() throws Exception {
    MethodCost cost = cost(GlobalExample.class,
        "getInstance()Lcom/google/test/metric/example/GlobalExample$Gadget;");
    assertEquals(0, cost.getTotalGlobalCost());
  }
View Full Code Here

TOP

Related Classes of com.google.test.metric.MethodCost

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.