Skip to content

Commit

Permalink
ext/gmp: Refactor gmp_cmp() test
Browse files Browse the repository at this point in the history
  • Loading branch information
Girgias committed Nov 27, 2024
1 parent 60d8ab9 commit 79aaca8
Showing 1 changed file with 24 additions and 14 deletions.
38 changes: 24 additions & 14 deletions ext/gmp/tests/gmp_cmp.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,27 @@ gmp
--FILE--
<?php

var_dump(gmp_cmp(123123,-123123));
var_dump(gmp_cmp("12345678900987654321","12345678900987654321"));
var_dump(gmp_cmp("12345678900987654321","123456789009876543211"));
var_dump(gmp_cmp(0,0));
var_dump(gmp_cmp(1231222,0));
var_dump(gmp_cmp(0,345355));
function cmp_helper($l, $r) {
echo 'gmp(', var_export($l, true), ', ', var_export($r, true), '): ';
$r = gmp_cmp($l, $r);
echo match (true) {
$r === 0 => "equals\n",
$r < 0 => "right greater than left\n",
$r > 0 => "left greater than right\n",
};
}

cmp_helper(123123,-123123);
cmp_helper("12345678900987654321","12345678900987654321");
cmp_helper("12345678900987654321","123456789009876543211");
cmp_helper(0,0);
cmp_helper(1231222,0);
cmp_helper(0,345355);

$n = gmp_init("827278512385463739");
var_dump(gmp_cmp(0,$n) < 0);
$n1 = gmp_init("827278512385463739");
var_dump(gmp_cmp($n1,$n));
var_dump(gmp_cmp($n1,$n) === 0);

try {
var_dump(gmp_cmp(array(),array()));
Expand All @@ -26,13 +36,13 @@ try {
echo "Done\n";
?>
--EXPECT--
int(1)
int(0)
int(-1)
int(0)
int(1)
int(-1)
gmp(123123, -123123): left greater than right
gmp('12345678900987654321', '12345678900987654321'): equals
gmp('12345678900987654321', '123456789009876543211'): right greater than left
gmp(0, 0): equals
gmp(1231222, 0): left greater than right
gmp(0, 345355): right greater than left
bool(true)
bool(true)
int(0)
gmp_cmp(): Argument #1 ($num1) must be of type GMP|string|int, array given
Done

0 comments on commit 79aaca8

Please sign in to comment.