Esempio n. 1
0
        public void DifferenceFactorInfo()
        {
            FactorManager.FactorInfo info = FactorManager.GetFactorInfo(new MethodReference(typeof(Factor), "Difference").GetMethodInfo());
            Console.WriteLine(info);
            Assert.True(info.IsDeterministicFactor);
            IDictionary <string, Type> parameterTypes = new Dictionary <string, Type>();

            parameterTypes["Difference"] = typeof(Gaussian);
            parameterTypes["A"]          = typeof(Gaussian);
            parameterTypes["B"]          = typeof(Gaussian);
            //parameterTypes["result"] = typeof(Gaussian);
            MessageFcnInfo fcninfo = info.GetMessageFcnInfo(factorManager, "AverageConditional", "Difference", parameterTypes);

            Assert.False(fcninfo.PassResult);
            Assert.False(fcninfo.PassResultIndex);
            Assert.Equal(2, fcninfo.Dependencies.Count);
            Assert.Equal(2, fcninfo.Requirements.Count);
            Console.WriteLine(fcninfo);

            Console.WriteLine("Parameter types:");
            Console.WriteLine(StringUtil.CollectionToString(fcninfo.GetParameterTypes(), ","));

            Console.WriteLine();
            try
            {
                fcninfo = info.GetMessageFcnInfo(factorManager, "Rubbish", "Difference", parameterTypes);
                Assert.True(false, "Did not throw an exception");
            }
            catch (ArgumentException ex)
            {
                if (!ex.Message.Contains("MissingMethodException"))
                {
                    Assert.True(false, "Correctly threw exception, but with wrong message");
                }
                Console.WriteLine("Different exception: " + ex);
            }

            Console.WriteLine();
            try
            {
                parameterTypes["result"] = typeof(double);
                fcninfo = info.GetMessageFcnInfo(factorManager, "AverageConditional", "Difference", parameterTypes);
                Assert.True(false, "Did not throw an exception");
            }
            catch (ArgumentException ex)
            {
                Console.WriteLine("Correctly failed with exception: " + ex);
            }

            Console.WriteLine();
            Console.WriteLine("All messages to A:");
            int count = 0;

            foreach (MessageFcnInfo fcninfo2 in info.GetMessageFcnInfos(null, "A", null))
            {
                Console.WriteLine(fcninfo2);
                CheckMessageFcnInfo(fcninfo2, info);
                count++;
            }
            //Assert.Equal(8, count);

            Console.WriteLine();
            Console.WriteLine("All messages to Difference:");
            count = 0;
            foreach (MessageFcnInfo fcninfo2 in info.GetMessageFcnInfos(null, "Difference", null))
            {
                Console.WriteLine(fcninfo2);
                CheckMessageFcnInfo(fcninfo2, info);
                count++;
            }
            Assert.Equal(8, count);

            Console.WriteLine();
            Console.WriteLine("All AverageConditionals:");
            count = 0;
            foreach (MessageFcnInfo fcninfo2 in info.GetMessageFcnInfos("AverageConditional", null, null))
            {
                Console.WriteLine(fcninfo2);
                CheckMessageFcnInfo(fcninfo2, info);
                count++;
            }
            Assert.Equal(12, count);

            Console.WriteLine();
            Console.WriteLine("All MessageFcnInfos:");
            count = 0;
            foreach (MessageFcnInfo fcninfo2 in info.GetMessageFcnInfos())
            {
                Console.WriteLine(fcninfo2);
                CheckMessageFcnInfo(fcninfo2, info);
                count++;
            }
            //Assert.Equal(26, count);
        }