Ejemplo n.º 1
0
        public void TestMultipleChildren()
        {
            var m1 = new Manager()
            {
                Name = "Manager1",
                Code = "using System;\r\nusing Models.Core;\r\nnamespace Models\r\n{\r\n[Serializable]\r\n" +
                       "public class Script1 : Model\r\n {\r\n " +
                       "public double A { get { return (1); } set { } }\r\n" +
                       "public double B { get { return (2); } set { } }\r\n }\r\n}\r\n"
            };
            var m2 = new Manager()
            {
                Name = "Manager2",
                Code = "using System;\r\nusing Models.Core;\r\nnamespace Models\r\n{\r\n[Serializable]\r\n" + "" +
                       "    public class Script2 : Model\r\n {\r\n" +
                       " public double A { get { return (3); } set { } }\r\n" +
                       " public double B { get { return (4); } set { } }\r\n }\r\n}\r\n"
            };

            report.VariableNames = new[]
            {
                "[Manager1].Script1.A as M1A",
                "[Manager2].Script2.A as M2A"
            };
            report.EventNames = new[]
            {
                "[Clock].DoReport"
            };
            simulation.Children.AddRange(new[] { m1, m2 });
            simulation.ParentAllDescendants();
            m1.OnCreated();
            m2.OnCreated();

            var runners = new[]
            {
                new Runner(simulation, runType: Runner.RunTypeEnum.MultiThreaded),
                new Runner(simulation, runType: Runner.RunTypeEnum.MultiProcess)
            };

            foreach (Runner runner in runners)
            {
                List <Exception> errors = runner.Run();
                if (errors != null && errors.Count > 0)
                {
                    throw errors[0];
                }

                double[] actual   = storage.Get <double>("M1A");
                double[] expected = storage.Get <double>("M2A");
                Assert.AreNotEqual(expected, actual);
            }
        }
Ejemplo n.º 2
0
        public void ReferenceAnotherReportVariable()
        {
            report.VariableNames = new string[]
            {
                "[Clock].Today.DayOfYear as n",
                "2 * n as 2n"
            };
            Runner           runner = new Runner(simulations);
            List <Exception> errors = runner.Run();

            if (errors != null && errors.Count > 0)
            {
                throw errors[0];
            }
            double[] actual   = storage.Get <double>("2n");
            double[] expected = new double[10] {
                2, 4, 6, 8, 10, 12, 14, 16, 18, 20
            };

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 3
0
        public void TestAllStatsBetweenVariableDates()
        {
            report.VariableNames = new string[]
            {
                "sum of [Clock].Today.DayOfYear from [Clock].StartDate to [Clock].Today as sum",
                "mean of [Clock].Today.DayOfYear from [Clock].StartDate to [Clock].Today as mean",
                "min of [Clock].Today.DayOfYear from [Clock].StartDate to [Clock].Today as min",
                "max of [Clock].Today.DayOfYear from [Clock].StartDate to [Clock].Today as max",
                "first of [Clock].Today.DayOfYear from [Clock].StartDate to [Clock].Today as first",
                "last of [Clock].Today.DayOfYear from [Clock].StartDate to [Clock].Today as last",
                "diff of [Clock].Today.DayOfYear from [Clock].StartDate to [Clock].Today as diff"
            };

            runner.Run();

            Assert.AreEqual(storage.Get <double>("sum"),
                            new double[] { 1, 3, 6, 10, 15, 21, 28, 36, 45, 55 });
            Assert.AreEqual(storage.Get <double>("mean"),
                            new double[] { 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5, 5.5 });
            Assert.AreEqual(storage.Get <double>("min"),
                            new double[] { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 });
            Assert.AreEqual(storage.Get <double>("max"),
                            new double[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
            Assert.AreEqual(storage.Get <double>("first"),
                            new double[] { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 });
            Assert.AreEqual(storage.Get <double>("last"),
                            new double[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
            Assert.AreEqual(storage.Get <double>("diff"),
                            new double[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 });
        }