本文整理汇总了C#中CalculationEngine.HasDependents方法的典型用法代码示例。如果您正苦于以下问题:C# CalculationEngine.HasDependents方法的具体用法?C# CalculationEngine.HasDependents怎么用?C# CalculationEngine.HasDependents使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CalculationEngine
的用法示例。
在下文中一共展示了CalculationEngine.HasDependents方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestRemove1
public void TestRemove1()
{
CalculationEngine ce = new CalculationEngine();
ExpressionContext context = new ExpressionContext();
VariableCollection variables = context.Variables;
ce.Add("a", "100", context);
ce.Add("b", "200", context);
ce.Add("c", "a + b", context);
ce.Add("d", "300", context);
ce.Add("e", "c + d", context);
ce.Remove("a");
// Only b and d should remain
Assert.AreEqual(2, ce.Count);
ce.Remove("b");
Assert.AreEqual(1, ce.Count);
ce.Remove("d");
Assert.AreEqual(0, ce.Count);
// b and d should have no dependents or precedents
Assert.IsFalse(ce.HasDependents("b"));
Assert.IsFalse(ce.HasDependents("d"));
Assert.IsFalse(ce.HasPrecedents("b"));
Assert.IsFalse(ce.HasPrecedents("d"));
}
示例2: TestDependencyManagement
public void TestDependencyManagement()
{
// Test that we are keeping accurate stats on our dependencies
CalculationEngine engine = new CalculationEngine();
ExpressionContext context = new ExpressionContext();
engine.Add("a", "100", context);
engine.Add("b", "100", context);
// Nothing should point to a and b
Assert.IsFalse(engine.HasPrecedents("a"));
Assert.IsFalse(engine.HasPrecedents("b"));
Assert.IsFalse(engine.HasDependents("a"));
Assert.IsFalse(engine.HasDependents("b"));
engine.Add("c", "a + b", context);
engine.Add("d", "a + c", context);
// a and b still have nothing pointing to them
Assert.IsFalse(engine.HasPrecedents("a"));
Assert.IsFalse(engine.HasPrecedents("b"));
// but they have dependents
Assert.IsTrue(engine.HasDependents("a"));
Assert.IsTrue(engine.HasDependents("b"));
// c and d have precedents
Assert.IsTrue(engine.HasPrecedents("d"));
Assert.IsTrue(engine.HasPrecedents("c"));
// and only c should have dependents
Assert.IsTrue(engine.HasDependents("c"));
Assert.IsFalse(engine.HasDependents("d"));
// test our counts
Assert.AreEqual(2, engine.GetDependents("a").Length);
Assert.AreEqual(1, engine.GetDependents("b").Length);
Assert.AreEqual(1, engine.GetDependents("c").Length);
Assert.AreEqual(0, engine.GetDependents("d").Length);
Assert.AreEqual(0, engine.GetPrecedents("a").Length);
Assert.AreEqual(0, engine.GetPrecedents("b").Length);
Assert.AreEqual(2, engine.GetPrecedents("c").Length);
Assert.AreEqual(2, engine.GetPrecedents("d").Length);
engine.Remove("d");
Assert.IsFalse(engine.HasDependents("c"));
Assert.IsFalse(engine.HasDependents("d"));
Assert.IsFalse(engine.HasPrecedents("d"));
Assert.IsTrue(engine.HasPrecedents("c"));
Assert.AreEqual(1, engine.GetDependents("a").Length);
Assert.AreEqual(1, engine.GetDependents("b").Length);
Assert.AreEqual(0, engine.GetDependents("c").Length);
engine.Remove("c");
Assert.IsFalse(engine.HasPrecedents("c"));
Assert.IsFalse(engine.HasDependents("c"));
Assert.IsFalse(engine.HasDependents("a"));
Assert.IsFalse(engine.HasDependents("b"));
Assert.AreEqual(0, engine.GetDependents("a").Length);
Assert.AreEqual(0, engine.GetDependents("b").Length);
engine.Remove("a");
engine.Remove("b");
Assert.IsFalse(engine.HasDependents("a"));
Assert.IsFalse(engine.HasPrecedents("a"));
Assert.IsFalse(engine.HasDependents("b"));
Assert.IsFalse(engine.HasPrecedents("b"));
Assert.AreEqual(0, engine.GetDependents("a").Length);
Assert.AreEqual(0, engine.GetDependents("b").Length);
Assert.AreEqual(0, engine.GetPrecedents("a").Length);
Assert.AreEqual(0, engine.GetPrecedents("b").Length);
}
示例3: TestInfoMethodsWithMissing
public void TestInfoMethodsWithMissing()
{
// Test that our informational methods can be called with a non-existant expression
CalculationEngine engine = new CalculationEngine();
Assert.IsFalse(engine.HasDependents("zz"));
Assert.IsFalse(engine.HasPrecedents("zz"));
Assert.AreEqual(0, engine.GetDependents("zz").Length);
Assert.AreEqual(0, engine.GetPrecedents("zz").Length);
}
示例4: TestClear
public void TestClear()
{
CalculationEngine engine = new CalculationEngine();
ExpressionContext context = new ExpressionContext();
engine.Add("a", "100", context);
engine.Add("b", "a + 2", context);
engine.Clear();
Assert.IsFalse(engine.HasDependents("a"));
Assert.IsFalse(engine.HasPrecedents("b"));
Assert.AreEqual(0, engine.Count);
}