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 option = new Option() as IOption; var measure = new ConstrainedWeightedMetrics(); option.Measure = measure; (option as Option).SetAction(new MockAction()); var cd1 = new OptionConsideration1(); var cd2 = new OptionConsideration2(); cd1.NameId = "cd1"; cd2.NameId = "cd2"; option.AddConsideration(cd1); option.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(); option.Consider(_optionContext); Assert.That(option.Utility.Value, Is.EqualTo(cNorm).Within(1e-6f)); }
public void ConstructorTest2([Values(-1.0f, 0.0f, 1.0f, 10f, 100000f)] float pNorm) { var m = new ConstrainedWeightedMetrics(pNorm); Assert.That(m.LowerBound, Is.EqualTo(Zero).Within(Tolerance)); Assert.That(m.PNorm, Is.EqualTo(pNorm.Clamp(m.PNormMin, m.PNormMax)).Within(Tolerance)); }
public void ConstructorTest1() { var m = new ConstrainedWeightedMetrics(); Assert.IsNotNull(m); Assert.That(m.LowerBound, Is.EqualTo(Zero).Within(Tolerance)); Assert.That(m.PNorm, Is.EqualTo(2.0f).Within(Tolerance)); }
public void ZeroSizeListTest() { var m = new ConstrainedWeightedMetrics(); var list = new List <Utility>(); float aVal = m.Calculate(list); Assert.That(aVal, Is.EqualTo(Zero).Within(Tolerance)); }
public void ConstructorTest3( [Values(-1.0f, 2.65f, 100000f)] float pNorm, [Values(-1.0f, 0.1f, 0.9f, 2.0f)] float lowerBound) { var m = new ConstrainedWeightedMetrics(pNorm, lowerBound); Assert.That(m.LowerBound, Is.EqualTo(lowerBound.Clamp01()).Within(Tolerance)); Assert.That(m.PNorm, Is.EqualTo(pNorm.Clamp(m.PNormMin, m.PNormMax)).Within(Tolerance)); }
public void ConstructorTest1() { var option = new Option(); var measure = new ConstrainedWeightedMetrics(); option.Measure = measure; Assert.IsNotNull(option); Assert.That(option.Weight, Is.EqualTo(1.0f).Within(1e-6f)); }
public void ZeroValuesTest() { var m = new ConstrainedWeightedMetrics(); var list = MeasureTestsHelper.RandomUtilityWeightList(_rnd.Next(1, MaxVecLen), 0.0f); float aVal = m.Calculate(list); float cVal = MeasureTestsHelper.CalculateConstrainedWeightedMetricsNorm(list); Assert.That(aVal, Is.EqualTo(Zero).Within(Tolerance)); Assert.That(cVal, Is.EqualTo(Zero).Within(Tolerance)); }
public void ConstructorTest2( [Range(0.0f, 10.0f, 0.5f)] float pNorm) { var option = new Option(); var measure = new ConstrainedWeightedMetrics(); measure.PNorm = pNorm; option.Measure = measure; Assert.IsNotNull(option); Assert.That(measure.PNorm, Is.EqualTo(pNorm.Clamp <float>(1.0f, 10000.0f)).Within(1e-6f)); Assert.That(option.Weight, Is.EqualTo(1.0f).Within(1e-6f)); }
public void ConstructorTest3( [Range(0.0f, 5.0f, 1.0f)] float pNorm, [Range(-1.0f, 2.0f, 0.2f)] float threshold) { var option = new Option(); var measure = new ConstrainedWeightedMetrics(); measure.LowerBound = threshold; measure.PNorm = pNorm; option.Measure = measure; Assert.IsNotNull(option); Assert.That(measure.PNorm, Is.EqualTo(pNorm.Clamp <float>(1.0f, 10000.0f)).Within(1e-6f)); Assert.That(measure.LowerBound, Is.EqualTo(threshold.Clamp01()).Within(1e-6f)); Assert.That(option.Weight, Is.EqualTo(1.0f).Within(1e-6f)); }
public void CalculateTest( [Values(-100f, -1f, 0f, 1f, 5f, 10f, 100f, 1000000f)] float p, [Values(-1f, 0f, 0.5f, 0.75f, 1f, 2f)] float lowerBound) { var m = new ConstrainedWeightedMetrics(p, lowerBound); var cLb = lowerBound.Clamp01(); var cP = p.Clamp(m.PNormMin, m.PNormMax); Assert.That(m.PNorm, Is.EqualTo(p.Clamp(m.PNormMin, m.PNormMax)).Within(Tolerance)); var list = MeasureTestsHelper.RandomUtilityList(_rnd.Next(1, MaxVecLen)); float aVal = m.Calculate(list); float cVal = MeasureTestsHelper.CalculateConstrainedWeightedMetricsNorm(list, cP, cLb); Assert.That(aVal, Is.EqualTo(cVal).Within(Tolerance)); Assert.That(aVal <= One); Assert.That(aVal >= Zero); }