Search in sources :

Example 1 with DTAnalysis

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

the class DMNDTAnalyser method dmnDTAnalysis.

private DTAnalysis dmnDTAnalysis(DMNModel model, DecisionTable dt, Set<Validation> flags) {
    DDTATable ddtaTable = new DDTATable();
    compileTableInputClauses(model, dt, ddtaTable);
    compileTableOutputClauses(model, dt, ddtaTable);
    compileTableRules(dt, ddtaTable);
    compileTableComputeColStringMissingEnum(model, dt, ddtaTable);
    printDebugTableInfo(ddtaTable);
    DTAnalysis analysis = new DTAnalysis(dt, ddtaTable);
    analysis.computeOutputInLOV();
    if (!dt.getHitPolicy().equals(HitPolicy.COLLECT)) {
        if (ddtaTable.getColIDsStringWithoutEnum().isEmpty()) {
            LOG.debug("findGaps");
            findGaps(analysis, ddtaTable, 0, new Interval[ddtaTable.inputCols()], Collections.emptyList());
        } else {
            LOG.debug("findGaps Skipped because getColIDsStringWithoutEnum is not empty: {}", ddtaTable.getColIDsStringWithoutEnum());
        }
        LOG.debug("findOverlaps");
        findOverlaps(analysis, ddtaTable, 0, new Interval[ddtaTable.inputCols()], Collections.emptyList());
    } else {
        LOG.debug("findGaps(), findOverlaps() are Skipped because getHitPolicy is COLLECT.");
    }
    LOG.debug("computeMaskedRules");
    analysis.computeMaskedRules();
    LOG.debug("computeMisleadingRules");
    analysis.computeMisleadingRules();
    LOG.debug("normalize");
    analysis.normalize();
    LOG.debug("computeSubsumptions");
    analysis.computeSubsumptions();
    LOG.debug("computeContractions");
    analysis.computeContractions();
    LOG.debug("compute1stNFViolations");
    analysis.compute1stNFViolations();
    LOG.debug("compute2ndNFViolations");
    analysis.compute2ndNFViolations();
    LOG.debug("computeHitPolicyRecommender");
    analysis.computeHitPolicyRecommender();
    if (flags.contains(Validation.COMPUTE_DECISION_TABLE_MCDC)) {
        LOG.debug("mcdc.");
        List<PosNegBlock> selectedBlocks = new MCDCAnalyser(ddtaTable, dt).compute();
        analysis.setMCDCSelectedBlocks(selectedBlocks);
    }
    return analysis;
}
Also used : DDTATable(org.kie.dmn.validation.dtanalysis.model.DDTATable) PosNegBlock(org.kie.dmn.validation.dtanalysis.mcdc.MCDCAnalyser.PosNegBlock) MCDCAnalyser(org.kie.dmn.validation.dtanalysis.mcdc.MCDCAnalyser) DTAnalysis(org.kie.dmn.validation.dtanalysis.model.DTAnalysis)

Example 2 with DTAnalysis

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

the class ExampleMCDCTest method test1.

@Test
public void test1() throws Exception {
    final String resourceFileName = "example1.dmn";
    List<DMNMessage> validate = validator.validate(getReader(resourceFileName), ANALYZE_DECISION_TABLE, COMPUTE_DECISION_TABLE_MCDC);
    DTAnalysis analysis = getAnalysis(validate, "_452a0adf-dd49-47c3-b02d-fe0ad45902c7");
    Collection<Record> mcdcCases = computeMCDCCases(analysis.getMCDCSelectedBlocks());
    assertThat(mcdcCases, hasSize(16));
    assertMCDCCases(resourceFileName, analysis.getSource(), mcdcCases);
    // debugOutputAndOpenXLSX(analysis.getSource(), analysis.getMCDCSelectedBlocks());
    String mcdc2tck = MCDC2TCKGenerator.mcdc2tck(analysis.getSource(), analysis.getMCDCSelectedBlocks());
// debugTCKXML(analysis.getSource(), mcdc2tck);
}
Also used : DMNMessage(org.kie.dmn.api.core.DMNMessage) Record(org.kie.dmn.validation.dtanalysis.mcdc.MCDCAnalyser.Record) DTAnalysis(org.kie.dmn.validation.dtanalysis.model.DTAnalysis) Test(org.junit.Test) AbstractDTAnalysisTest(org.kie.dmn.validation.dtanalysis.AbstractDTAnalysisTest)

Example 3 with DTAnalysis

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

the class GapsAndOverlaps1domainOnTableTest method test.

@Test
public void test() {
    List<DMNMessage> validate = validator.validate(getReader("GapsAndOverlaps1-domainOnTable.dmn"), VALIDATE_COMPILATION, ANALYZE_DECISION_TABLE);
    DTAnalysis analysis = getAnalysis(validate, "_cd2e0a28-3cc2-456b-90b6-392d9c3574af");
    assertThat(analysis.getGaps(), hasSize(11));
    @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("1"), RangeBoundary.OPEN, null)), Interval.newFromBounds(new Bound(new BigDecimal("2"), RangeBoundary.OPEN, null), new Bound(new BigDecimal("999"), RangeBoundary.OPEN, null)))), new Hyperrectangle(2, Arrays.asList(Interval.newFromBounds(new Bound(new BigDecimal("1"), RangeBoundary.CLOSED, null), new Bound(new BigDecimal("2"), RangeBoundary.OPEN, null)), Interval.newFromBounds(new Bound(new BigDecimal("2"), RangeBoundary.OPEN, null), new Bound(new BigDecimal("5"), RangeBoundary.OPEN, null)))), new Hyperrectangle(2, Arrays.asList(Interval.newFromBounds(new Bound(new BigDecimal("1"), RangeBoundary.CLOSED, null), new Bound(new BigDecimal("2"), RangeBoundary.OPEN, null)), Interval.newFromBounds(new Bound(new BigDecimal("6"), RangeBoundary.OPEN, null), new Bound(new BigDecimal("999"), RangeBoundary.OPEN, null)))), new Hyperrectangle(2, Arrays.asList(Interval.newFromBounds(new Bound(new BigDecimal("2"), RangeBoundary.CLOSED, null), new Bound(new BigDecimal("3"), RangeBoundary.CLOSED, null)), Interval.newFromBounds(new Bound(new BigDecimal("4"), RangeBoundary.OPEN, null), new Bound(new BigDecimal("5"), RangeBoundary.OPEN, null)))), new Hyperrectangle(2, Arrays.asList(Interval.newFromBounds(new Bound(new BigDecimal("2"), RangeBoundary.CLOSED, null), new Bound(new BigDecimal("3"), RangeBoundary.CLOSED, null)), Interval.newFromBounds(new Bound(new BigDecimal("6"), RangeBoundary.OPEN, null), new Bound(new BigDecimal("999"), RangeBoundary.OPEN, null)))), new Hyperrectangle(2, Arrays.asList(Interval.newFromBounds(new Bound(new BigDecimal("3"), RangeBoundary.OPEN, null), new Bound(new BigDecimal("4"), RangeBoundary.CLOSED, null)), Interval.newFromBounds(new Bound(new BigDecimal("4"), RangeBoundary.OPEN, null), new Bound(new BigDecimal("999"), RangeBoundary.OPEN, null)))), new Hyperrectangle(2, Arrays.asList(Interval.newFromBounds(new Bound(new BigDecimal("4"), RangeBoundary.OPEN, null), new Bound(new BigDecimal("5"), RangeBoundary.CLOSED, null)), Interval.newFromBounds(new Bound(new BigDecimal("0"), RangeBoundary.CLOSED, null), new Bound(new BigDecimal("1"), RangeBoundary.OPEN, null)))), new Hyperrectangle(2, Arrays.asList(Interval.newFromBounds(new Bound(new BigDecimal("4"), RangeBoundary.OPEN, null), new Bound(new BigDecimal("5"), RangeBoundary.CLOSED, null)), Interval.newFromBounds(new Bound(new BigDecimal("4"), RangeBoundary.OPEN, null), new Bound(new BigDecimal("999"), RangeBoundary.OPEN, null)))), new Hyperrectangle(2, Arrays.asList(Interval.newFromBounds(new Bound(new BigDecimal("5"), RangeBoundary.OPEN, null), new Bound(new BigDecimal("6"), RangeBoundary.OPEN, null)))), new Hyperrectangle(2, Arrays.asList(Interval.newFromBounds(new Bound(new BigDecimal("6"), RangeBoundary.CLOSED, null), new Bound(new BigDecimal("7"), RangeBoundary.CLOSED, null)), Interval.newFromBounds(new Bound(new BigDecimal("3"), RangeBoundary.OPEN, null), new Bound(new BigDecimal("999"), RangeBoundary.OPEN, null)))), new Hyperrectangle(2, Arrays.asList(Interval.newFromBounds(new Bound(new BigDecimal("7"), RangeBoundary.OPEN, null), new Bound(Interval.POS_INF, RangeBoundary.CLOSED, null)))));
    assertThat(gaps, hasSize(11));
    // 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(1, 3), new Hyperrectangle(2, Arrays.asList(Interval.newFromBounds(new Bound(new BigDecimal("2"), RangeBoundary.CLOSED, null), new Bound(new BigDecimal("4"), RangeBoundary.CLOSED, null)), Interval.newFromBounds(new Bound(new BigDecimal("1"), RangeBoundary.CLOSED, null), new Bound(new BigDecimal("2"), RangeBoundary.CLOSED, null))))));
    assertThat(overlaps, hasSize(1));
    // Assert OVERLAPs same values
    assertThat(analysis.getOverlaps(), contains(overlaps.toArray()));
}
Also used : 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 4 with DTAnalysis

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

the class GapsOverlapsBooleanTest method test.

@Test
public void test() {
    List<DMNMessage> validate = validator.validate(getReader("GapsOverlapsBoolean.dmn"), VALIDATE_COMPILATION, ANALYZE_DECISION_TABLE);
    DTAnalysis analysis = getAnalysis(validate, "_EE34FD37-00D1-47A7-B2F6-CC9BCEF30005");
    assertThat(analysis.getGaps(), hasSize(1));
    @SuppressWarnings({ "unchecked", "rawtypes" }) List<Hyperrectangle> gaps = Arrays.asList(new Hyperrectangle(2, Arrays.asList(Interval.newFromBounds(new Bound(true, RangeBoundary.CLOSED, null), new Bound(true, RangeBoundary.CLOSED, null)), Interval.newFromBounds(new Bound(true, RangeBoundary.CLOSED, null), new Bound(true, RangeBoundary.CLOSED, null)))));
    assertThat(gaps, hasSize(1));
    // Assert GAPS
    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(1, 2), new Hyperrectangle(2, Arrays.asList(Interval.newFromBounds(new Bound(false, RangeBoundary.CLOSED, null), new Bound(true, RangeBoundary.OPEN, null)), Interval.newFromBounds(new Bound(false, RangeBoundary.CLOSED, null), new Bound(true, RangeBoundary.OPEN, null))))));
    assertThat(overlaps, hasSize(1));
    // Assert OVERLAPs same values
    assertThat(analysis.getOverlaps(), contains(overlaps.toArray()));
}
Also used : 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) Test(org.junit.Test)

Example 5 with DTAnalysis

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

the class HitPolicyFirstTest method test.

@Test
public void test() {
    List<DMNMessage> validate = validator.validate(getReader("DTAnalysisFirst.dmn"), ANALYZE_DECISION_TABLE);
    DTAnalysis analysis = getAnalysis(validate, "_38EB6C20-6DF4-4EA0-A421-206B9F31AF22");
    assertThat(analysis.getGaps(), hasSize(0));
    assertThat(analysis.getOverlaps(), hasSize(0));
    assertTrue("It should contain at least 1 DMNMessage for the type " + DMNMessageType.DECISION_TABLE_1STNFVIOLATION, validate.stream().anyMatch(p -> p.getMessageType().equals(DMNMessageType.DECISION_TABLE_1STNFVIOLATION)));
}
Also used : List(java.util.List) DMNMessage(org.kie.dmn.api.core.DMNMessage) DMNMessageType(org.kie.dmn.api.core.DMNMessageType) DTAnalysis(org.kie.dmn.validation.dtanalysis.model.DTAnalysis) Matchers.hasSize(org.hamcrest.Matchers.hasSize) Assert.assertTrue(org.junit.Assert.assertTrue) ANALYZE_DECISION_TABLE(org.kie.dmn.validation.DMNValidator.Validation.ANALYZE_DECISION_TABLE) Test(org.junit.Test) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) DMNMessage(org.kie.dmn.api.core.DMNMessage) DTAnalysis(org.kie.dmn.validation.dtanalysis.model.DTAnalysis) Test(org.junit.Test)

Aggregations

DTAnalysis (org.kie.dmn.validation.dtanalysis.model.DTAnalysis)63 DMNMessage (org.kie.dmn.api.core.DMNMessage)50 Test (org.junit.Test)46 Bound (org.kie.dmn.validation.dtanalysis.model.Bound)32 Hyperrectangle (org.kie.dmn.validation.dtanalysis.model.Hyperrectangle)32 BigDecimal (java.math.BigDecimal)25 List (java.util.List)16 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)16 Matchers.hasSize (org.hamcrest.Matchers.hasSize)16 Assert.assertTrue (org.junit.Assert.assertTrue)16 DMNMessageType (org.kie.dmn.api.core.DMNMessageType)16 ANALYZE_DECISION_TABLE (org.kie.dmn.validation.DMNValidator.Validation.ANALYZE_DECISION_TABLE)16 Overlap (org.kie.dmn.validation.dtanalysis.model.Overlap)15 Arrays (java.util.Arrays)11 Matchers.contains (org.hamcrest.Matchers.contains)11 Matchers.is (org.hamcrest.Matchers.is)7 VALIDATE_COMPILATION (org.kie.dmn.validation.DMNValidator.Validation.VALIDATE_COMPILATION)7 Interval (org.kie.dmn.validation.dtanalysis.model.Interval)7 RangeBoundary (org.kie.dmn.feel.runtime.Range.RangeBoundary)6 DecisionTable (org.kie.dmn.model.api.DecisionTable)5