예제 #1
0
        public void CreateAndExecuteNativeFunctionalMethod()
        {
            int count = 0;
            FunctionalMethod method = new FunctionalMethod((Machine machine, object x, object[] args) => ++count);

            Assert.IsNull(method.Name);
            Assert.IsNull(method.Behavior);

            object result = method.ExecuteNative(null, null, null);

            Assert.AreEqual(1, count);
            Assert.AreEqual(1, result);
        }
예제 #2
0
        public void CreateAndInvokeAgentTwice()
        {
            ManualResetEvent handle1 = new ManualResetEvent(false);
            ManualResetEvent handle2 = new ManualResetEvent(false);
            int count = 0;
            AgentObject agent = new AgentObject();

            IMethod method = new FunctionalMethod((x, y, args) =>
            {
                count++;
                return ((ManualResetEvent)args[0]).Set();
            });

            agent.ExecuteMethod((Machine)null, method, new object[] { handle1 });
            agent.ExecuteMethod((Machine)null, method, new object[] { handle2 });
            handle1.WaitOne();
            handle2.WaitOne();
            Assert.AreEqual(2, count);
        }
예제 #3
0
 static DotNetObject()
 {
     binaryMethods["+"] = new FunctionalMethod((machine, obj, args) => ObjectOperators.Add(obj, args[0]));
     binaryMethods["-"] = new FunctionalMethod((machine, obj, args) => ObjectOperators.Substract(obj, args[0]));
     binaryMethods["*"] = new FunctionalMethod((machine, obj, args) => ObjectOperators.Multiply(obj, args[0]));
     binaryMethods["/"] = new FunctionalMethod((machine, obj, args) => ObjectOperators.Divide(obj, args[0]));
     binaryMethods["<"] = new FunctionalMethod((machine, obj, args) => ObjectOperators.Less(obj, args[0]));
     binaryMethods[">"] = new FunctionalMethod((machine, obj, args) => ObjectOperators.Greater(obj, args[0]));
     binaryMethods["<="] = new FunctionalMethod((machine, obj, args) => ObjectOperators.LessEqual(obj, args[0]));
     binaryMethods[">="] = new FunctionalMethod((machine, obj, args) => ObjectOperators.GreaterEqual(obj, args[0]));
     binaryMethods["="] = new FunctionalMethod((machine, obj, args) => ObjectOperators.Equals(obj, args[0]));
     binaryMethods["~="] = new FunctionalMethod((machine, obj, args) => !ObjectOperators.Equals(obj, args[0]));
     binaryMethods["=="] = new FunctionalMethod((machine, obj, args) => ObjectOperators.Same(obj, args[0]));
     binaryMethods["~~"] = new FunctionalMethod((machine, obj, args) => !ObjectOperators.Same(obj, args[0]));
     binaryMethods["nat"] = new FunctionalMethod(AtMethod);
     binaryMethods["nget"] = new FunctionalMethod(GetMethod);
     unaryMethods["minus"] = new FunctionalMethod((machine, obj, args) => ObjectOperators.Negate(obj));
     ternaryMethods["natput"] = new FunctionalMethod(AtPutMethod);
     ternaryMethods["nsetput"] = new FunctionalMethod(SetPutMethod);
     ternaryMethods["ngetat"] = new FunctionalMethod(GetAtMethod);
     cuaternaryMethods["nsetatput"] = new FunctionalMethod(SetAtPutMethod);
 }