Commit 19f596ef authored by R.W.Majeed's avatar R.W.Majeed

examples and more tests

parent 2a2ce614
......@@ -22,35 +22,56 @@ public class TestFacts {
ScriptEngineManager sem;
ObservationFactory factory;
ScriptEngine engine;
List<Observation> list;
DateTimeAccuracy defaultStart;
public void setup(){
public void setup() throws ScriptException{
sem = new ScriptEngineManager();
engine = sem.getEngineByName("nashorn");
// enable strict mode
engine.eval("'use strict';");
factory = new ObservationFactoryImpl();
public void verifyAddFacts() throws ScriptException{
final DateTimeAccuracy defaultStart = DateTimeAccuracy.parsePartialIso8601("2016");
defaultStart = DateTimeAccuracy.parsePartialIso8601("2016");
Observation[] facts = new Observation[]{
factory.createObservation("P1", "C1", DateTimeAccuracy.parsePartialIso8601("2011")),
factory.createObservation("P1", "C2", DateTimeAccuracy.parsePartialIso8601("2011-02-01")),
factory.createObservation("P1", "C3", DateTimeAccuracy.parsePartialIso8601("2011-02-01"))
Facts f = new Facts(factory, "P1", "V1", defaultStart);
List<Observation> list = new ArrayList<>();
this.list = new ArrayList<>();
Collections.addAll(list, facts);
public void verifyAddFacts() throws ScriptException{
Facts f = new Facts(factory, "P1", "V1", defaultStart);
engine.put("facts", f);
// retrieve fact
Fact t = f.get("C4");
Assert.assertEquals(defaultStart, t.getObservation().getStartTime());
public void verifyHasFacts() throws ScriptException{
Facts f = new Facts(factory, "P1", "V1", defaultStart);
engine.put("facts", f);
Object ret;
// verify logical and with two existing facts
ret = engine.eval("Boolean(facts.get('C2') && facts.get('C3'))");
Assert.assertTrue( ret instanceof Boolean );
Assert.assertEquals(Boolean.TRUE, ret);
// should return false as C4 does not exist
ret = engine.eval("Boolean(facts.get('C2') && facts.get('C4'))");
Assert.assertTrue( ret instanceof Boolean );
Assert.assertEquals(Boolean.FALSE, ret);
// concept ids of the facts which can be
// produced if the conditions are right
this.produces = ["ASDF"];
// concept ids for which facts are read
this.requires = ["X","y","Z"];
// inference function
this.infer = function(facts){
// adding concepts not advertised
// in this.produces will result in warning.
// post-process a whole encounter
// a facts object will be available for modifications
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment