use of org.kie.dmn.validation.dtanalysis.model.Hyperrectangle in project drools by kiegroup.
the class BuiltinAndOtherValuesTest method testWeirdYMduration.
@Test
public void testWeirdYMduration() {
List<DMNMessage> validate = validator.validate(getReader("weirdYMduration.dmn"), ANALYZE_DECISION_TABLE);
DTAnalysis analysis = getAnalysis(validate, "_fe7d267b-d770-461e-8300-e09981147341");
assertThat(analysis.getGaps(), hasSize(1));
@SuppressWarnings({ "unchecked", "rawtypes" }) List<Hyperrectangle> gaps = Arrays.asList(new Hyperrectangle(1, Arrays.asList(Interval.newFromBounds(new Bound(org.kie.dmn.feel.lang.types.impl.ComparablePeriod.parse("P1M"), RangeBoundary.CLOSED, null), new Bound(org.kie.dmn.feel.lang.types.impl.ComparablePeriod.parse("P1M"), RangeBoundary.CLOSED, null)))));
assertThat(gaps, hasSize(1));
// Assert GAPS same values
assertThat(analysis.getGaps(), contains(gaps.toArray()));
// assert OVERLAPs count.
assertThat(analysis.getOverlaps(), hasSize(0));
}
use of org.kie.dmn.validation.dtanalysis.model.Hyperrectangle in project drools by kiegroup.
the class DMNDTAnalyser method findOverlaps.
private void findOverlaps(DTAnalysis analysis, DDTATable ddtaTable, int jColIdx, Interval[] currentIntervals, Collection<Integer> activeRules) {
LOG.debug("findOverlaps jColIdx {}, currentIntervals {}, activeRules {}", jColIdx, currentIntervals, activeRules);
if (jColIdx < ddtaTable.inputCols()) {
List<Bound> bounds = findBoundsSorted(ddtaTable, jColIdx, activeRules);
List<Interval> activeIntervals = new ArrayList<>();
Bound<?> lastBound = bounds.get(0);
for (Bound<?> currentBound : bounds) {
LOG.debug("lastBound {} currentBound {} activeIntervals {} == rules {}", lastBound, currentBound, activeIntervals, activeIntervalsToRules(activeIntervals));
if (activeIntervals.size() > 1 && canBeNewCurrInterval(lastBound, currentBound)) {
Interval analysisInterval = new Interval(lastBound.isUpperBound() ? Interval.invertBoundary(lastBound.getBoundaryType()) : lastBound.getBoundaryType(), lastBound.getValue(), currentBound.getValue(), currentBound.isLowerBound() ? Interval.invertBoundary(currentBound.getBoundaryType()) : currentBound.getBoundaryType(), 0, 0);
currentIntervals[jColIdx] = analysisInterval;
findOverlaps(analysis, ddtaTable, jColIdx + 1, currentIntervals, activeIntervalsToRules(activeIntervals));
}
if (currentBound.isLowerBound()) {
activeIntervals.add(currentBound.getParent());
} else {
activeIntervals.remove(currentBound.getParent());
}
lastBound = currentBound;
}
// facilitate debugging.
currentIntervals[jColIdx] = null;
} else if (jColIdx == ddtaTable.inputCols()) {
if (activeRules.size() > 1) {
Hyperrectangle overlap = new Hyperrectangle(ddtaTable.inputCols(), Arrays.asList(currentIntervals));
LOG.debug("OVERLAP DETECTED {}", overlap);
analysis.addOverlap(new Overlap(activeRules, overlap));
}
} else {
throw new IllegalStateException();
}
LOG.debug(".");
}
use of org.kie.dmn.validation.dtanalysis.model.Hyperrectangle in project drools by kiegroup.
the class StringWithoutEnumNoGapTest method test.
@Test
public void test() {
List<DMNMessage> validate = validator.validate(getReader("stringWithoutEnumNoGap.dmn"), VALIDATE_COMPILATION, VALIDATE_MODEL, ANALYZE_DECISION_TABLE);
// no gap but no enum "skip Gap analysis" message, (omit 2 overlaps DROOLS-5363), 2 masked, (omit 2 misleading as redundant with Masked).
assertThat(validate, hasSize(3));
debugValidatorMsg(validate);
DTAnalysis analysis = getAnalysis(validate, "_8b48d1c9-265c-47aa-9378-7f11d55dfe55");
assertThat(analysis.getGaps(), hasSize(0));
// assert OVERLAPs count.
assertThat(analysis.getOverlaps(), hasSize(2));
@SuppressWarnings({ "unchecked", "rawtypes" }) List<Overlap> overlaps = Arrays.asList(new Overlap(Arrays.asList(1, 3), new Hyperrectangle(2, Arrays.asList(Interval.newFromBounds(new Bound("EU", RangeBoundary.CLOSED, null), new Bound("EU", RangeBoundary.CLOSED, null)), Interval.newFromBounds(new Bound(new BigDecimal("18"), RangeBoundary.CLOSED, null), new Bound(Interval.POS_INF, RangeBoundary.CLOSED, null))))), new Overlap(Arrays.asList(3, 2), new Hyperrectangle(2, Arrays.asList(Interval.newFromBounds(new Bound("US", RangeBoundary.CLOSED, null), new Bound("US", RangeBoundary.CLOSED, null)), Interval.newFromBounds(new Bound(new BigDecimal("21"), RangeBoundary.CLOSED, null), new Bound(Interval.POS_INF, RangeBoundary.CLOSED, null))))));
assertThat(overlaps, hasSize(2));
// Assert OVERLAPs same values
assertThat(analysis.getOverlaps(), contains(overlaps.toArray()));
// MaskedRules count.
assertThat(analysis.getMaskedRules(), hasSize(2));
List<MaskedRule> maskedRules = Arrays.asList(new MaskedRule(1, 3), new MaskedRule(2, 3));
assertThat(maskedRules, hasSize(2));
assertThat(analysis.getMaskedRules(), contains(maskedRules.toArray()));
assertTrue("It should contain DMNMessage for the MaskedRule", validate.stream().anyMatch(p -> p.getMessageType().equals(DMNMessageType.DECISION_TABLE_MASKED_RULE)));
// MisleadingRules are duplicate of Masked, so are no longer displayed.
assertThat(analysis.getMisleadingRules(), hasSize(2));
List<MisleadingRule> misleadingRules = Arrays.asList(new MisleadingRule(3, 1), new MisleadingRule(3, 2));
assertThat(misleadingRules, hasSize(2));
assertThat(analysis.getMisleadingRules(), containsInAnyOrder(misleadingRules.toArray()));
assertTrue("It should NOT contain DMNMessage for the MisleadingRule", validate.stream().noneMatch(p -> p.getMessageType().equals(DMNMessageType.DECISION_TABLE_MISLEADING_RULE)));
}
use of org.kie.dmn.validation.dtanalysis.model.Hyperrectangle in project drools by kiegroup.
the class DTNestingTest method checkNegativeTableInBKM.
private void checkNegativeTableInBKM(List<DMNMessage> validate) {
DTAnalysis analysis = getAnalysis(validate, "_68839ac9-1d1b-4e12-9c4f-6b9048b860e1");
assertThat(analysis.getGaps(), hasSize(1));
@SuppressWarnings({ "unchecked", "rawtypes" }) List<Hyperrectangle> gaps = Arrays.asList(new Hyperrectangle(1, Arrays.asList(Interval.newFromBounds(new Bound(new BigDecimal("0"), RangeBoundary.CLOSED, null), new Bound(Interval.POS_INF, RangeBoundary.CLOSED, null)))));
assertThat(gaps, hasSize(1));
// Assert GAPS
assertThat(analysis.getGaps(), contains(gaps.toArray()));
// assert OVERLAPs count.
assertThat(analysis.getOverlaps(), hasSize(0));
}
use of org.kie.dmn.validation.dtanalysis.model.Hyperrectangle in project drools by kiegroup.
the class AgeKittenTest method checkAnalysis.
private void checkAnalysis(List<DMNMessage> validate) {
DTAnalysis analysis = getAnalysis(validate, "_5e3e4546-69c2-43f2-b93a-7ea285878ca0");
assertThat(analysis.getGaps(), hasSize(2));
@SuppressWarnings({ "unchecked", "rawtypes" }) List<Hyperrectangle> gaps = Arrays.asList(new Hyperrectangle(2, Arrays.asList(Interval.newFromBounds(new Bound(new BigDecimal("0"), RangeBoundary.CLOSED, null), new Bound(new BigDecimal("12"), RangeBoundary.OPEN, null)))), new Hyperrectangle(2, Arrays.asList(Interval.newFromBounds(new Bound(new BigDecimal("15"), RangeBoundary.CLOSED, null), new Bound(new BigDecimal("18"), RangeBoundary.OPEN, null)), Interval.newFromBounds(new Bound("Dog", RangeBoundary.CLOSED, null), new Bound("Dog", RangeBoundary.CLOSED, null)))));
assertThat(gaps, hasSize(2));
// Assert GAPS
assertThat(analysis.getGaps(), contains(gaps.toArray()));
// assert OVERLAPs count.
assertThat(analysis.getOverlaps(), hasSize(0));
}
Aggregations