PatternSameSizeSupportWeightFunction implements ViolationWeightFunction { @Override public double getWeight(Overlap violation, Overlaps overlaps, Model model) { APIUsagePattern pattern = violation.getPattern(); return pattern.getSupport() / (double) model.getMaxPatternSupport(pattern.getNodeSize()); }  @Override double getWeight(Overlap violation, Overlaps overlaps, Model model); @Override String getFormula(Overlap violation, Overlaps overlaps, Model model); @Override String getId();  }
@Test public void calculatesPatternSupportWeight_noEquallySizedPattern() { ViolationWeightFunction weightFunction = new PatternSameSizeSupportWeightFunction(); double weight = weightFunction.getWeight(violation, null, model); assertThat(weight, is(1.0)); }
@Test public void calculatesPatternSupportWeight_equallySizedPatternWithLargerSupport() { APIUsagePattern pattern2 = somePattern(pattern, pattern.getSupport() * 2); model = () -> asSet(pattern, pattern2); ViolationWeightFunction weightFunction = new PatternSameSizeSupportWeightFunction(); double weight = weightFunction.getWeight(violation, null, model); assertThat(weight, is(0.5)); }
@Test public void calculatesPatternSupportWeight_equallySizedPatternWithSmallerSupport() { APIUsagePattern pattern2 = somePattern(pattern, 1); model = () -> asSet(pattern, pattern2); ViolationWeightFunction weightFunction = new PatternSameSizeSupportWeightFunction(); double weight = weightFunction.getWeight(violation, null, model); assertThat(weight, is(1.0)); }