Internal Test: Verifies that the error code is correctly cleared after a successful operation.
ID: 327
using uCalcSoftware;
var uc = new uCalc();
// Trigger an error and check the code
uc.EvalStr("1+");
Console.WriteLine($"1. Error code after failure: {(int)uc.Error.Code}");
// A successful evaluation should clear the error code
uc.EvalStr("1+1");
Console.WriteLine($"2. Error code after success: {(int)uc.Error.Code}");
// Trigger a different type of error
uc.Error.TrapOnDivideByZero = true;
uc.EvalStr("1/0");
Console.WriteLine($"3. Error code after new failure: {(int)uc.Error.Code}");
// A successful definition should also clear the error code
uc.DefineVariable("x=5");
Console.WriteLine($"4. Error code after successful definition: {(int)uc.Error.Code}");
1. Error code after failure: 257
2. Error code after success: 0
3. Error code after new failure: 8
4. Error code after successful definition: 0 using uCalcSoftware; var uc = new uCalc(); // Trigger an error and check the code uc.EvalStr("1+"); Console.WriteLine($"1. Error code after failure: {(int)uc.Error.Code}"); // A successful evaluation should clear the error code uc.EvalStr("1+1"); Console.WriteLine($"2. Error code after success: {(int)uc.Error.Code}"); // Trigger a different type of error uc.Error.TrapOnDivideByZero = true; uc.EvalStr("1/0"); Console.WriteLine($"3. Error code after new failure: {(int)uc.Error.Code}"); // A successful definition should also clear the error code uc.DefineVariable("x=5"); Console.WriteLine($"4. Error code after successful definition: {(int)uc.Error.Code}");
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
// Trigger an error and check the code
uc.EvalStr("1+");
cout << "1. Error code after failure: " << (int)uc.Error().Code() << endl;
// A successful evaluation should clear the error code
uc.EvalStr("1+1");
cout << "2. Error code after success: " << (int)uc.Error().Code() << endl;
// Trigger a different type of error
uc.Error().TrapOnDivideByZero(true);
uc.EvalStr("1/0");
cout << "3. Error code after new failure: " << (int)uc.Error().Code() << endl;
// A successful definition should also clear the error code
uc.DefineVariable("x=5");
cout << "4. Error code after successful definition: " << (int)uc.Error().Code() << endl;
}
1. Error code after failure: 257
2. Error code after success: 0
3. Error code after new failure: 8
4. Error code after successful definition: 0 #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; // Trigger an error and check the code uc.EvalStr("1+"); cout << "1. Error code after failure: " << (int)uc.Error().Code() << endl; // A successful evaluation should clear the error code uc.EvalStr("1+1"); cout << "2. Error code after success: " << (int)uc.Error().Code() << endl; // Trigger a different type of error uc.Error().TrapOnDivideByZero(true); uc.EvalStr("1/0"); cout << "3. Error code after new failure: " << (int)uc.Error().Code() << endl; // A successful definition should also clear the error code uc.DefineVariable("x=5"); cout << "4. Error code after successful definition: " << (int)uc.Error().Code() << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
'// Trigger an error and check the code
uc.EvalStr("1+")
Console.WriteLine($"1. Error code after failure: {uc.Error.Code.ToString("D")}")
'// A successful evaluation should clear the error code
uc.EvalStr("1+1")
Console.WriteLine($"2. Error code after success: {uc.Error.Code.ToString("D")}")
'// Trigger a different type of error
uc.Error.TrapOnDivideByZero = true
uc.EvalStr("1/0")
Console.WriteLine($"3. Error code after new failure: {uc.Error.Code.ToString("D")}")
'// A successful definition should also clear the error code
uc.DefineVariable("x=5")
Console.WriteLine($"4. Error code after successful definition: {uc.Error.Code.ToString("D")}")
End Sub
End Module
1. Error code after failure: 257
2. Error code after success: 0
3. Error code after new failure: 8
4. Error code after successful definition: 0 Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() '// Trigger an error and check the code uc.EvalStr("1+") Console.WriteLine($"1. Error code after failure: {uc.Error.Code.ToString("D")}") '// A successful evaluation should clear the error code uc.EvalStr("1+1") Console.WriteLine($"2. Error code after success: {uc.Error.Code.ToString("D")}") '// Trigger a different type of error uc.Error.TrapOnDivideByZero = true uc.EvalStr("1/0") Console.WriteLine($"3. Error code after new failure: {uc.Error.Code.ToString("D")}") '// A successful definition should also clear the error code uc.DefineVariable("x=5") Console.WriteLine($"4. Error code after successful definition: {uc.Error.Code.ToString("D")}") End Sub End Module