An internal test verifying that an expression remains tied to its original context, even after the context has been cloned and modified.
ID: 606
See: uCalc = [uCalc]
using uCalcSoftware;
var uc = new uCalc();
// Internal Test: Context integrity after cloning
var baseUc = new uCalc();
baseUc.DefineVariable("x = 100");
// Clone the base instance and modify the variable in the clone
var clonedUc = baseUc.Clone();
clonedUc.Eval("x = 200");
// Parse an expression in the original base context
var baseExpr = baseUc.Parse("x");
// 1. Verify the expression evaluates using its original context's value
Console.WriteLine($"Base expression evaluates to: {baseExpr.Evaluate()}");
// 2. Get the parent and verify it is not the cloned instance
Console.WriteLine($"Parent is not the clone: {baseExpr.uCalc.MemoryIndex != clonedUc.MemoryIndex}");
Base expression evaluates to: 100
Parent is not the clone: True using uCalcSoftware; var uc = new uCalc(); // Internal Test: Context integrity after cloning var baseUc = new uCalc(); baseUc.DefineVariable("x = 100"); // Clone the base instance and modify the variable in the clone var clonedUc = baseUc.Clone(); clonedUc.Eval("x = 200"); // Parse an expression in the original base context var baseExpr = baseUc.Parse("x"); // 1. Verify the expression evaluates using its original context's value Console.WriteLine($"Base expression evaluates to: {baseExpr.Evaluate()}"); // 2. Get the parent and verify it is not the cloned instance Console.WriteLine($"Parent is not the clone: {baseExpr.uCalc.MemoryIndex != clonedUc.MemoryIndex}");
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
#define tf(IsTrue) ((IsTrue) ? "True" : "False")
int main() {
uCalc uc;
// Internal Test: Context integrity after cloning
uCalc baseUc;
baseUc.DefineVariable("x = 100");
// Clone the base instance and modify the variable in the clone
auto clonedUc = baseUc.Clone();
clonedUc.Eval("x = 200");
// Parse an expression in the original base context
auto baseExpr = baseUc.Parse("x");
// 1. Verify the expression evaluates using its original context's value
cout << "Base expression evaluates to: " << baseExpr.Evaluate() << endl;
// 2. Get the parent and verify it is not the cloned instance
cout << "Parent is not the clone: " << tf(baseExpr.uCalc().MemoryIndex() != clonedUc.MemoryIndex()) << endl;
}
Base expression evaluates to: 100
Parent is not the clone: True #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; #define tf(IsTrue) ((IsTrue) ? "True" : "False") int main() { uCalc uc; // Internal Test: Context integrity after cloning uCalc baseUc; baseUc.DefineVariable("x = 100"); // Clone the base instance and modify the variable in the clone auto clonedUc = baseUc.Clone(); clonedUc.Eval("x = 200"); // Parse an expression in the original base context auto baseExpr = baseUc.Parse("x"); // 1. Verify the expression evaluates using its original context's value cout << "Base expression evaluates to: " << baseExpr.Evaluate() << endl; // 2. Get the parent and verify it is not the cloned instance cout << "Parent is not the clone: " << tf(baseExpr.uCalc().MemoryIndex() != clonedUc.MemoryIndex()) << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
'// Internal Test: Context integrity after cloning
Dim baseUc As New uCalc()
baseUc.DefineVariable("x = 100")
'// Clone the base instance and modify the variable in the clone
Dim clonedUc = baseUc.Clone()
clonedUc.Eval("x = 200")
'// Parse an expression in the original base context
Dim baseExpr = baseUc.Parse("x")
'// 1. Verify the expression evaluates using its original context's value
Console.WriteLine($"Base expression evaluates to: {baseExpr.Evaluate()}")
'// 2. Get the parent and verify it is not the cloned instance
Console.WriteLine($"Parent is not the clone: {baseExpr.uCalc.MemoryIndex <> clonedUc.MemoryIndex}")
End Sub
End Module
Base expression evaluates to: 100
Parent is not the clone: True Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() '// Internal Test: Context integrity after cloning Dim baseUc As New uCalc() baseUc.DefineVariable("x = 100") '// Clone the base instance and modify the variable in the clone Dim clonedUc = baseUc.Clone() clonedUc.Eval("x = 200") '// Parse an expression in the original base context Dim baseExpr = baseUc.Parse("x") '// 1. Verify the expression evaluates using its original context's value Console.WriteLine($"Base expression evaluates to: {baseExpr.Evaluate()}") '// 2. Get the parent and verify it is not the cloned instance Console.WriteLine($"Parent is not the clone: {baseExpr.uCalc.MemoryIndex <> clonedUc.MemoryIndex}") End Sub End Module