Ejemplo n.º 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);
        }
Ejemplo n.º 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);
 }
Ejemplo n.º 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);
 }
Ejemplo n.º 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);
 }