RuleEngine { public boolean matchRule(Rule rule, Item item) { for(String key:rule.getAnt().keys()){ if(!item.get(key).containsAll(rule.getAnt().get(key))){ return false; } } return true; }  void add(Rule rule); void addRules(List<Rule> rules); void clear(); int getMemoryLength(); synchronized Rule getTopMatch(Item item); boolean matchRule(Rule rule, Item item);  }
@Test public void match8(){ Item item = new Item(123); item.put("q", "1"); Assert.assertFalse(re.matchRule(Rule.buildRule("{q=1,q=2}=>{y=1}", 0.0, 0.0), item)); }
@Test public void match5(){ Item item = new Item(123); item.put("q", "1"); item.put("q", "2"); Assert.assertFalse(re.matchRule(Rule.buildRule("{q=3}=>{y=1}", 0.0, 0.0), item)); }
@Test public void match6(){ Item item = new Item(123); item.put("q", "1"); item.put("q", "2"); Assert.assertFalse(re.matchRule(Rule.buildRule("{q=1,q=3}=>{y=1}", 0.0, 0.0), item)); }
@Test public void match1(){ Item item = new Item(123); item.put("a", "b"); Assert.assertTrue(re.matchRule(Rule.buildRule("{}=>{y=1}", 0.0, 0.0), item)); }
@Test public void match2(){ Item item = new Item(123); item.put("a", "b"); Assert.assertFalse(re.matchRule(Rule.buildRule("{a=c}=>{y=1}", 0.0, 0.0), item)); }
@Test public void match3(){ Item item = new Item(123); item.put("q", "1"); Assert.assertTrue(re.matchRule(Rule.buildRule("{q=1}=>{y=1}", 0.0, 0.0), item)); }
@Test public void match4(){ Item item = new Item(123); item.put("q", "1"); item.put("q", "2"); Assert.assertTrue(re.matchRule(Rule.buildRule("{q=2}=>{y=1}", 0.0, 0.0), item)); }
@Test public void match7(){ Item item = new Item(123); item.put("q", "1"); item.put("q", "2"); Assert.assertTrue(re.matchRule(Rule.buildRule("{q=1}=>{y=1}", 0.0, 0.0), item)); }