public void When_DeriveNode_Expect_Reference(Node function, Dictionary <VariableNode, Node> expected) { var nf = new NodeFinder(); var d = new Derivatives() { Variables = new HashSet <VariableNode>(nf.Build(function)) }; var actual = d.Derive(function); CompareDictionary(expected, actual); }
/// <summary> /// Creates the derivatives for the specified function. /// </summary> /// <param name="function">The function.</param> /// <returns>The derivatives with respect to all variables.</returns> public Dictionary <VariableNode, Node> CreateDerivatives(Node function) { var state = GetState <IBiasingSimulationState>(); var bp = GetParameterSet <Parameters>(); var comparer = new VariableNodeComparer(state.Comparer, Simulation.EntityBehaviors.Comparer, bp.VariableComparer); // Derive the function var derivatives = new Derivatives() { Variables = new HashSet <VariableNode>(comparer) }; var nf = new NodeFinder(); foreach (var variable in nf.Build(function).Where(v => v.NodeType == NodeTypes.Voltage || v.NodeType == NodeTypes.Current)) { if (derivatives.Variables.Contains(variable)) { continue; } derivatives.Variables.Add(variable); } return(derivatives.Derive(function) ?? new Dictionary <VariableNode, Node>(comparer)); }