Internal Test: Validates that end-users cannot modify a locked constant.
ID: 288
See: DefineConstant
using uCalcSoftware;
var uc = new uCalc();
uc.DefineConstant("LOCKED_VAL = 1000");
Console.WriteLine($"Initial value: {uc.Eval("LOCKED_VAL")}");
// 1. End-user attempts to assign a value. This should fail.
uc.Eval("LOCKED_VAL = 2000");
Console.WriteLine($"Error after assignment attempt: {uc.Error.Message}");
Console.WriteLine($"Value remains unchanged: {uc.Eval("LOCKED_VAL")}");
Initial value: 1000
Error after assignment attempt: Value cannot be assigned here
Value remains unchanged: 1000 using uCalcSoftware; var uc = new uCalc(); uc.DefineConstant("LOCKED_VAL = 1000"); Console.WriteLine($"Initial value: {uc.Eval("LOCKED_VAL")}"); // 1. End-user attempts to assign a value. This should fail. uc.Eval("LOCKED_VAL = 2000"); Console.WriteLine($"Error after assignment attempt: {uc.Error.Message}"); Console.WriteLine($"Value remains unchanged: {uc.Eval("LOCKED_VAL")}");
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
uc.DefineConstant("LOCKED_VAL = 1000");
cout << "Initial value: " << uc.Eval("LOCKED_VAL") << endl;
// 1. End-user attempts to assign a value. This should fail.
uc.Eval("LOCKED_VAL = 2000");
cout << "Error after assignment attempt: " << uc.Error().Message() << endl;
cout << "Value remains unchanged: " << uc.Eval("LOCKED_VAL") << endl;
}
Initial value: 1000
Error after assignment attempt: Value cannot be assigned here
Value remains unchanged: 1000 #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; uc.DefineConstant("LOCKED_VAL = 1000"); cout << "Initial value: " << uc.Eval("LOCKED_VAL") << endl; // 1. End-user attempts to assign a value. This should fail. uc.Eval("LOCKED_VAL = 2000"); cout << "Error after assignment attempt: " << uc.Error().Message() << endl; cout << "Value remains unchanged: " << uc.Eval("LOCKED_VAL") << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
uc.DefineConstant("LOCKED_VAL = 1000")
Console.WriteLine($"Initial value: {uc.Eval("LOCKED_VAL")}")
'// 1. End-user attempts to assign a value. This should fail.
uc.Eval("LOCKED_VAL = 2000")
Console.WriteLine($"Error after assignment attempt: {uc.Error.Message}")
Console.WriteLine($"Value remains unchanged: {uc.Eval("LOCKED_VAL")}")
End Sub
End Module
Initial value: 1000
Error after assignment attempt: Value cannot be assigned here
Value remains unchanged: 1000 Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() uc.DefineConstant("LOCKED_VAL = 1000") Console.WriteLine($"Initial value: {uc.Eval("LOCKED_VAL")}") '// 1. End-user attempts to assign a value. This should fail. uc.Eval("LOCKED_VAL = 2000") Console.WriteLine($"Error after assignment attempt: {uc.Error.Message}") Console.WriteLine($"Value remains unchanged: {uc.Eval("LOCKED_VAL")}") End Sub End Module