Esempio n. 1
0
 @Test
 public void CallInterfaceWithMultipleReturn() throws Exception {
   ArdenValue val =
       eval(
           "x := INTERFACE {ytest}",
           "(data1, data2, data3) := CALL x WITH 1,(2,3),4; conclude true;",
           "return (COUNT data1, data2, data3);",
           new TestContext() {
             @Override
             public ArdenRunnable findInterface(String mapping) {
               Assert.assertEquals("ytest", mapping);
               return new ArdenRunnable() {
                 @Override
                 public ArdenValue[] run(ExecutionContext context, ArdenValue[] arguments)
                     throws InvocationTargetException {
                   Assert.assertEquals(3, arguments.length);
                   Assert.assertEquals("1", arguments[0].toString());
                   Assert.assertEquals("(2,3)", arguments[1].toString());
                   Assert.assertEquals("4", arguments[2].toString());
                   return new ArdenValue[] {ArdenList.EMPTY, new ArdenString("hello")};
                 }
               };
             }
           });
   Assert.assertEquals("(0,\"hello\",null)", val.toString());
 }
Esempio n. 2
0
 @Test
 public void CallInterface() throws Exception {
   ArdenValue val =
       eval(
           "x := INTERFACE {ytest}",
           "data1 := CALL x WITH 1,(2,3),4; conclude true;",
           "return data1;",
           new TestContext() {
             @Override
             public ArdenRunnable findInterface(String mapping) {
               Assert.assertEquals("ytest", mapping);
               return new ArdenRunnable() {
                 @Override
                 public ArdenValue[] run(ExecutionContext context, ArdenValue[] arguments)
                     throws InvocationTargetException {
                   Assert.assertEquals(3, arguments.length);
                   Assert.assertEquals("1", arguments[0].toString());
                   Assert.assertEquals("(2,3)", arguments[1].toString());
                   Assert.assertEquals("4", arguments[2].toString());
                   return new ArdenValue[] {ArdenNumber.create(42, 0)};
                 }
               };
             }
           });
   Assert.assertEquals("42", val.toString());
 }
Esempio n. 3
0
 @Test
 public void CallMlmWithMultipleReturn() throws Exception {
   ArdenValue val =
       eval(
           "x := MLM 'ytest' FROM INSTITUTION \"abc\"",
           "(data1, data2, data3) := CALL x WITH 1,(2,3),4; conclude true;",
           "return (COUNT data1, data2, data3);",
           new TestContext() {
             @Override
             public ArdenRunnable findModule(String name, String institution) {
               Assert.assertEquals("ytest", name);
               Assert.assertEquals("abc", institution);
               return new ArdenRunnable() {
                 @Override
                 public ArdenValue[] run(ExecutionContext context, ArdenValue[] arguments)
                     throws InvocationTargetException {
                   Assert.assertEquals(3, arguments.length);
                   Assert.assertEquals("1", arguments[0].toString());
                   Assert.assertEquals("(2,3)", arguments[1].toString());
                   Assert.assertEquals("4", arguments[2].toString());
                   return new ArdenValue[] {ArdenList.EMPTY, new ArdenString("hello")};
                 }
               };
             }
           });
   Assert.assertEquals("(0,\"hello\",null)", val.toString());
 }
Esempio n. 4
0
 @Test
 public void CallMlm() throws Exception {
   ArdenValue val =
       eval(
           "x := MLM 'xtest'",
           "data1 := CALL x WITH 1,(2,3),4; conclude true;",
           "return data1;",
           new TestContext() {
             @Override
             public ArdenRunnable findModule(String name, String institution) {
               Assert.assertEquals("xtest", name);
               Assert.assertNull(institution);
               return new ArdenRunnable() {
                 @Override
                 public ArdenValue[] run(ExecutionContext context, ArdenValue[] arguments)
                     throws InvocationTargetException {
                   Assert.assertEquals(3, arguments.length);
                   Assert.assertEquals("1", arguments[0].toString());
                   Assert.assertEquals("(2,3)", arguments[1].toString());
                   Assert.assertEquals("4", arguments[2].toString());
                   return new ArdenValue[] {ArdenNumber.create(42, 0)};
                 }
               };
             }
           });
   Assert.assertEquals("42", val.toString());
 }
Esempio n. 5
0
 @Test
 public void UninitializedVar() throws Exception {
   ArdenValue sum =
       eval(
           "",
           "if false then isum := 0; endif; conclude true;",
           "return isum;",
           new TestContext());
   Assert.assertEquals("null", sum.toString());
 }
Esempio n. 6
0
 @Test
 public void IsObjectType() throws Exception {
   ArdenValue val =
       eval(
           "MedicationDose := OBJECT [ Medication, Dose, Status ];",
           "dose := NEW MedicationDose WITH 1,2,3; conclude true;",
           "return (dose IS MedicationDose, 1 IS MedicationDose);",
           new TestContext());
   Assert.assertEquals("(true,false)", val.toString());
 }
Esempio n. 7
0
 @Test
 public void ExtractAttributeNames() throws Exception {
   ArdenValue val =
       eval(
           "MedicationDose := OBJECT [ Medication, Dose, Status ];",
           "dose := NEW MedicationDose; conclude true;",
           "return EXTRACT ATTRIBUTE NAMES dose;",
           new TestContext());
   Assert.assertEquals("(\"Medication\",\"Dose\",\"Status\")", val.toString());
 }
Esempio n. 8
0
 @Test
 public void GetWidthAttribute() throws Exception {
   ArdenValue val =
       eval(
           "Rectangle := Object [ aLeft, aTop, aWidth, aHeight ];",
           "rect := NEW Rectangle WITH 1,2,3,4; " + " conclude true;",
           "return rect.awidth;",
           new TestContext());
   Assert.assertEquals("3", val.toString());
 }
Esempio n. 9
0
 @Test
 public void AttributeFrom() throws Exception {
   ArdenValue val =
       eval(
           "MedicationDose := OBJECT [ Medication, Dose, Status ];",
           "dose := NEW MedicationDose WITH 1,2,3;"
               + "attrNames := (\"Medication\",\"Status\",\"Dose\"); conclude true;",
           "return ATTRIBUTE attrNames FROM dose;",
           new TestContext());
   Assert.assertEquals("(1,3,2)", val.toString());
 }
Esempio n. 10
0
 @Test
 public void ForLoop() throws Exception {
   ArdenValue sum =
       eval(
           "",
           "isum := 0;\n"
               + "for i in 1 seqto 100 do\n"
               + "   isum := isum + i;\n"
               + "enddo; conclude true;",
           "return isum;",
           new TestContext());
   Assert.assertEquals("5050", sum.toString());
 }
Esempio n. 11
0
 @Test
 public void WhileLoop() throws Exception {
   ArdenValue sum =
       eval(
           "",
           "i := 0; isum := 0;\n"
               + "while i <= 100 do\n"
               + "   isum := isum + i; i := i + 1;\n"
               + "enddo; conclude true;",
           "return isum;",
           new TestContext());
   Assert.assertEquals("5050", sum.toString());
 }