Esempio n. 1
0
        public void ConsiderTest(
            [Range(0.0f, 10.0f, 2.5f)] float xval1,
            [Range(0.0f, 10.0f, 2.5f)] float xval2)
        {
            // NEVER use the derived class to call
            // Consider otherwise the machinery in the base
            // class is never called!
            var consideration = ConsiderationConstructor.WeightedMetrics();

            var cd1 = new OptionConsideration1();
            var cd2 = new OptionConsideration2();

            cd1.NameId = "cd1";
            cd2.NameId = "cd2";
            consideration.AddConsideration(cd1);
            consideration.AddConsideration(cd2);
            _optionContext.XVal1 = xval1;
            _optionContext.XVal2 = xval2;
            cd1.Consider(_optionContext);
            cd2.Consider(_optionContext);
            var cUtil1 = cd1.Utility;
            var cUtil2 = cd2.Utility;
            var cUtilL = new List <Utility>();

            cUtilL.Add(cUtil1);
            cUtilL.Add(cUtil2);
            var cNorm = cUtilL.WeightedMetrics();

            consideration.Consider(_optionContext);
            Assert.That(consideration.Utility.Value, Is.EqualTo(cNorm).Within(Tolerance));
        }
Esempio n. 2
0
        public void ConstructorTest2()
        {
            var c = ConsiderationConstructor.WeightedMetrics(4.0f);

            Assert.IsNotNull(c);
            Assert.AreEqual(4.0f, (c.Measure as WeightedMetrics).PNorm);
        }
Esempio n. 3
0
        public void ConstructorTest1()
        {
            var c = ConsiderationConstructor.WeightedMetrics();

            Assert.IsNotNull(c);
            Assert.That(c.Weight, Is.EqualTo(1.0f).Within(Tolerance));
        }
        public void WeightedMetricsConstructor()
        {
            var c = ConsiderationConstructor.WeightedMetrics();

            Assert.IsNotNull(c);
            Assert.IsNotNull(c.Measure);
            Assert.That(c.Measure is WeightedMetrics);
        }
        public void WeightedMetricsNameConstructor()
        {
            var cc = new ConsiderationCollection();
            var c  = ConsiderationConstructor.WeightedMetrics("name", cc);

            Assert.IsNotNull(c);
            Assert.IsNotNull(c.Measure);
            Assert.That(c.Measure is WeightedMetrics);
            Assert.That(cc.Contains("name"));
        }
        public void CloneProducesSameUtilityTest([Range(0.0f, 1.0f, 0.1f)] float util)
        {
            _considerations.Clear();
            var           c       = ConsiderationConstructor.WeightedMetrics("name", _considerations, 3.0f);
            CustomContext context = new CustomContext();

            context.BaseUtility = new Utility(util, 0.8f);
            var b1 = new BasicConsideration("b1", _considerations);
            var b2 = new BasicConsideration("b2", _considerations);

            c.AddConsideration("b1");
            c.AddConsideration("b2");
            var cc = c.Clone() as ICompositeConsideration;

            c.Consider(context);
            cc.Consider(context);
            Assert.AreEqual(c.Utility.Value, cc.Utility.Value);
            Assert.AreEqual(c.Utility.Weight, cc.Utility.Weight);
        }