public void SystemToSystemCloneTest() { Project p = new Project(); MathSystem s1 = p.CurrentSystem; // BUILD SYSTEM 1: sin(x^2) Signal x = Binder.CreateSignal(); x.Label = "x"; Std.ConstrainAlwaysReal(x); Signal x2 = StdBuilder.Square(x); x2.Label = "x2"; Signal sinx2 = StdBuilder.Sine(x2); sinx2.Label = "sinx2"; Signal sinx2t2 = sinx2 * IntegerValue.ConstantTwo; s1.AddSignalTree(sinx2t2, true, true); // EVALUATE SYSTEM 1 FOR x=1.5 x.PostNewValue(new RealValue(1.5)); p.SimulateInstant(); Assert.AreEqual(0, s1.BusCount, "A0"); Assert.AreEqual(5, s1.SignalCount, "A1"); Assert.AreEqual(3, s1.PortCount, "A2"); Assert.AreEqual("Std.Real(1.55614639377584)", sinx2t2.Value.ToString(), "A3"); // CLONE SYSTEM 1 TO SYSTEM 2 /* * HINT: would be simpler to just call: * MathSystem s2 = s1.Clone(); */ SystemWriter writer = new SystemWriter(); SystemReader reader = new SystemReader(writer); reader.ReadSystem(s1); IMathSystem s2 = writer.WrittenSystems.Dequeue(); Assert.AreEqual(0, s2.BusCount, "B0"); Assert.AreEqual(5, s2.SignalCount, "B1"); Assert.AreEqual(3, s2.PortCount, "B2"); Assert.AreEqual("Std.Real(1.55614639377584)", s2.GetOutput(0).Value.ToString(), "B3"); // EVALUATE SYSTEM 2 FOR x=2.5 s2.GetInput(0).PostNewValue(new RealValue(2.5)); p.SimulateInstant(); Assert.AreEqual("Std.Real(-0.0663584330951136)", s2.GetOutput(0).Value.ToString(), "C0"); // CHECK SYSTEM 1 STILL ON x=1.5 Assert.AreEqual("Std.Real(1.5)", x.Value.ToString(), "D0"); Assert.AreEqual("Std.Real(1.55614639377584)", sinx2t2.Value.ToString(), "D1"); }