Package com.google.test.metric

Examples of com.google.test.metric.ClassCost


    assertEquals(2, classCost.getTotalGlobalCost());
  }

  public void testMutableGlobalExampleTotalClassCosts() {
    // This class uses a class which has a static mutable instance.
    ClassCost classCost = decoratedComputer.compute(MutableGlobalExample.class);
    assertEquals(0, classCost.getHighestMethodComplexityCost());
    assertEquals(2, classCost.getHighestMethodGlobalCost());
    assertEquals(0, classCost.getTotalComplexityCost());

    /* There are three instance methods which access expensive (mutable) global state:
     * 1) Gadget#getGlobalId() - cost of 1
     * 2) Gadget#getGlobalCount() - cost of 2
     * 3) Gadget#globalIncrement() - cost of 2
     * The class' total global cost is 5.
     *
     * Note that the only other method is the constructor, which has zero global state cost, and
     * zero complexity cost.
     */
    assertEquals(5, classCost.getTotalGlobalCost());
  }
View Full Code Here


    MetricComputer toDecorate = new MetricComputerBuilder().withClassRepository(repo).build();
    decoratedComputer = new MetricComputerJavaDecorator(toDecorate, repo);
  }

  public void testCostToConstructClassCost() throws Exception {
    ClassCost classCost = decoratedComputer.compute(Cost2ToConstruct.class);
    assertEquals(2, classCost.getHighestMethodComplexityCost());
    assertEquals(0, classCost.getHighestMethodGlobalCost());
    assertEquals(0, classCost.getTotalGlobalCost());
    assertEquals(2, classCost.getTotalComplexityCost());
  }
View Full Code Here

    assertEquals(0, classCost.getTotalGlobalCost());
    assertEquals(2, classCost.getTotalComplexityCost());
  }

  public void testStaticWorkInTheConstructorClassCost() throws Exception {
    ClassCost classCost = decoratedComputer.compute(StaticWorkInTheConstructor.class);
    assertEquals(2, classCost.getHighestMethodComplexityCost());
    assertEquals(0, classCost.getHighestMethodGlobalCost());
    assertEquals(0, classCost.getTotalGlobalCost());
    assertEquals(2, classCost.getTotalComplexityCost());
  }
View Full Code Here

    assertEquals(0, classCost.getTotalGlobalCost());
    assertEquals(2, classCost.getTotalComplexityCost());
  }

  public void testObjectInstantiationWorkInTheConstructorClassCost() throws Exception {
    ClassCost classCost = decoratedComputer.compute(ObjectInstantiationWorkInTheConstructor.class);
    assertEquals(2, classCost.getHighestMethodComplexityCost());
    assertEquals(0, classCost.getHighestMethodGlobalCost());
    assertEquals(0, classCost.getTotalGlobalCost());
    assertEquals(2, classCost.getTotalComplexityCost());
  }
View Full Code Here

    assertEquals(1, getCount.getOperations().size());
  }

  public void testGadgetTotalClassCosts() {
    // This class has no cost, because there are no global references or cyclomatic complexity.
    ClassCost classCost = decoratedComputer.compute(Gadget.class);
    assertEquals(0, classCost.getHighestMethodComplexityCost());
    assertEquals(0, classCost.getHighestMethodGlobalCost());
    assertEquals(0, classCost.getTotalComplexityCost());
    assertEquals(0, classCost.getTotalGlobalCost());
  }
View Full Code Here

    assertEquals(0, classCost.getTotalGlobalCost());
  }

  public void testFinalGlobalTotalClassCosts() {
    // This class has static (global) state, but has no cost.
    ClassCost classCost = decoratedComputer.compute(FinalGlobal.class);
    assertEquals(0, classCost.getHighestMethodComplexityCost());
    assertEquals(0, classCost.getHighestMethodGlobalCost());
    assertEquals(0, classCost.getTotalComplexityCost());
    assertEquals(0, classCost.getTotalGlobalCost());
    // Note to the reader: This is interesting. This class does the harm,
    // exposing the mutable global state. He himself is easy to test, though.
    // (Low cyclomatic complexity, and no external global state is accessed).
    // It is only when others start to use him does he become a problem.
View Full Code Here

    // in him.
  }

  public void testFinalGlobalExampleTotalClassCosts() {
    // This class has methods which access both mutable and non-mutable global state.
    ClassCost classCost = decoratedComputer.compute(FinalGlobalExample.class);
    assertEquals(0, classCost.getHighestMethodComplexityCost());
    assertEquals(1, classCost.getHighestMethodGlobalCost());
    assertEquals(0, classCost.getTotalComplexityCost());

    /* There are two instance methods which access expensive (mutable) global state:
     * 1) Gadget#getGlobalCount()
     * 2) Gadget#globalIncrement()
     * Each has a global state cost of 1, so the class' total global cost is 2.
     *
     * Note that the other methods Gadget#getInstance() and Gadget#getGlobalId() do not have a
     * global state cost. Why? Because while they access global state, it is <em>final</em>
     * global state. This is non-mutable, and it does not count against you.
     */
    assertEquals(2, classCost.getTotalGlobalCost());
  }
View Full Code Here

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

  public void testClassCost() throws Exception {
    ClassCost classCost = decoratedComputer.compute(MultipleMethodsDifferentCosts.class);
    assertEquals(12, classCost.getHighestMethodComplexityCost());
    assertEquals(0, classCost.getHighestMethodGlobalCost());
    // overall cost is a mysterious numbers that is calculated with a weighted average formula
    float weight = 1.5f;
    long expectedOverallCost = (long)
        ((Math.pow(4, weight + 1) * 7 + Math.pow(12, weight + 1))
          /
        (Math.pow(4, weight) * 7 + Math.pow(12, weight)));
    assertEquals(7, expectedOverallCost);
    assertEquals(4*7 + 12, classCost.getTotalComplexityCost());
    assertEquals(0, classCost.getTotalGlobalCost());
  }
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

  }

  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

TOP

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

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.