Search in sources :

Example 11 with Overlap

use of org.kie.dmn.validation.dtanalysis.model.Overlap in project drools by kiegroup.

the class SubsumptionRulesTest method testSubsumptionRules.

@Test
public void testSubsumptionRules() {
    List<DMNMessage> validate = validator.validate(getReader("Subsumption.dmn"), ANALYZE_DECISION_TABLE);
    DTAnalysis analysis = getAnalysis(validate, "_82100fc5-8799-4ee2-981f-215ded39e68a");
    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(2, 3), new Hyperrectangle(2, Arrays.asList(Interval.newFromBounds(new Bound(new BigDecimal("21"), RangeBoundary.OPEN, null), new Bound(Interval.POS_INF, RangeBoundary.CLOSED, null)), Interval.newFromBounds(new Bound(false, RangeBoundary.CLOSED, null), new Bound(true, RangeBoundary.OPEN, null))))), new Overlap(Arrays.asList(2, 4), new Hyperrectangle(2, Arrays.asList(Interval.newFromBounds(new Bound(new BigDecimal("21"), RangeBoundary.OPEN, null), new Bound(Interval.POS_INF, RangeBoundary.CLOSED, null)), Interval.newFromBounds(new Bound(true, RangeBoundary.CLOSED, null), new Bound(true, RangeBoundary.CLOSED, null))))));
    assertThat(overlaps, hasSize(2));
    // Assert OVERLAPs same values
    assertThat(analysis.getOverlaps(), contains(overlaps.toArray()));
    // Subsumption count.
    assertThat(analysis.getSubsumptions(), hasSize(1));
    List<Subsumption> results = Arrays.asList(new Subsumption(2, 4));
    assertThat(results, hasSize(1));
    assertThat(analysis.getSubsumptions(), contains(results.toArray()));
    assertTrue("It should contain at least 1 DMNMessage for the Subsumtption", validate.stream().anyMatch(p -> p.getMessageType().equals(DMNMessageType.DECISION_TABLE_SUBSUMPTION_RULE)));
}
Also used : Arrays(java.util.Arrays) RangeBoundary(org.kie.dmn.feel.runtime.Range.RangeBoundary) DMNMessage(org.kie.dmn.api.core.DMNMessage) Bound(org.kie.dmn.validation.dtanalysis.model.Bound) Interval(org.kie.dmn.validation.dtanalysis.model.Interval) DMNMessageType(org.kie.dmn.api.core.DMNMessageType) Subsumption(org.kie.dmn.validation.dtanalysis.model.Subsumption) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) BigDecimal(java.math.BigDecimal) List(java.util.List) Hyperrectangle(org.kie.dmn.validation.dtanalysis.model.Hyperrectangle) Matchers.contains(org.hamcrest.Matchers.contains) DTAnalysis(org.kie.dmn.validation.dtanalysis.model.DTAnalysis) Overlap(org.kie.dmn.validation.dtanalysis.model.Overlap) Matchers.hasSize(org.hamcrest.Matchers.hasSize) ANALYZE_DECISION_TABLE(org.kie.dmn.validation.DMNValidator.Validation.ANALYZE_DECISION_TABLE) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Subsumption(org.kie.dmn.validation.dtanalysis.model.Subsumption) DMNMessage(org.kie.dmn.api.core.DMNMessage) Hyperrectangle(org.kie.dmn.validation.dtanalysis.model.Hyperrectangle) Bound(org.kie.dmn.validation.dtanalysis.model.Bound) Overlap(org.kie.dmn.validation.dtanalysis.model.Overlap) DTAnalysis(org.kie.dmn.validation.dtanalysis.model.DTAnalysis) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 12 with Overlap

use of org.kie.dmn.validation.dtanalysis.model.Overlap 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(".");
}
Also used : Bound(org.kie.dmn.validation.dtanalysis.model.Bound) ArrayList(java.util.ArrayList) Hyperrectangle(org.kie.dmn.validation.dtanalysis.model.Hyperrectangle) Overlap(org.kie.dmn.validation.dtanalysis.model.Overlap) Interval(org.kie.dmn.validation.dtanalysis.model.Interval)

Example 13 with Overlap

use of org.kie.dmn.validation.dtanalysis.model.Overlap 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)));
}
Also used : Arrays(java.util.Arrays) RangeBoundary(org.kie.dmn.feel.runtime.Range.RangeBoundary) DMNMessage(org.kie.dmn.api.core.DMNMessage) Bound(org.kie.dmn.validation.dtanalysis.model.Bound) Interval(org.kie.dmn.validation.dtanalysis.model.Interval) DMNMessageType(org.kie.dmn.api.core.DMNMessageType) VALIDATE_COMPILATION(org.kie.dmn.validation.DMNValidator.Validation.VALIDATE_COMPILATION) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) BigDecimal(java.math.BigDecimal) List(java.util.List) Hyperrectangle(org.kie.dmn.validation.dtanalysis.model.Hyperrectangle) Matchers.contains(org.hamcrest.Matchers.contains) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) MisleadingRule(org.kie.dmn.validation.dtanalysis.model.MisleadingRule) DTAnalysis(org.kie.dmn.validation.dtanalysis.model.DTAnalysis) Overlap(org.kie.dmn.validation.dtanalysis.model.Overlap) Matchers.hasSize(org.hamcrest.Matchers.hasSize) ANALYZE_DECISION_TABLE(org.kie.dmn.validation.DMNValidator.Validation.ANALYZE_DECISION_TABLE) MaskedRule(org.kie.dmn.validation.dtanalysis.model.MaskedRule) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) VALIDATE_MODEL(org.kie.dmn.validation.DMNValidator.Validation.VALIDATE_MODEL) MisleadingRule(org.kie.dmn.validation.dtanalysis.model.MisleadingRule) Hyperrectangle(org.kie.dmn.validation.dtanalysis.model.Hyperrectangle) Bound(org.kie.dmn.validation.dtanalysis.model.Bound) Overlap(org.kie.dmn.validation.dtanalysis.model.Overlap) DTAnalysis(org.kie.dmn.validation.dtanalysis.model.DTAnalysis) BigDecimal(java.math.BigDecimal) MaskedRule(org.kie.dmn.validation.dtanalysis.model.MaskedRule) DMNMessage(org.kie.dmn.api.core.DMNMessage) Test(org.junit.Test)

Example 14 with Overlap

use of org.kie.dmn.validation.dtanalysis.model.Overlap in project drools by kiegroup.

the class AbstractDTAnalysisTest method debugAnalysis.

protected static void debugAnalysis(DTAnalysis analysis) {
    if (!LOG.isDebugEnabled()) {
        return;
    }
    StringBuilder sbGaps = new StringBuilder("\nGaps:\n");
    for (Hyperrectangle gap : analysis.getGaps()) {
        sbGaps.append(gap.toString());
        sbGaps.append("\n");
    }
    LOG.debug(sbGaps.toString());
    DefaultPrinterConfiguration printConfig = new DefaultPrinterConfiguration();
    printConfig.addOption(new DefaultConfigurationOption(DefaultPrinterConfiguration.ConfigOption.COLUMN_ALIGN_PARAMETERS, true));
    printConfig.addOption(new DefaultConfigurationOption(DefaultPrinterConfiguration.ConfigOption.COLUMN_ALIGN_FIRST_METHOD_CHAIN, true));
    Expression printGaps = DTAnalysisMeta.printGaps(analysis);
    LOG.debug("\n" + printGaps.toString(printConfig));
    StringBuilder sbOverlaps = new StringBuilder("\nOverlaps:\n");
    for (Overlap overlap : analysis.getOverlaps()) {
        sbOverlaps.append(overlap.toString());
        sbOverlaps.append("\n");
    }
    LOG.debug(sbOverlaps.toString());
    Expression printOverlaps = DTAnalysisMeta.printOverlaps(analysis);
    LOG.debug("\n" + printOverlaps.toString(printConfig));
}
Also used : DefaultConfigurationOption(com.github.javaparser.printer.configuration.DefaultConfigurationOption) Expression(com.github.javaparser.ast.expr.Expression) Hyperrectangle(org.kie.dmn.validation.dtanalysis.model.Hyperrectangle) DefaultPrinterConfiguration(com.github.javaparser.printer.configuration.DefaultPrinterConfiguration) Overlap(org.kie.dmn.validation.dtanalysis.model.Overlap)

Example 15 with Overlap

use of org.kie.dmn.validation.dtanalysis.model.Overlap in project drools by kiegroup.

the class BuiltinAndOtherValuesTest method checkComplexDTDates.

private void checkComplexDTDates(DTAnalysis analysis) {
    assertThat(analysis.getGaps(), hasSize(2));
    @SuppressWarnings({ "unchecked", "rawtypes" }) List<Hyperrectangle> gaps = Arrays.asList(new Hyperrectangle(1, Arrays.asList(Interval.newFromBounds(new Bound(java.time.LocalDate.parse("2019-03-31"), RangeBoundary.CLOSED, null), new Bound(java.time.LocalDate.parse("2019-03-31"), RangeBoundary.CLOSED, null)))), new Hyperrectangle(1, Arrays.asList(Interval.newFromBounds(new Bound(java.time.LocalDate.parse("2019-12-31"), RangeBoundary.CLOSED, null), new Bound(java.time.LocalDate.parse("2019-12-31"), RangeBoundary.CLOSED, null)))));
    assertThat(gaps, hasSize(2));
    // Assert GAPS same values
    assertThat(analysis.getGaps(), contains(gaps.toArray()));
    // assert OVERLAPs count.
    assertThat(analysis.getOverlaps(), hasSize(1));
    @SuppressWarnings({ "unchecked", "rawtypes" }) List<Overlap> overlaps = Arrays.asList(new Overlap(Arrays.asList(2, 3), new Hyperrectangle(1, Arrays.asList(Interval.newFromBounds(new Bound(java.time.LocalDate.parse("2019-06-30"), RangeBoundary.CLOSED, null), new Bound(java.time.LocalDate.parse("2019-06-30"), RangeBoundary.CLOSED, null))))));
    assertThat(overlaps, hasSize(1));
    // Assert OVERLAPs same values
    assertThat(analysis.getOverlaps(), contains(overlaps.toArray()));
}
Also used : Hyperrectangle(org.kie.dmn.validation.dtanalysis.model.Hyperrectangle) Bound(org.kie.dmn.validation.dtanalysis.model.Bound) Overlap(org.kie.dmn.validation.dtanalysis.model.Overlap)

Aggregations

Overlap (org.kie.dmn.validation.dtanalysis.model.Overlap)19 Hyperrectangle (org.kie.dmn.validation.dtanalysis.model.Hyperrectangle)18 Bound (org.kie.dmn.validation.dtanalysis.model.Bound)17 DTAnalysis (org.kie.dmn.validation.dtanalysis.model.DTAnalysis)15 Test (org.junit.Test)14 DMNMessage (org.kie.dmn.api.core.DMNMessage)14 BigDecimal (java.math.BigDecimal)12 Interval (org.kie.dmn.validation.dtanalysis.model.Interval)7 Arrays (java.util.Arrays)6 List (java.util.List)6 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)6 Matchers.contains (org.hamcrest.Matchers.contains)6 Matchers.hasSize (org.hamcrest.Matchers.hasSize)6 Assert.assertTrue (org.junit.Assert.assertTrue)6 DMNMessageType (org.kie.dmn.api.core.DMNMessageType)6 RangeBoundary (org.kie.dmn.feel.runtime.Range.RangeBoundary)6 ANALYZE_DECISION_TABLE (org.kie.dmn.validation.DMNValidator.Validation.ANALYZE_DECISION_TABLE)6 VALIDATE_COMPILATION (org.kie.dmn.validation.DMNValidator.Validation.VALIDATE_COMPILATION)5 MaskedRule (org.kie.dmn.validation.dtanalysis.model.MaskedRule)4 Expression (com.github.javaparser.ast.expr.Expression)2