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)); }
public void ConsiderTest2( [Range(0.0f, 10.0f, 2.5f)] float xval1, [Range(0.0f, 10.0f, 2.5f)] float xval2, [Values(0.1f, 0.5f, 0.8f)] float threshold) { // NEVER use the derived class to call // Consider otherwise the machinery in the base // class is never called! var c = ConsiderationConstructor.ConstrainedChebyshev(threshold); 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.Chebyshev(); if (cUtil1.Combined < threshold || cUtil2 < threshold) { cNorm = 0.0f; } c.Consider(_optionContext); Assert.That(c.Utility.Value, Is.EqualTo(cNorm).Within(Tolerance)); }