PatternSizeWeightFunction implements ViolationWeightFunction { @Override public double getWeight(Overlap violation, Overlaps overlaps, Model model) { return Math.log10(getPatternWeight(violation)) / Math.log10(getMaxPatternWeight(model)); }  @Override double getWeight(Overlap violation, Overlaps overlaps, Model model); @Override String getFormula(Overlap violation, Overlaps overlaps, Model model); @Override String getId();  }
@Test public void weightsLargerPatternMore() throws Exception { APIUsagePattern smallerPattern = somePattern(buildAUG().withActionNode("N").build()); APIUsagePattern largerPattern = somePattern(buildAUG().withActionNodes("N", "M").build()); Model model = () -> asSet(smallerPattern, largerPattern); double smallerWeight = new PatternSizeWeightFunction().getWeight(instance(smallerPattern), null, model); double largerWeight = new PatternSizeWeightFunction().getWeight(instance(largerPattern), null, model); assertThat(smallerWeight, is(lessThan(largerWeight))); }
@Test public void normalizesWeight() throws Exception { APIUsagePattern smallerPattern = somePattern(buildAUG().withActionNodes("N", "M").build()); APIUsagePattern largerPattern = somePattern(buildAUG().withActionNodes("N", "M", "O").build()); Model model = () -> asSet(smallerPattern, largerPattern); double smallerWeight = new PatternSizeWeightFunction().getWeight(instance(smallerPattern), null, model); assertThat(smallerWeight, is(lessThan(1.0))); assertThat(smallerWeight, is(greaterThan(0.0))); }
@Test public void smoothesWeight() throws Exception { APIUsagePattern smallerPattern = somePattern(buildAUG().withActionNodes("N").build()); APIUsagePattern largerPattern = somePattern(buildAUG().withActionNodes("N", "M").build()); APIUsagePattern largestPattern = somePattern(buildAUG().withActionNodes("N", "M", "O").build()); Model model = () -> asSet(smallerPattern, largerPattern, largestPattern); double smallerWeight = new PatternSizeWeightFunction().getWeight(instance(smallerPattern), null, model); double largerWeight = new PatternSizeWeightFunction().getWeight(instance(largerPattern), null, model); double largestWeight = new PatternSizeWeightFunction().getWeight(instance(largestPattern), null, model); assertThat(largerWeight - smallerWeight, is(greaterThan(largestWeight - largerWeight))); }