Ejemplo n.º 1
0
        public void LoadAndUseFiboModule()
        {
            Machine machine = new Machine();

            var module = machine.LoadModule("fibo");

            Assert.IsNotNull(module);
            Assert.IsNotNull(module.Context);
            Assert.AreEqual("fibo", module.Name);

            Assert.IsNotNull(module.Context.GetValue("fibo/1"));
            Assert.IsInstanceOfType(module.Context.GetValue("fibo/1"), typeof(MultiFunction));

            var ffunc = (MultiFunction)module.Context.GetValue("fibo/1");

            Assert.AreEqual(1, ffunc.Apply(null, new object[] { 0 }));
            Assert.AreEqual(1, ffunc.Apply(null, new object[] { 1 }));
            Assert.AreEqual(2, ffunc.Apply(null, new object[] { 2 }));
            Assert.AreEqual(3, ffunc.Apply(null, new object[] { 3 }));
            Assert.AreEqual(5, ffunc.Apply(null, new object[] { 4 }));
        }
Ejemplo n.º 2
0
        public void LoadAndUseTailModuleWithTailRecursion()
        {
            Machine machine = new Machine();

            var module = machine.LoadModule("tail");

            Assert.IsNotNull(module);
            Assert.IsNotNull(module.Context);
            Assert.AreEqual("tail", module.Name);

            Assert.IsNotNull(module.Context.GetValue("tail/2"));
            Assert.IsInstanceOfType(module.Context.GetValue("tail/2"), typeof(MultiFunction));

            var ffunc = (MultiFunction)module.Context.GetValue("tail/2");

            var result = ffunc.Apply(null, new object[] { 2, 1 });

            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(DelayedCall));

            Assert.AreEqual(3, Machine.ExpandDelayedCall(result));
        }
Ejemplo n.º 3
0
        public void LoadAreaServer()
        {
            Machine machine = new Machine();

            var module = machine.LoadModule("area_server");

            Assert.IsNotNull(module);
            Assert.IsNotNull(module.Context);
            Assert.AreEqual("area_server", module.Name);

            Assert.IsNotNull(module.Context.GetValue("loop/0"));

            machine.RootContext.SetValue(module.Name, module);

            this.EvaluateExpression("Pid = spawn(fun() -> area_server:loop() end).", machine.RootContext);

            Process process = new Process();
            Process.Current = process;

            this.EvaluateExpression("Pid ! {self(), rectangle, 6, 10}.", machine.RootContext);
            Assert.AreEqual(60, process.GetMessage());

            this.EvaluateExpression("Pid ! {self(), circle, 23}.", machine.RootContext);
            Assert.AreEqual(3.14159 * 23 * 23, process.GetMessage());

            this.EvaluateExpression("Pid ! stop.", machine.RootContext);
        }
Ejemplo n.º 4
0
        public void LoadArithModule()
        {
            Machine machine = new Machine();

            var module = machine.LoadModule("arith");

            Assert.IsNotNull(module);
            Assert.IsNotNull(module.Context);
            Assert.AreEqual("arith", module.Name);

            Assert.IsNotNull(module.Context.GetValue("add/2"));
            Assert.IsInstanceOfType(module.Context.GetValue("add/2"), typeof(Function));

            Assert.IsNotNull(module.Context.GetValue("subtract/2"));
            Assert.IsInstanceOfType(module.Context.GetValue("subtract/2"), typeof(Function));

            Assert.IsNotNull(module.Context.GetValue("multiply/2"));
            Assert.IsInstanceOfType(module.Context.GetValue("multiply/2"), typeof(Function));

            Assert.IsNotNull(module.Context.GetValue("divide/2"));
            Assert.IsInstanceOfType(module.Context.GetValue("divide/2"), typeof(Function));
        }