public void Constructor_ExpectedValues(int referenceValue, ComparisonType comparisonType) { // Setup var rng = MockRepository.GenerateStub <IRandomNumberGenerator>(); var die = MockRepository.GenerateStub <IAbstractDie>(); die.Stub(d => d.ProbabilityDistribution).Return(new DiscreteValueProbabilityDistribution(new[] { new ValueProbabilityPair(1, 1.0) })); // Call var thresholdCompare = new ThresholdCompare(die, comparisonType, referenceValue, rng); // Assert Assert.IsInstanceOf <IRollable <bool> >(thresholdCompare); Assert.IsInstanceOf <IDiscreteBooleanRandomVariable>(thresholdCompare); Assert.AreEqual(referenceValue, thresholdCompare.ReferenceValue); Assert.AreEqual(comparisonType, thresholdCompare.ComparisonType); }
public static Predicate <int> CombiningDelegate() { var zeroThreshold = new ThresholdCompare { Threshold = 0 }; var tenThreshold = new ThresholdCompare { Threshold = 10 }; var hundredThreshold = new ThresholdCompare { Threshold = 100 }; Predicate <int> megaPredicate = zeroThreshold.IsGreaterThan; megaPredicate += tenThreshold.IsGreaterThan; megaPredicate += hundredThreshold.IsGreaterThan; return(megaPredicate); }
public static void Example_Instance() { var zeroThreshold = new ThresholdCompare { Threshold = 0 }; var tenThreshold = new ThresholdCompare { Threshold = 10 }; var hundredThreshold = new ThresholdCompare { Threshold = 100 }; Predicate <int> greaterThanZero = zeroThreshold.IsGreaterThan; Predicate <int> greaterThanTen = tenThreshold.IsGreaterThan; Predicate <int> greaterThanHundred = hundredThreshold.IsGreaterThan; Console.WriteLine("-1 is greater than zero? " + greaterThanZero(-1)); Console.WriteLine("11 is greater than ten? " + greaterThanTen(11)); Console.WriteLine("1000 is greater than hundred? " + greaterThanHundred(1000)); }
public void Roll_BasedOnProbabilityDistribution_ReturnExpectedResult(ComparisonType comparisonType) { // Setup var spec = new[] { new ValueProbabilityPair(1, 0.25), new ValueProbabilityPair(4, 0.5), new ValueProbabilityPair(8, 0.25), }; var die = MockRepository.GenerateStub <IAbstractDie>(); die.Stub(d => d.ProbabilityDistribution).Return(new DiscreteValueProbabilityDistribution(spec)); var rng = new TestingRandomNumberGenerator(); const int referenceValue = 4; var thresholdCompare = new ThresholdCompare(die, comparisonType, referenceValue, rng); double successProbability = thresholdCompare.ProbabilityDistribution.SuccessProbability; var expectedValueAndProbabilities = new[] { Tuple.Create(true, 0.0), Tuple.Create(true, successProbability - 0.1), Tuple.Create(true, successProbability), Tuple.Create(false, successProbability + 1e-6), Tuple.Create(false, successProbability + 0.1), Tuple.Create(false, 1.0), }; rng.AddFactorValues(expectedValueAndProbabilities.Select(t => t.Item2)); foreach (Tuple <bool, double> expectedValueAndProbability in expectedValueAndProbabilities) { // Call bool rolledResult = thresholdCompare.Roll(); // Assert Assert.AreEqual(rolledResult, expectedValueAndProbability.Item1); } }
public void ProbabilityDistribution_DieGreaterThanOrEqualToReferenceValue_ReturnExpectedResult( int referenceValue, double expectedSuccessProbability) { // Setup var rng = MockRepository.GenerateStub <IRandomNumberGenerator>(); var spec = new[] { new ValueProbabilityPair(1, 0.25), new ValueProbabilityPair(4, 0.5), new ValueProbabilityPair(8, 0.25), }; var die = MockRepository.GenerateStub <IAbstractDie>(); die.Stub(d => d.ProbabilityDistribution).Return(new DiscreteValueProbabilityDistribution(spec)); var thresholdCompare = new ThresholdCompare(die, ComparisonType.GreaterOrEqual, referenceValue, rng); // Call BooleanProbabilityDistribution distribution = thresholdCompare.ProbabilityDistribution; // Assert Assert.AreEqual(expectedSuccessProbability, distribution.SuccessProbability); }