-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRealTest.groovy
46 lines (38 loc) · 1.54 KB
/
RealTest.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package com.mjog.dagrule
import static org.junit.Assert.*;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
public class RealTest {
DecisionDag rule;
def evaluate(vars){
return rule.evaluate(vars);
}
void assertRules() throws Exception{
assert "Cinema" == evaluate(family_visiting: "yes")
assert "ERROR" == evaluate(family_visiting: "no", weather: "cold")
assert "Play Tennis" == evaluate(family_visiting: "no", weather: "sunny")
assert "Stay In" == evaluate(family_visiting: "no", weather: "rainy")
assert "ERROR" == evaluate(family_visiting: "no", weather: "windy")
assert "Shopping" == evaluate(family_visiting: "no", weather: "windy", money: "rich")
assert "Cinema" == evaluate(family_visiting: "no", weather: "windy", money: "poor")
assert "ERROR" == evaluate(family_visiting: "no", weather: "cloudy", money: "poor")
}
@Test
void testCSVDSL() throws Exception{
ClassLoader classLoader = RealTest.class.getClassLoader();
rule = new CSVDSL().buildDecisionDag(new FileReader(classLoader.getResource("com/mjog/dagrule/RealTest.dagrule").getFile()), true);
assertRules()
}
@Test
void testPasDSL() throws Exception{
ClassLoader classLoader = RealTest.class.getClassLoader();
rule = new PasDSL().buildDecisionDag(new FileReader(classLoader.getResource("com/mjog/dagrule/WeatherRules.pas").getFile()), true);
assertRules()
}
}