PatternSupportWeightFunction implements ViolationWeightFunction { @Override public double getWeight(Overlap violation, Overlaps overlaps, Model model) { return violation.getPattern().getSupport() / (double) model.getMaxPatternSupport(); }  @Override double getWeight(Overlap violation, Overlaps overlaps, Model model); @Override String getFormula(Overlap violation, Overlaps overlaps, Model model); @Override String getId();  }
@Test public void computesSinglePatternWeight() throws Exception { Overlap overlap = someOverlap(); APIUsagePattern pattern = overlap.getPattern(); Model model = () -> asSet(pattern); ViolationWeightFunction weightFunction = new PatternSupportWeightFunction(); double weight = weightFunction.getWeight(overlap, null, model); assertThat(weight, is(1.0)); }
@Test public void weightsRelativeToLargestSupport() throws Exception { APIUsagePattern pattern = somePattern(2); Model model = () -> asSet(pattern, somePattern(4)); ViolationWeightFunction weigthFunction = new PatternSupportWeightFunction(); double weight = weigthFunction.getWeight(emptyOverlap(pattern), null, model); assertThat(weight, is(0.5)); }