예제 #1
0
        public void T47_TestBooleanOperationOnNull()
        {
            string          src    = @"
d = [Imperative]
{
	a = false;
        b = 0;
	d = 0;
	if( a == null)
	{
	    d = d + 1;
	}
    if( b == null)
	{
	    d = d + 1;
	}	
    return d;
}
";
            ExecutionMirror mirror = thisTest.RunScriptSource(src);

            thisTest.Verify("d", 0);
        }
예제 #2
0
        public void T47_TestBooleanOperationOnNull()
        {
            Assert.Throws(typeof(ProtoCore.Exceptions.CompileErrorsOccured), () =>
            {
                string src             = @"[Associative]
{
	a = false;
        b = 0;
	d = 0;
	if( a == null)
	{
	    d = d + 1;
	}
    if( b == null)
	{
	    d = d + 1;
	}	
}
";
                ExecutionMirror mirror = thisTest.RunScriptSource(src);
                thisTest.Verify("d", 0);
            });
        }
예제 #3
0
        public void T23_TestUsingMathAndLogicalExpr()
        {
            string          src    = @"c1;
c2;
c3;
c4;
[Imperative]
{
  a = -3.5;
  b = -4;
  c1 = a + b; 
  c2 = a - b;
  c3 = a * b;
  c4 = a / b; 
}
";
            ExecutionMirror mirror = thisTest.RunScriptSource(src);

            Assert.IsTrue((double)mirror.GetValue("c1").Payload == -7.5);
            Assert.IsTrue((double)mirror.GetValue("c2").Payload == 0.5);
            Assert.IsTrue((double)mirror.GetValue("c3").Payload == 14.0);
            Assert.IsTrue((double)mirror.GetValue("c4").Payload == 0.875);
        }
예제 #4
0
        public void T15_TestInRecursiveFunctionScope()
        {
            string          src    = @"val;
	def fac : int ( n : int )
	{
return = [Imperative]
{
	    if(n == 0 )
        {
		    return = 1;
        }
		return = n * fac (n-1 );
	}
}
[Imperative]
{
    val = fac(5);				
}
";
            ExecutionMirror mirror = thisTest.RunScriptSource(src);

            thisTest.Verify("val", 120);
        }
예제 #5
0
        public void T23_TestUsingMathAndLogicalExpr()
        {
            string          src    = @"c1;
c2;
c3;
c4;
[Associative]
{
  a = -3.5;
  b = -4;
  c1 = a + b; 
  c2 = a - b;
  c3 = a * b;
  c4 = a / b; 
}
";
            ExecutionMirror mirror = thisTest.RunScriptSource(src);

            thisTest.Verify("c1", -7.5);
            thisTest.Verify("c2", 0.5);
            thisTest.Verify("c3", 14.0);
            thisTest.Verify("c4", 0.875);
        }
예제 #6
0
        public void T28_FunctionPointerInInlineCond()
        {
            string          code   = @"
def foo(x, y = 10, z = 100)
{
    return = x + y + z;
}
def bar(x, y = 2, z = 3)
{
    return = x * y * z;
}
def ding(i, f, b)
{
    return = (i > 0) ? f(i) : b(i);
}
r1 = ding(1, foo, bar);
r2 = ding(-1, foo, bar);
";
            ExecutionMirror mirror = thisTest.RunScriptSource(code);

            thisTest.Verify("r1", 111);
            thisTest.Verify("r2", -6);
        }
예제 #7
0
        public void T56_Defect_1454691()
        {
            string          code   = @"
import(""FFITarget.dll"");
b;
[Associative]
{
    x = 3;
	A1 = ClassFunctionality.ClassFunctionality(x);
	a1 = A1.IntVal;
	b = [Imperative]
	{
		if ( a1 < 10 )
		{
			return = A1.IntVal;;
		}
	return = A1.IntVal + 1;
	}
}";
            ExecutionMirror mirror = thisTest.RunScriptSource(code);

            thisTest.Verify("b", 3);
        }
예제 #8
0
파일: Function.cs 프로젝트: yaoclee/Dynamo
        public void T016_Associative_Function_ModifyArgumentInsideFunctionDoesNotAffectItsValue()
        {
            string          code   = @"
input;
result;
originalInput;
def Foo : int (a : int)
{
    a = a + 1;
    return = a;
}
[Associative]
{
	input = 3;
	result = Foo(input); 
	originalInput = input;
}";
            ExecutionMirror mirror = thisTest.RunScriptSource(code);

            thisTest.Verify("input", 3);
            thisTest.Verify("result", 4);
            thisTest.Verify("originalInput", 3);
        }
예제 #9
0
        public void T39_Defect_1452951_1()
        {
            string          code   = @"
x;
[Imperative]
{
	def foo ( a : int[])
	{
	    a[1] = 4;
		return = a;
	}
	a = { 4,5 };
   
	[Associative]
	{
	   x = foo(a);
	}
}";
            ExecutionMirror mirror = thisTest.RunScriptSource(code);

            object[] expectedResult = { 4, 4 };
            thisTest.Verify("x", expectedResult);
        }
예제 #10
0
        public void T026_LanguageBlockScope_ImperativeParallelImperative_Function()
        {
            //Assert.Throws(typeof(ProtoCore.Exceptions.CompileErrorsOccured), () =>
            //{
            string          src    = @"
	def foo : int(a : int, b : int)
	{
		return = a - b;
	}

z = [Imperative]	
{
	x = 20;
	y = 0;
	z = foo (x, y);
	return z;
}";
            ExecutionMirror mirror = thisTest.RunScriptSource(src);

            thisTest.Verify("z", 20);
            //});
            //Assert.Fail("Sprint 15: Rev 617: Scope: Need sensible error message to show the user that function called in a parallel language block is not defined. ");
        }
예제 #11
0
        public void T004_LanguageBlockScope_AssociativeNestedImperative()
        {
            string          src    = @"a_inner;b_inner;c_inner;
[Associative]
{
	a = 10;
	b = true;
	c = 20.1;
	i = [Imperative]	
	{
		a_inner = a;
		b_inner = b;
		c_inner = c;
        return [a_inner, b_inner, c_inner];
	}
	a_inner=i[0];b_inner=i[1];c_inner=i[2];
}";
            ExecutionMirror mirror = thisTest.RunScriptSource(src);

            thisTest.Verify("a_inner", 10);
            thisTest.Verify("b_inner", true);
            thisTest.Verify("c_inner", 20.1);
        }
예제 #12
0
        public void T003_LanguageBlockScope_ImperativeNestedAssociative()
        {
            string          src    = @"a_inner;
b_inner;
c_inner;
[Imperative]
{
	a = 10;
	b = true;
	c = 20.1;
	[Associative]	
	{
		a_inner = a;
		b_inner = b;
		c_inner = c;
	}
}";
            ExecutionMirror mirror = thisTest.RunScriptSource(src);

            thisTest.Verify("a_inner", 10);
            thisTest.Verify("b_inner", true);
            thisTest.Verify("c_inner", 20.1);
        }
예제 #13
0
        public void T012_LanguageBlockScope_ImperativeParallelImperative()
        {
            string          src    = @"aI; bI; cI;
[Imperative]
{
	a = 10;
	b = true;
	c = 20.1;
	
}
[Imperative]	
{
	aI = a;
	bI = b;
	cI = c;
	
}";
            ExecutionMirror mirror = thisTest.RunScriptSource(src);

            thisTest.Verify("aI", null);
            thisTest.Verify("bI", null);
            thisTest.Verify("cI", null);
        }
예제 #14
0
        public void T011_LanguageBlockScope_AssociativeParallelAssociative()
        {
            string          src    = @"aA;bA;cA;
[Associative]
{
	a = 10;
	b = true;
	c = 20.1;
	
}
[Associative]	
{
	aA = a;
	bA = b;
	cA = c;
	
}";
            ExecutionMirror mirror = thisTest.RunScriptSource(src);

            thisTest.Verify("aA", null);
            thisTest.Verify("bA", null);
            thisTest.Verify("cA", null);
        }
예제 #15
0
        public void T05_ClassMemerVarAsFunctionPointerDefaultArg()
        {
            string          code   = @"
class A
{
	x:var;
	constructor A()
	{
		x = foo;
	}
}
def foo:double(x:int, y:double = 2.0)
{
	return = x + y;
}
a = A.A();
b = a.x(3,2.0);	//b=5.0;
c = a.x(2, 4.0);	//c = 6.0"    ;
            ExecutionMirror mirror = thisTest.RunScriptSource(code);
            object          b      = 5.0;

            thisTest.Verify("b", b);
        }
예제 #16
0
        public void T11_TestForLoopWithSingleton()
        {
            string          src    = @"x;
[Imperative]
{
	a = {1};
	b = 1;
	x = 0;
 
	for ( y in a )
	{
		x = x + 1;
	}
 
	for ( y in b )
	{
		x = x + 1;
	}
} ";
            ExecutionMirror mirror = thisTest.RunScriptSource(src);

            Assert.IsTrue((Int64)mirror.GetValue("x").Payload == 2);
        }
예제 #17
0
        public void T26_NestedFunctionPointer()
        {
            string          code   = @"
def foo(x)
{
    return = 2 * x;
}
def bar(x)
{
    return = 3 * x;
}
def ding(x, f1:var, f2:var)
{
    return = f1(f2(x));
}
x = 1;
r = ding(x, foo, bar);
x = 2;
";
            ExecutionMirror mirror = thisTest.RunScriptSource(code);

            thisTest.Verify("r", 12);
        }
예제 #18
0
        public void T27_TestCallingFunctionInsideForLoop()
        {
            string          src    = @"x;
[Imperative]
{
	def function1 : double ( a : double )
	{		
		return = a + 0.7;
	}
	
	a = { 1.3, 2.3, 3.3, 4.3 };
	
	x = 3;
	
	for ( i in a )
	{	
		x = x + function1( i );
	}
}";
            ExecutionMirror mirror = thisTest.RunScriptSource(src);

            Assert.IsTrue((double)mirror.GetValue("x").Payload == 17);
        }
예제 #19
0
        public void T04_GlobalFunctionInImperBlk()
        {
            string          code   = @"
a;
b;
c;
[Imperative]
{
	def foo:double(x:int, y:double = 2.0)
	{
		return = x + y;
	}
	a = foo;
	b = foo(3); //b=5.0;
	c = foo(2, 4.0); //c = 6.0
}";
            ExecutionMirror mirror = thisTest.RunScriptSource(code);
            object          b      = 5.0;
            object          c      = 6.0;

            thisTest.Verify("b", b);
            thisTest.Verify("c", c);
        }
예제 #20
0
파일: GCTest.cs 프로젝트: Steell/Dynamo
        public void T11_TestGCLangBlkInFunction()
        {
            string          code   = @"
import(""DisposeVerify.ds"");
def foo : A(a : A)
{
	aaa = A.A();
	[Imperative]
	{
		aaaa = aaa;
		c = a;
	}
	return = aaa;
}
DisposeVerify.x = 1;
aa = A.A();
bb = foo(aa);
v1 = DisposeVerify.x; // 2
";
            ExecutionMirror mirror = thisTest.RunScriptSource(code, "", testCasePath);

            thisTest.Verify("v1", 1);
        }
예제 #21
0
        public void T62_Defect_1456721()
        {
            string          code   = @"
b = true;
a = 2 * b;
c = 3;
b1 = null;
a1 = 2 * b1;
c1 = 3;
a2 = 1 + true;
b2 = 2 * true;
c2 = 3  - true;
";
            ExecutionMirror mirror = thisTest.RunScriptSource(code);

            thisTest.Verify("c", 3, 0);
            thisTest.Verify("c1", 3, 0);
            thisTest.Verify("a", null);
            thisTest.Verify("a1", null);
            thisTest.Verify("a2", null);
            thisTest.Verify("b2", null);
            thisTest.Verify("c2", null);
        }
예제 #22
0
        public void Test_4_20_zipped_collection()
        {
            string          errmsg = "";
            string          code   = @"// Current limitation : 
a = {3, 4, 5};
b = {2, 6};
c = a + b ; // { 5, 10, null}; // Here the length of the resulting variable [c] will be based on the length of the first
//collection encountered [in this case a]
d = b + a; // { 5, 10}; // Here the length of the resulting variable [d] will be based on the length of the first
// collection encountered [in this case b]
// Workaround :
//def sum(a, b)
//{
  //return = a + b;
//}
//d = sum(a, b); // {5, 10}";
            ExecutionMirror mirror = thisTest.VerifyRunScriptSource(code, errmsg);

            thisTest.Verify("a", new object[] { 3, 4, 5 });
            thisTest.Verify("b", new object[] { 2, 6 });
            thisTest.Verify("c", new object[] { 5, 10 });
            thisTest.Verify("c", new object[] { 5, 10 });
        }
예제 #23
0
        public void T26_Defect_1450854()
        {
            string          src    = @"[Imperative]
{
    a = 1;
    b = 2;
    c = 0;
	
    if (3 == a ^ b )
    {
        c = 3;
    }
    else
    {
        c = 0;
    }	
		
} 
";
            ExecutionMirror mirror = thisTest.RunScriptSource(src);

            thisTest.Verify("c", 3);
        }
예제 #24
0
        public void T001_Inline_Using_Function_Call()
        {
            string src = @"
	def fo1 : int(a1 : int)
	{
		return a1 * a1;
	}
i = [Imperative]
{
	a	=	10;				
	b	=	20;
				
	smallest1   =   a	<   b   ?   a	:	b;
	largest1	=   a	>   b   ?   a	:	b;
	d = fo1(a);
	smallest2   =   (fo1(a))	<   (fo1(b))  ?   (fo1(a))	:	(fo1(a));	//100
	largest2	=   (fo1(a)) >   (fo1(b))  ?   (fo1(a))	:	(fo1(b)); //400
    return [smallest2, largest2];
}
";
            ExecutionMirror mirror = thisTest.RunScriptSource(src);
            thisTest.Verify("i", new[] {100, 400});
        }
예제 #25
0
        public void T25_TestUsingMathematicalExpr()
        {
            string          src    = @"c1;
c2;
c3;
c4;
[Associative]
{
  a = 3.0;
  b = 2;
  c1 = a + b; 
  c2 = a - b;
  c3 = a * b;
  c4 = a / b; 
}
";
            ExecutionMirror mirror = thisTest.RunScriptSource(src);

            thisTest.Verify("c1", 5);
            thisTest.Verify("c2", 1);
            thisTest.Verify("c3", 6);
            thisTest.Verify("c4", 1.5);
        }
예제 #26
0
        public void T22_Defect_1467166_3()
        {
            String code =
@"
def foo()
{
    return null;
}
i = [Imperative] 
{
   x1 = null == null ? 1 : 0;
   x2 = null != null ? 1 : 0;
   x3 = null == a ? 1 : 0;
   x4 = foo2(1) == a ? 1 : 0;
   x5 = foo() == null ? 1 : 0;
   return [x1, x2, x3, x4, x5];
}
";
            ProtoScript.Runners.ProtoScriptRunner fsr = new ProtoScript.Runners.ProtoScriptRunner();
            String errmsg = "";
            ExecutionMirror mirror = thisTest.VerifyRunScriptSource(code, errmsg);
            thisTest.Verify("i", new[] {1, 0, 1, 1, 1});
        }
예제 #27
0
        public void T62_Defect_1456721()
        {
            string          code   = @"
b = true;
a = 2 * b;
c = 3;
b1 = null;
a1 = 2 * b1;
c1 = 3;
a2 = 1 + true;
b2 = 2 * true;
c2 = 3  - true;
";
            ExecutionMirror mirror = thisTest.RunScriptSource(code);

            thisTest.Verify("c", 3, 0);
            thisTest.Verify("c1", 3, 0);
            Assert.IsTrue(mirror.GetValue("a").DsasmValue.optype == ProtoCore.DSASM.AddressType.Null);
            Assert.IsTrue(mirror.GetValue("a1").DsasmValue.optype == ProtoCore.DSASM.AddressType.Null);
            Assert.IsTrue(mirror.GetValue("a2").DsasmValue.optype == ProtoCore.DSASM.AddressType.Null);
            Assert.IsTrue(mirror.GetValue("b2").DsasmValue.optype == ProtoCore.DSASM.AddressType.Null);
            Assert.IsTrue(mirror.GetValue("c2").DsasmValue.optype == ProtoCore.DSASM.AddressType.Null);
        }
예제 #28
0
        public void UpdateMemberArray2()
        {
            String code =
                @"
class C
{
    x;
    constructor C()
    {
        x = {{1,2,3},{10,20,30}};
    }
}
i = 0;
j = 1;
p = C.C();
g = C.C();
a = p.x[i][j] + g.x[j][2];
g.x = {{1},{100,200,300,400}}; 
";
            ExecutionMirror mirror = thisTest.RunScriptSource(code);

            thisTest.Verify("a", 302);
        }
예제 #29
0
        public void T25_TestUsingMathematicalExpr()
        {
            string          src    = @"c1;
c2;
c3;
c4;
[Imperative]
{
  a = 3.0;
  b = 2;
  c1 = a + b; 
  c2 = a - b;
  c3 = a * b;
  c4 = a / b; 
}
";
            ExecutionMirror mirror = thisTest.RunScriptSource(src);

            Assert.IsTrue((double)mirror.GetValue("c1").Payload == 5);
            Assert.IsTrue((double)mirror.GetValue("c2").Payload == 1);
            Assert.IsTrue((double)mirror.GetValue("c3").Payload == 6);
            Assert.IsTrue((double)mirror.GetValue("c4").Payload == 1.5);
        }
예제 #30
0
        public void T14_TestUsingMathAndLogicalExpr()
        {
            string          src    = @"
i = [Imperative]
{
  a = 3;
  b = -4;
  b = a + b; 
  b = a - b;
  b = a * b;
  b = a / b; 
  
  c1 = 1 && 2;
  c2 = 1 && 0;
  c3 = null && true;
  return [a, b, c1, c2, c3];
}
";
            ExecutionMirror mirror = thisTest.RunScriptSource(src);
            var             arr    = new object[] { 3, 0, true, false, null };

            thisTest.Verify("i", arr);
        }