Skip to content

Commit

Permalink
unit test for js rule engine load file
Browse files Browse the repository at this point in the history
  • Loading branch information
cschen1205 committed May 8, 2017
1 parent 24d2294 commit 43b5f71
Showing 1 changed file with 39 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
import org.testng.annotations.Test;

import javax.script.ScriptException;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.Collections;

/**
* Created by cschen on 28/4/17.
Expand All @@ -14,15 +19,48 @@ public class JSRuleInferenceEngineUnitTest {
@BeforeTest
public void setup() throws ScriptException {
engine = new JSRuleInferenceEngine();

}

@Test
public void testLoadFile() throws IOException, ScriptException {
String jsContent = IOUtil.readToEnd("js/vehicle-rules.js");
engine.loadString(jsContent);
Files.write(Paths.get("/tmp/rules.js"), Collections.singletonList(jsContent));
engine.loadFile("/tmp/rules.js");

engine.buildRules();

engine.clearFacts();

engine.addFact("num_wheels", "4");
engine.addFact("motor", "yes");
engine.addFact("num_doors", "3");
engine.addFact("size", "medium");



System.out.println("before inference");
System.out.println(engine.getKnowledgeBase());
System.out.println();



engine.infer(); //forward chain

System.out.println("after inference");
System.out.println(engine.getKnowledgeBase());
System.out.println();

}



@Test
public void testVehicleScenario() throws ScriptException {

String jsContent = IOUtil.readToEnd("js/vehicle-rules.js");
engine.loadString(jsContent);

engine.buildRules();

engine.clearFacts();
Expand Down

0 comments on commit 43b5f71

Please sign in to comment.