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("<=")));
}
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)));
}
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);
}
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);
}
}
}
}
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;
}
Aggregations