public void ThresholdComparerTest() { ThresholdComparer zeroThreashold = new ThresholdComparer { Threhold = 0 }; ThresholdComparer tenThreshold = new ThresholdComparer { Threhold = 10 }; ThresholdComparer hundredThreshold = new ThresholdComparer { Threhold = 100 }; Predicate<int> graterThanZero = zeroThreashold.IsGraterThan; Predicate<int> tenThanZero = tenThreshold.IsGraterThan; Predicate<int> handredThanZero = hundredThreshold.IsGraterThan; // Create Delegate Predicate<int> createDelegate = (Predicate<int>)Delegate.CreateDelegate(typeof(Predicate<int>), zeroThreashold, "IsGraterThan"); Assert.IsTrue(graterThanZero(1)); Assert.IsTrue(tenThanZero(11)); Assert.IsFalse(graterThanZero(-1)); }
public void CombineDelete() { ThresholdComparer zeroThreashold = new ThresholdComparer { Threhold = 0 }; ThresholdComparer tenThreshold = new ThresholdComparer { Threhold = 10 }; ThresholdComparer hundredThreshold = new ThresholdComparer { Threhold = 100 }; Predicate<int> graterThanZero = zeroThreashold.IsGraterThan; Predicate<int> tenThanZero = tenThreshold.IsGraterThan; Predicate<int> handredThanZero = hundredThreshold.IsGraterThan; Predicate<int> combinePredicate = graterThanZero + tenThanZero + handredThanZero; Assert.IsFalse(combinePredicate(5)); Assert.IsTrue(combinePredicate(101)); Assert.IsFalse(combinePredicate(99)); foreach (Predicate<int> d in combinePredicate.GetInvocationList()) { Assert.IsTrue(d(101)); } }