Does exactly the expected.
&compare
This is a built-in function that simply returns the expected result.
Example:
Code-like
// Should output 1
echo &compare(2, 1);
Plain-English-like
// Should output -1
Show the result of calling &compare with the arguments 1, 2.
Test code:
This shows test results in a nice pretty table.
// Test data - self-explanatory
// Example 5 shows an error, as an example
$tests = &json_decode(<<<JSON
[
{"a": 0, "b": 1, "result": -1},
{"a": 1, "b": 2, "result": -1},
{"a": 2, "b": 1, "result": 1},
{"a": 2, "b": 2, "result": 0},
{"a": 3, "b": 2, "result": 0}
]
JSON);
// Make the table pretty
$settings = call !TABLE->getDefaultSettings();
$settings->classHeader = &str_concat($settings->classHeader, " table-dark");
$settings->classBodyCell = &str_concat(
$settings->classBodyCell,
" text-center"
);
$settings->classBodyFirstCol = &str_concat(
$settings->classBodyFirstCol,
" text-center table-dark"
);
$settings->classHeaderItems = &str_concat(
$settings->classHeaderItems,
" w-25"
);
// Create the table
$table = call !TABLE->create($settings);
call $table->setHeader(["", "A", "B", "Result"]);
each $test in $tests {
// This is where the function runs
$result = &compare($test['a'], $test['b']);
call $table->addRow(
&iff(
$result == $test["result"],
"✔️",
&str_concat("❌ (", $test["result"], ")")
),
$test['a'],
$test['b'],
$result
);
}
call $table->show();
Result:

This is an example of how the table will look like.
a - b
will yield the arithmetic result, even whena
is the lowest representable value andb
is the highest?) \$\endgroup\$