示例#1
0
        public void TestGoalSeek([Values(1700, 1400, 1300)] decimal target)
        {
            // Given
            var tree     = GetTree();
            var goalSeek = new GoalSeek <GoalSeekContext>(() => new GoalSeekContext(0, target), tree, ModifyContext, GetTarget, GetStartValue);

            // When
            var result        = goalSeek.GetGoalSeekValue(target);
            var executionTine = goalSeek.GetExecutionTine();
            var iterations    = goalSeek.GetIterations();

            // Then
            var context = new GoalSeekContext(result, target);

            tree.Run(context);
            Assert.IsNotNull(context);
            var grossUp = (long)(context.TargetDecimal - context.Tax + context.DecimalToManipulate);

            Assert.AreEqual(target, grossUp);
            Assert.IsNotNull(iterations);
            Assert.IsNotNull(executionTine);
        }
示例#2
0
 /// <summary>
 /// Modify the variable in the context
 /// </summary>
 /// <param name="context">
 /// The context.
 /// </param>
 /// <param name="input">
 /// The input.
 /// </param>
 /// <returns>
 /// The <see cref="GoalSeekContext"/>.
 /// </returns>
 private static GoalSeekContext ModifyContext(GoalSeekContext context, decimal input)
 {
     context.DecimalToManipulate = input;
     return(context);
 }
示例#3
0
 /// <summary>
 /// The get start value.
 /// </summary>
 /// <param name="context">
 /// The context.
 /// </param>
 /// <returns>
 /// The <see cref="decimal"/>.
 /// </returns>
 private static decimal GetStartValue(GoalSeekContext context)
 {
     return(context.Tax);
 }
示例#4
0
 /// <summary>
 /// Get the target
 /// </summary>
 /// <param name="context">
 /// The context from which to retrieve the target
 /// </param>
 /// <returns>
 /// The <see cref="decimal"/>.
 /// </returns>
 private static decimal GetTarget(GoalSeekContext context)
 {
     return(context.TargetDecimal);
 }