Skip to main content

valueIsEqualTo

Short summary​

This assertion method checks if the current value is equal to the expected value

Attention: Nothing is equal to NaN, that means if currentValue OR expectedValue OR tolerance is NaN then is the assertion false. For details check IEEE 754_

Attention: infinity is equal to infinity and -infinity is equal to -infinity, that means if currentValue AND expectedValue have the value infinity OR currentValue AND expectedValue have the value -infinity the assertion is TRUE. For details check IEEE 754_

Attention: If tolerance has the value infinity or -infinity and currentValue is not NaN and expectedValue is not NaN then is the assertion true. for details check IEEE 754

Parameters​

NameTypeCommentKind
currentValueREALcurrent value to checkinput
expectedValueREALexpected value to compareinput
toleranceREALtolerance to compensate twiddling floats, it has no signinput
messageAssertMessagemessage if the assertion is falseinput

Code​

Declaration​

METHOD valueIsEqualTo
VAR_INPUT
(* current value to check *)
currentValue :REAL;
(* expected value to compare *)
expectedValue :REAL;
(* tolerance to compensate twiddling floats, it has no sign *)
tolerance :REAL;
(* message if the assertion is false *)
message :AssertMessage;
END_VAR

Implementation​

IF (
THIS^.isValueNaN(currentValue)
OR_ELSE THIS^.isValueNaN(expectedValue)
OR_ELSE THIS^.isValueNaN(tolerance)
) THEN
THIS^.assertionWasWrong(message, THIS^.getDebugInfo('valueIsEqualTo'));
ELSIF (THIS^.isValueInfinite(tolerance)) THEN
RETURN;
ELSIF (
THIS^.isValueInfinite(currentValue)
OR_ELSE THIS^.isValueInfinite(expectedValue)
OR_ELSE THIS^.isValueInfinite(tolerance)
) THEN
RETURN (THIS^.isValuePositiveInfinite(currentValue) AND_THEN THIS^.isValuePositiveInfinite(expectedValue));
RETURN (THIS^.isValueNegativeInfinite(currentValue) AND_THEN THIS^.isValueNegativeInfinite(expectedValue));
THIS^.assertionWasWrong(message, THIS^.getDebugInfo('valueIsEqualTo'));
ELSIF (ABS(currentValue-expectedValue) > ABS(tolerance)) THEN
THIS^.assertionWasWrong(message, THIS^.getDebugInfo('valueIsEqualTo'));
END_IF