/// <summary> /// Test using DC simulation /// The netlist should contain one DC simulation. The first exporter is tested to the reference /// </summary> /// <param name="netlist">Netlist</param> /// <param name="reference">Reference values</param> protected void TestDC(Netlist netlist, double[] reference) { int index = 0; netlist.OnExportSimulationData += (object sender, SimulationData data) => { double actual = netlist.Exports[0].Extract(data); double expected = reference[index++]; double tol = Math.Max(Math.Abs(actual), Math.Abs(expected)) * 1e-3 + 1e-12; Assert.AreEqual(expected, actual, tol); }; netlist.Simulate(); }
/// <summary> /// Test using transient simulation /// The netlist should contain a transient simulation. The first exporter is tested to the reference /// </summary> /// <param name="netlist">Netlist</param> /// <param name="reft">Reference time values</param> /// <param name="refv">Reference values</param> protected void TestTransient(Netlist netlist, double[] reft, double[] refv) { var interpolation = LinearSpline.Interpolate(reft, refv); netlist.OnExportSimulationData += (object sender, SimulationData data) => { double time = data.GetTime(); double actual = netlist.Exports[0].Extract(data); double expected = interpolation.Interpolate(time); double tol = Math.Max(Math.Abs(actual), Math.Abs(expected)) * 1e-3 + 1e-12; Assert.AreEqual(expected, actual, tol); }; netlist.Simulate(); }
/// <summary> /// Test using the noise simulation /// The netlist should contain a noise simulation. Input and output referred noise density are checked /// </summary> /// <param name="netlist">Netlist</param> /// <param name="reference">Reference values</param> protected void TestNoise(Netlist netlist, double[] reference_in, double[] reference_out) { int index = 0; netlist.OnExportSimulationData += (object sender, SimulationData data) => { double freq = data.GetFrequency(); double actual = Math.Log(data.GetInputNoiseDensity()); double expected = Math.Log(reference_in[index]); double tol = Math.Max(Math.Abs(actual), Math.Abs(expected)) * 1e-3 + 1e-12; Assert.AreEqual(expected, actual, tol); actual = Math.Log(data.GetOutputNoiseDensity()); expected = Math.Log(reference_out[index]); tol = Math.Max(Math.Abs(actual), Math.Abs(expected)) * 1e-3 + 1e-12; Assert.AreEqual(expected, actual, tol); index++; }; netlist.Simulate(); }