public void UseCase_ComplexDerivedSystemAsFunction() { // TODO: Replace with new (easier to use) MathFunction class instead of MathSystem _p.KeepTrack = false; MathSystem s = _p.CurrentSystem; Signal x = Binder.CreateSignal(); x.Label = "x"; Signal x2 = StdBuilder.Square(x); x2.Label = "x2"; Signal secx2 = StdBuilder.Secant(x2); secx2.Label = "secx2"; Signal diff = Std.Derive(secx2, x); diff.Label = "diff1"; s.AddSignalTree(diff, true, true); s.RemoveUnusedObjects(); Assert.AreEqual("2*sec(sqr(x))*tan(sqr(x))*x", _f.Format(diff, FormattingOptions.Compact), "Formatted Diff A"); Assert.AreEqual(1, s.InputCount, "Input Signal Count A"); Assert.AreEqual(1, s.OutputCount, "Output Signal Count A"); Assert.AreEqual(0, s.BusCount, "Bus Count A"); Assert.AreEqual(6, s.SignalCount, "Signal Count A"); Assert.AreEqual(4, s.PortCount, "Port Count A"); Signal diff2 = Std.AutoSimplify(diff); s.UnpromoteAsOutput(diff); s.AddSignalTree(diff2, true, true); s.RemoveUnusedObjects(); Assert.AreEqual("2*sec(sqr(x))*tan(sqr(x))*x", _f.Format(diff2, FormattingOptions.Compact), "Formatted Diff B"); Assert.AreEqual(1, s.InputCount, "Input Signal Count B"); Assert.AreEqual(1, s.OutputCount, "Output Signal Count B"); Assert.AreEqual(0, s.BusCount, "Bus Count B"); Assert.AreEqual(6, s.SignalCount, "Signal Count B"); Assert.AreEqual(4, s.PortCount, "Port Count B"); IValueStructure vs = s.Evaluate(ComplexValue.I)[0]; Assert.IsInstanceOfType(typeof(ComplexValue), vs, "Result is complex."); ComplexValue cv = (ComplexValue)vs; Assert.AreEqual(0, Math.Round(cv.RealValue, 4), "Real Result"); Assert.AreEqual(-5.7649, Math.Round(cv.ImaginaryValue, 4), "Imag Result"); }