Search in sources :

Example 6 with Interval

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

the class IntervalTest method testHumanFriendlyContinuous.

@Test
public void testHumanFriendlyContinuous() {
    Interval domainInterval = new Interval(RangeBoundary.CLOSED, 0, 100, RangeBoundary.CLOSED, 0, 0);
    DummyDomain domain = new DummyDomain(domainInterval, Collections.emptyList());
    assertThat(new Interval(RangeBoundary.CLOSED, 1, 100, RangeBoundary.CLOSED, 0, 0).asHumanFriendly(domain), startsWith(">="));
    assertThat(new Interval(RangeBoundary.OPEN, 1, 100, RangeBoundary.CLOSED, 0, 0).asHumanFriendly(domain), startsWith(">"));
    assertThat(new Interval(RangeBoundary.OPEN, 1, 100, RangeBoundary.CLOSED, 0, 0).asHumanFriendly(domain), not(startsWith(">=")));
    assertThat(new Interval(RangeBoundary.CLOSED, 0, 99, RangeBoundary.CLOSED, 0, 0).asHumanFriendly(domain), startsWith("<="));
    assertThat(new Interval(RangeBoundary.CLOSED, 0, 99, RangeBoundary.OPEN, 0, 0).asHumanFriendly(domain), startsWith("<"));
    assertThat(new Interval(RangeBoundary.CLOSED, 0, 99, RangeBoundary.OPEN, 0, 0).asHumanFriendly(domain), not(startsWith("<=")));
}
Also used : Interval(org.kie.dmn.validation.dtanalysis.model.Interval) Test(org.junit.Test)

Example 7 with Interval

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

the class IntervalTest method testFlatten3.

@Test
public void testFlatten3() {
    Interval a = new Interval(RangeBoundary.CLOSED, 0, 3, RangeBoundary.CLOSED, 0, 0);
    Interval b = new Interval(RangeBoundary.CLOSED, 1, 2, RangeBoundary.CLOSED, 0, 0);
    Interval c = new Interval(RangeBoundary.CLOSED, 3, 4, RangeBoundary.CLOSED, 0, 0);
    List<Interval> result = Interval.flatten(Arrays.asList(c, b, a));
    assertThat(result, contains(new Interval(RangeBoundary.CLOSED, 0, 4, RangeBoundary.CLOSED, 0, 0)));
}
Also used : Interval(org.kie.dmn.validation.dtanalysis.model.Interval) Test(org.junit.Test)

Example 8 with Interval

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

the class IntervalTest method testInvertOverDomain.

@Test
public void testInvertOverDomain() {
    Interval a = new Interval(RangeBoundary.CLOSED, 0, 3, RangeBoundary.OPEN, 1, 2);
    Interval domain = new Interval(RangeBoundary.CLOSED, Interval.NEG_INF, Interval.POS_INF, RangeBoundary.CLOSED, 0, 0);
    List<Interval> result = Interval.invertOverDomain(a, domain);
    assertThat(result, hasSize(2));
    assertInterval(result.get(0), RangeBoundary.CLOSED, Interval.NEG_INF, 0, RangeBoundary.OPEN, 1, 2);
    assertInterval(result.get(1), RangeBoundary.CLOSED, 3, Interval.POS_INF, RangeBoundary.CLOSED, 1, 2);
}
Also used : Interval(org.kie.dmn.validation.dtanalysis.model.Interval) Test(org.junit.Test)

Example 9 with Interval

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

the class MCDCAnalyser method calculateElseRuleIdx.

private void calculateElseRuleIdx() {
    if (dt.getHitPolicy() == HitPolicy.PRIORITY) {
        // calculate "else" rule if present.
        for (int ruleIdx = ddtaTable.getRule().size() - 1; ruleIdx >= 0 && !elseRuleIdx.isPresent(); ruleIdx--) {
            DDTARule rule = ddtaTable.getRule().get(ruleIdx);
            List<DDTAInputEntry> ie = rule.getInputEntry();
            boolean checkAll = true;
            for (int colIdx = 0; colIdx < ie.size() && checkAll; colIdx++) {
                DDTAInputEntry ieIDX = ie.get(colIdx);
                boolean idIDXsize1 = ieIDX.getIntervals().size() == 1;
                Interval ieIDXint0 = ieIDX.getIntervals().get(0);
                Interval domainMinMax = ddtaTable.getInputs().get(colIdx).getDomainMinMax();
                boolean equals = ieIDXint0.equals(domainMinMax);
                checkAll &= idIDXsize1 && equals;
            }
            if (checkAll) {
                LOG.debug("I believe P table with else rule: {}", ruleIdx + 1);
                elseRuleIdx = Optional.of(ruleIdx);
            }
        }
    }
}
Also used : DDTARule(org.kie.dmn.validation.dtanalysis.model.DDTARule) DDTAInputEntry(org.kie.dmn.validation.dtanalysis.model.DDTAInputEntry) Interval(org.kie.dmn.validation.dtanalysis.model.Interval)

Example 10 with Interval

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

the class DMNDTAnalyser method toIntervals.

private List<Interval> toIntervals(List<BaseNode> elements, boolean isNegated, Interval minMax, List discreteValues, int rule, int col) {
    List<Interval> results = new ArrayList<>();
    if (elements.size() == 1 && elements.get(0) instanceof UnaryTestNode && ((UnaryTestNode) elements.get(0)).getValue() instanceof NullNode) {
        return Collections.emptyList();
    }
    if (discreteValues != null && !discreteValues.isEmpty() && areAllEQUnaryTest(elements) && elements.size() > 1) {
        // JDK BitSet size will always be larger.
        int bitsetLogicalSize = discreteValues.size();
        BitSet hitValues = new BitSet(bitsetLogicalSize);
        for (BaseNode n : elements) {
            Comparable<?> thisValue = valueFromNode(((UnaryTestNode) n).getValue());
            int indexOf = discreteValues.indexOf(thisValue);
            if (indexOf < 0) {
                throw new IllegalStateException("Unable to determine discreteValue index for: " + n);
            }
            hitValues.set(indexOf);
        }
        if (isNegated) {
            hitValues.flip(0, bitsetLogicalSize);
        }
        int lowerBoundIdx = -1;
        int upperBoundIdx = -1;
        for (int i = 0; i < hitValues.length(); i++) {
            boolean curValue = hitValues.get(i);
            if (curValue) {
                if (lowerBoundIdx < 0) {
                    lowerBoundIdx = i;
                    upperBoundIdx = i;
                } else {
                    upperBoundIdx = i;
                }
            } else {
                if (lowerBoundIdx >= 0 && upperBoundIdx >= 0) {
                    results.add(createIntervalOfRule(discreteValues, rule, col, lowerBoundIdx, upperBoundIdx));
                    lowerBoundIdx = -1;
                    upperBoundIdx = -1;
                }
            }
        }
        if (lowerBoundIdx >= 0 && upperBoundIdx >= 0) {
            results.add(createIntervalOfRule(discreteValues, rule, col, lowerBoundIdx, upperBoundIdx));
        }
    } else {
        for (BaseNode n : elements) {
            if (n instanceof DashNode) {
                results.add(new Interval(minMax.getLowerBound().getBoundaryType(), minMax.getLowerBound().getValue(), minMax.getUpperBound().getValue(), minMax.getUpperBound().getBoundaryType(), rule, col));
                continue;
            }
            UnaryTestNode ut = (UnaryTestNode) n;
            Interval interval = utnToInterval(ut, minMax, discreteValues, rule, col);
            if (isNegated) {
                results.addAll(Interval.invertOverDomain(interval, minMax));
            } else {
                results.add(interval);
            }
        }
    }
    return results;
}
Also used : UnaryTestNode(org.kie.dmn.feel.lang.ast.UnaryTestNode) ArrayList(java.util.ArrayList) BitSet(java.util.BitSet) BaseNode(org.kie.dmn.feel.lang.ast.BaseNode) DashNode(org.kie.dmn.feel.lang.ast.DashNode) NullNode(org.kie.dmn.feel.lang.ast.NullNode) Interval(org.kie.dmn.validation.dtanalysis.model.Interval)

Aggregations

Interval (org.kie.dmn.validation.dtanalysis.model.Interval)20 Test (org.junit.Test)9 ArrayList (java.util.ArrayList)4 QName (javax.xml.namespace.QName)3 ProcessedUnaryTest (org.kie.dmn.feel.codegen.feel11.ProcessedUnaryTest)3 UnaryTestListNode (org.kie.dmn.feel.lang.ast.UnaryTestListNode)3 UnaryTestNode (org.kie.dmn.feel.lang.ast.UnaryTestNode)3 UnaryTestInterpretedExecutableExpression (org.kie.dmn.feel.lang.impl.UnaryTestInterpretedExecutableExpression)3 DDTAInputClause (org.kie.dmn.validation.dtanalysis.model.DDTAInputClause)3 DDTAInputEntry (org.kie.dmn.validation.dtanalysis.model.DDTAInputEntry)3 BaseNode (org.kie.dmn.feel.lang.ast.BaseNode)2 NullNode (org.kie.dmn.feel.lang.ast.NullNode)2 InputClause (org.kie.dmn.model.api.InputClause)2 Bound (org.kie.dmn.validation.dtanalysis.model.Bound)2 DDTARule (org.kie.dmn.validation.dtanalysis.model.DDTARule)2 Hyperrectangle (org.kie.dmn.validation.dtanalysis.model.Hyperrectangle)2 StaticJavaParser.parseExpression (com.github.javaparser.StaticJavaParser.parseExpression)1 Expression (com.github.javaparser.ast.expr.Expression)1 IntegerLiteralExpr (com.github.javaparser.ast.expr.IntegerLiteralExpr)1 MethodCallExpr (com.github.javaparser.ast.expr.MethodCallExpr)1