public void ConstructorTest1() { var c = ConsiderationConstructor.ConstrainedWeightedMetrics(); Assert.IsNotNull(c); Assert.That(c.Weight, Is.EqualTo(1.0f).Within(Tolerance)); }
public void ConstructorTest() { var c = ConsiderationConstructor.Chebyshev(); Assert.IsNotNull(c); Assert.That(c.Weight, Is.EqualTo(1.0f).Within(Tolerance)); }
public void ConstructorTest2() { var c = ConsiderationConstructor.WeightedMetrics(4.0f); Assert.IsNotNull(c); Assert.AreEqual(4.0f, (c.Measure as WeightedMetrics).PNorm); }
public void ConstuctorTest2([Range(-1.0f, 2.0f, 0.1f)] float threshold) { var c = ConsiderationConstructor.ConstrainedChebyshev(threshold); Assert.That(c.Weight, Is.EqualTo(1.0f).Within(Tolerance)); Assert.That((c.Measure as ConstrainedChebyshev).LowerBound, Is.EqualTo(threshold.Clamp01()).Within(Tolerance)); }
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 ConstructorTest() { _considerations.Clear(); var c = ConsiderationConstructor.Chebyshev("name", _considerations); Assert.That(_considerations.Contains("name")); }
public void ConstrainedChebyshevConstructor() { var c = ConsiderationConstructor.ConstrainedChebyshev(); Assert.IsNotNull(c); Assert.IsNotNull(c.Measure); Assert.That(c.Measure is ConstrainedChebyshev); }
public void MultiplicativeConstructor() { var c = ConsiderationConstructor.Multiplicative(); Assert.IsNotNull(c); Assert.IsNotNull(c.Measure); Assert.That(c.Measure is MultiplicativePseudoMeasure); }
public void MeasureInputConstructor(IMeasure measure) { var c = ConsiderationConstructor.Create(measure); Assert.IsNotNull(c); Assert.IsNotNull(c.Measure); Assert.That(c.Measure, Is.EqualTo(measure)); }
public void CloneHasSameNameIdTest() { _considerations.Clear(); var c = ConsiderationConstructor.Chebyshev("name", _considerations); var cc = c.Clone(); Assert.That(c.NameId == cc.NameId); }
public void EmptyOrNullConsiderationIdNotAcceptableTest() { _considerations.Clear(); var c = ConsiderationConstructor.Chebyshev("name", _considerations); Assert.That(c.AddConsideration("") == false); Assert.That(c.AddConsideration((string)null) == false); }
public void WeightedMetricsConstructor() { var c = ConsiderationConstructor.WeightedMetrics(); Assert.IsNotNull(c); Assert.IsNotNull(c.Measure); Assert.That(c.Measure is WeightedMetrics); }
public void SameNameIdIsNotAddedTest() { _considerations.Clear(); var c = ConsiderationConstructor.Chebyshev("name", _considerations); var b1 = new BasicConsideration("b1", _considerations); Assert.That(c.AddConsideration("b1")); Assert.That(c.AddConsideration("b1") == false); }
public void MultiplicativeNameConstructor() { var cc = new ConsiderationCollection(); var c = ConsiderationConstructor.Multiplicative("name", cc); Assert.IsNotNull(c); Assert.IsNotNull(c.Measure); Assert.That(c.Measure is MultiplicativePseudoMeasure); }
public void EnsureSettingDefaultUtilityAlsoSetsUtilityTest() { _considerations.Clear(); var c = ConsiderationConstructor.Chebyshev("name", _considerations); c.DefaultUtility = new Utility(0.4f, 0.5f); Assert.AreEqual(c.DefaultUtility.Value, c.Utility.Value); Assert.AreEqual(c.DefaultUtility.Weight, c.Utility.Weight); }
public void EnsureSameInstanceConsiderationIsNotAddedTest() { _considerations.Clear(); var c = ConsiderationConstructor.Chebyshev("name", _considerations); var b1 = new BasicConsideration("b1", _considerations); Assert.That(c.AddConsideration(b1)); Assert.That(c.AddConsideration(b1) == false); }
public void EnsureNullIsNotAcceptedByMeasureTest() { _considerations.Clear(); var c = ConsiderationConstructor.Chebyshev("name", _considerations); Assert.IsNotNull(c.Measure); c.Measure = null; Assert.IsNotNull(c.Measure); }
public void ChebyshevWithNameConstructor() { var cc = new ConsiderationCollection(); var c = ConsiderationConstructor.Chebyshev("name", cc); Assert.IsNotNull(c); Assert.IsNotNull(c.Measure); Assert.That(c.Measure is Chebyshev); Assert.That(cc.Contains("name")); }
public void CloneHasCollectionTest() { _considerations.Clear(); var c = ConsiderationConstructor.Chebyshev("name", _considerations); var cc = c.Clone() as ICompositeConsideration; var b1 = new BasicConsideration("b1", _considerations); Assert.That(c.AddConsideration("b1")); Assert.That(cc.AddConsideration("b1")); }
public void MeasureAndNameConstructor(IMeasure measure) { var cc = new ConsiderationCollection(); var c = ConsiderationConstructor.Create("name", cc, measure); Assert.IsNotNull(c); Assert.IsNotNull(c.Measure); Assert.That(c.Measure, Is.EqualTo(measure)); Assert.That(cc.Contains("name")); }
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)); }
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 ThrowsNameIdAlreadyExistsTest() { _considerations.Clear(); var c1 = ConsiderationConstructor.Chebyshev("name", _considerations); Assert.Throws <CompositeConsideration.NameIdAlreadyExistsInCollectionException>( () => ConsiderationConstructor .Chebyshev("name", _considerations)); }
public void ConstrainedChebyshevNameAndLowerBoundConstructor() { var cc = new ConsiderationCollection(); var c = ConsiderationConstructor.ConstrainedChebyshev("name", cc, 0.5f); Assert.IsNotNull(c); Assert.IsNotNull(c.Measure); Assert.That(c.Measure is ConstrainedChebyshev); var m = c.Measure as ConstrainedChebyshev; Assert.That(m.LowerBound, Is.EqualTo(0.5f)); Assert.That(cc.Contains("name")); }
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 EnsureCloneHasConsiderationsTest() { _considerations.Clear(); var c = ConsiderationConstructor.Chebyshev("name", _considerations); var b1 = new BasicConsideration("b1", _considerations); var b2 = new BasicConsideration("b2", _considerations); c.AddConsideration("b1"); c.AddConsideration("b2"); var cc = c.Clone() as ICompositeConsideration; Assert.That(cc.AddConsideration("b1") == false); Assert.That(cc.AddConsideration("b2") == false); }
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")); }
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); }
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)); }
public void ConstuctorTest1() { var c = ConsiderationConstructor.ConstrainedChebyshev(); Assert.That(c.Weight, Is.EqualTo(1.0f).Within(Tolerance)); }