Esempio n. 1
0
        public void ConsiderTest1(
            [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 c = ConsiderationConstructor.ConstrainedWeightedMetrics();

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

            cd1.NameId = "cd1";
            cd2.NameId = "cd2";
            c.AddConsideration(cd1);
            c.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();

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

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

            Assert.IsNotNull(c);
            Assert.IsNotNull(c.Measure);
            Assert.That(c.Measure is ConstrainedWeightedMetrics);
        }
Esempio n. 4
0
        public void ConstructorTest2(
            [Range(0.0f, 10.0f, 0.5f)] float pNorm)
        {
            var c = ConsiderationConstructor.ConstrainedWeightedMetrics(pNorm);

            Assert.IsNotNull(c);
            Assert.That((c.Measure as ConstrainedWeightedMetrics).PNorm,
                        Is.EqualTo(pNorm.Clamp <float>(1.0f, 10000.0f)).Within(Tolerance));
            Assert.That(c.Weight, Is.EqualTo(1.0f).Within(1e-6f));
        }
Esempio n. 5
0
        public void ConstructorTest3(
            [Range(0.0f, 5.0f, 1.0f)] float pNorm,
            [Range(-1.0f, 2.0f, 0.2f)] float threshold)
        {
            var c = ConsiderationConstructor.ConstrainedWeightedMetrics(pNorm, threshold);

            Assert.IsNotNull(c);
            Assert.That((c.Measure as ConstrainedWeightedMetrics).PNorm,
                        Is.EqualTo(pNorm.Clamp <float>(1.0f, 10000.0f)).Within(Tolerance));
            Assert.That((c.Measure as ConstrainedWeightedMetrics).LowerBound,
                        Is.EqualTo(threshold.Clamp01()).Within(Tolerance));
            Assert.That(c.Weight, Is.EqualTo(1.0f).Within(Tolerance));
        }
        public void ConstrainedWeightedMetricsNameConstructor()
        {
            var cc = new ConsiderationCollection();
            var c  = ConsiderationConstructor.ConstrainedWeightedMetrics("name", cc, 3.0f, 0.5f);

            Assert.IsNotNull(c);
            Assert.IsNotNull(c.Measure);
            Assert.That(c.Measure is ConstrainedWeightedMetrics);
            var m = c.Measure as ConstrainedWeightedMetrics;

            Assert.That(m.LowerBound, Is.EqualTo(0.5f));
            Assert.That(m.PNorm, Is.EqualTo(3.0f));
            Assert.That(cc.Contains("name"));
        }