/** * * * <pre> * or * / \ * and or * / \ / \ * descr descr2 descr3 descr4 * </pre> * * result:<br> * descr && descr2<br> * or<br> * descr3<br> * or<br> * descr4 */ @Test public void testAddOrAndOr() { Pattern pattern = VerifierComponentMockFactory.createPattern1(); LiteralRestriction literalRestriction = LiteralRestriction.createRestriction(pattern, ""); LiteralRestriction literalRestriction2 = LiteralRestriction.createRestriction(pattern, ""); LiteralRestriction literalRestriction3 = LiteralRestriction.createRestriction(pattern, ""); LiteralRestriction literalRestriction4 = LiteralRestriction.createRestriction(pattern, ""); PatternSolver solver = new PatternSolver(pattern); solver.addOperator(OperatorDescrType.OR); solver.addOperator(OperatorDescrType.AND); solver.add(literalRestriction); solver.add(literalRestriction2); solver.end(); solver.addOperator(OperatorDescrType.OR); solver.add(literalRestriction3); solver.add(literalRestriction4); solver.end(); solver.end(); List<Set<VerifierComponent>> list = solver.getPossibilityLists(); assertEquals(3, list.size()); assertEquals(2, list.get(0).size()); assertTrue(list.get(0).contains(literalRestriction)); assertTrue(list.get(0).contains(literalRestriction2)); assertEquals(1, list.get(1).size()); assertTrue(list.get(1).contains(literalRestriction3)); assertEquals(1, list.get(2).size()); assertTrue(list.get(2).contains(literalRestriction4)); }
public void testPatternPossibilityRedundancy() throws Exception { StatelessSession session = getStatelessSession(this.getClass().getResourceAsStream("Possibilities.drl")); session.setAgendaFilter(new RuleNameMatchesAgendaFilter("Find pattern possibility redundancy")); Collection<Object> data = new ArrayList<Object>(); VerifierResult result = VerifierResultFactory.createVerifierResult(); session.setGlobal("result", result); String ruleName1 = "Rule 1"; String ruleName2 = "Rule 2"; Pattern p1 = new Pattern(); p1.setRuleName(ruleName1); Pattern p2 = new Pattern(); p2.setRuleName(ruleName2); LiteralRestriction lr1 = new LiteralRestriction(); lr1.setRuleName(ruleName1); LiteralRestriction lr2 = new LiteralRestriction(); lr2.setRuleName(ruleName2); PatternPossibility pp1 = new PatternPossibility(); pp1.setPatternId(p1.getId()); pp1.setRuleName(ruleName1); pp1.add(lr1); PatternPossibility pp2 = new PatternPossibility(); pp2.setPatternId(p2.getId()); pp2.setRuleName(ruleName2); pp2.add(lr2); Redundancy r1 = new Redundancy(lr1, lr2); Redundancy r2 = new Redundancy(p1, p2); data.add(p1); data.add(p2); data.add(lr1); data.add(lr2); data.add(pp1); data.add(pp2); data.add(r1); data.add(r2); StatelessSessionResult sessionResult = session.executeWithResults(data); Map<String, Set<String>> map = createRedundancyMap(sessionResult.iterateObjects()); assertTrue(TestBase.mapContains(map, ruleName1, ruleName2)); assertTrue(TestBase.mapContains(map, ruleName2, ruleName1)); if (!map.isEmpty()) { fail("More redundancies than was expected."); } }