Esempio n. 1
0
 private ArdenValue eval(String data, String logic, String action, ExecutionContext context)
     throws Exception {
   MedicalLogicModule mlm = ActionTests.parseTemplate(data, logic, action);
   ArdenValue[] result = mlm.run(context, null);
   Assert.assertEquals(1, result.length);
   return result[0];
 }
Esempio n. 2
0
  @Test
  public void JDBCExecutionContextRead() throws Exception {
    if (loadSQLite() == null) {
      return;
    }
    String[] args = new String[] {"-e", "jdbc:sqlite:"};
    CommandLineOptions options = CliFactory.parseArguments(CommandLineOptions.class, args);

    ExecutionContext testContext = new JDBCExecutionContext(options);
    MedicalLogicModule mlm =
        ActionTests.parseTemplate(
            "varA := read {drop table if exists person};\n"
                + "varB := read {create table person (id integer, name string)};\n"
                + "varC := read {insert into person values (1, 'A')};\n"
                + "varD := read {insert into person values (2, 'B')};\n"
                + "(varE, varF) := read {select * from person};\n",
            "conclude true;",
            "return (varE, varF);");
    ArdenValue[] result = mlm.run(testContext, null);
    Assert.assertEquals(1, result.length);

    ArdenValue[] expected = {
      new ArdenNumber(1), new ArdenNumber(2), new ArdenString("A"), new ArdenString("B")
    };
    ArdenValue[] resultList = ((ArdenList) (result[0])).values;

    Assert.assertArrayEquals(expected, resultList);
  }
Esempio n. 3
0
 @Test
 public void RecursiveMlm() throws Exception {
   MedicalLogicModule mlm =
       ActionTests.parseTemplate(
           "this := MLM mlm_self; arg := ARGUMENT;",
           "If arg > 1 THEN"
               + "  result := CALL this WITH (arg-1);"
               + "ELSE"
               + "  result := 1;"
               + "ENDIF; conclude true;",
           "return result * arg;");
   ArdenValue[] result = mlm.run(new TestContext(), new ArdenValue[] {new ArdenNumber(10)});
   Assert.assertEquals(1, result.length);
   Assert.assertEquals("3628800", result[0].toString());
 }