From: Robert Nicholson Date: Fri, 25 Jan 2008 00:13:49 +0000 (+0000) Subject: - add some basic tests for array diff and intersection functions X-Git-Tag: RELEASE_1_3_1~300 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3b8256dce49b59ff152027f16ff4c38168e8b381;p=php - add some basic tests for array diff and intersection functions --- diff --git a/ext/standard/tests/array/array_diff_key_basic.phpt b/ext/standard/tests/array/array_diff_key_basic.phpt new file mode 100644 index 0000000000..6f6fcb9a4d --- /dev/null +++ b/ext/standard/tests/array/array_diff_key_basic.phpt @@ -0,0 +1,19 @@ +--TEST-- +Test array_diff_key() : basic functionality +--FILE-- + 1, 'red' => 2, 'green' => 3, 'purple' => 4); +$array2 = array('green' => 5, 'blue' => 6, 'yellow' => 7, 'cyan' => 8); +var_dump(array_diff_key($array1, $array2)); +?> +--EXPECT-- +array(2) { + ["red"]=> + int(2) + ["purple"]=> + int(4) +} \ No newline at end of file diff --git a/ext/standard/tests/array/array_diff_key_variation1.phpt b/ext/standard/tests/array/array_diff_key_variation1.phpt new file mode 100644 index 0000000000..00da7afa91 --- /dev/null +++ b/ext/standard/tests/array/array_diff_key_variation1.phpt @@ -0,0 +1,89 @@ +--TEST-- +array_diff_key() : type variations +--FILE-- + 'a', 2 => 'b', 3 => 'c', 'key1' => 'value'); +$arr2 = array(1.00 => 'a', 2.00 => 'b', 3.00 => 'c', 'key2' => 'value'); +$arr3 = array('1' => 'a', '2' => 'b', '3' => 'c', 'key3' => 'value'); +$arr4 = array('1.00' => 'a', '2.00' => 'b', '3.00' => 'c', 'key4' => 'value'); //$arr4 looks different to the other three arrays. +print "Result of comparing integers and floating point value:\n"; //1 and 1.00 are treated as the same thing +print_r(array_diff_key($arr1, $arr2)); +print_r(array_diff_key($arr2, $arr1)); +print "Result of comparing integers and strings containing an integers:\n"; //1 and the string 1 are treated as the same thing +print_r(array_diff_key($arr1, $arr3)); +print_r(array_diff_key($arr3, $arr1)); +print "Result of comparing integers and strings containing floating points:\n"; //1 and the string 1.00 are not treated as the same thing +print_r(array_diff_key($arr1, $arr4)); +print_r(array_diff_key($arr4, $arr1)); +print "Result of comparing floating points and strings containing integers:\n"; +print_r(array_diff_key($arr2, $arr3)); //1.00 and the string 1 are treated as the same thing +print_r(array_diff_key($arr3, $arr2)); +print "Result of comparing strings containing integers and strings containing floating points:\n"; //the strings 1 and 1.00 are not treated as the same thing. +print_r(array_diff_key($arr3, $arr4)); +print_r(array_diff_key($arr4, $arr3)); +?> +--EXPECTF-- +Result of comparing integers and floating point value: +Array +( + [key1] => value +) +Array +( + [key2] => value +) +Result of comparing integers and strings containing an integers: +Array +( + [key1] => value +) +Array +( + [key3] => value +) +Result of comparing integers and strings containing floating points: +Array +( + [1] => a + [2] => b + [3] => c + [key1] => value +) +Array +( + [1.00] => a + [2.00] => b + [3.00] => c + [key4] => value +) +Result of comparing floating points and strings containing integers: +Array +( + [key2] => value +) +Array +( + [key3] => value +) +Result of comparing strings containing integers and strings containing floating points: +Array +( + [1] => a + [2] => b + [3] => c + [key3] => value +) +Array +( + [1.00] => a + [2.00] => b + [3.00] => c + [key4] => value +) diff --git a/ext/standard/tests/array/array_diff_uassoc_basic.phpt b/ext/standard/tests/array/array_diff_uassoc_basic.phpt new file mode 100644 index 0000000000..6a96be6b7c --- /dev/null +++ b/ext/standard/tests/array/array_diff_uassoc_basic.phpt @@ -0,0 +1,28 @@ +--TEST-- +array_diff_uassoc(): Basic test +--FILE-- + $b) ? 1 : -1; +} +$array1 = array("a" => "green", "b" => "brown", "c" => "blue", "red"); +$array2 = array("a" => "green", "yellow", "red"); +$result = array_diff_uassoc($array1, $array2, "key_compare_func"); +var_dump($result); +?> +--EXPECT-- +array(3) { + ["b"]=> + string(5) "brown" + ["c"]=> + string(4) "blue" + [0]=> + string(3) "red" +} \ No newline at end of file diff --git a/ext/standard/tests/array/array_diff_ukey_basic.phpt b/ext/standard/tests/array/array_diff_ukey_basic.phpt new file mode 100644 index 0000000000..7ac309a01e --- /dev/null +++ b/ext/standard/tests/array/array_diff_ukey_basic.phpt @@ -0,0 +1,24 @@ +--TEST-- +array_diff_ukey() : Basic test. +--FILE-- + $key2) return 1; + else return -1; +} +$array1 = array('blue' => 1, 'red' => 2, 'green' => 3, 'purple' => 4); +$array2 = array('green' => 5, 'blue' => 6, 'yellow' => 7, 'cyan' => 8); +var_dump(array_diff_ukey($array1, $array2, 'key_compare_func')); +?> +--EXPECT-- +array(2) { + ["red"]=> + int(2) + ["purple"]=> + int(4) +} diff --git a/ext/standard/tests/array/array_intersect_key_basic.phpt b/ext/standard/tests/array/array_intersect_key_basic.phpt new file mode 100644 index 0000000000..fc6e177f54 --- /dev/null +++ b/ext/standard/tests/array/array_intersect_key_basic.phpt @@ -0,0 +1,19 @@ +--TEST-- +array_intersect_key(): Basic Test +--FILE-- + 1, 'red' => 2, 'green' => 3, 'purple' => 4); +$array2 = array('green' => 5, 'blue' => 6, 'yellow' => 7, 'cyan' => 8); +var_dump(array_intersect_key($array1, $array2)); +?> +--EXPECT-- +array(2) { + ["blue"]=> + int(1) + ["green"]=> + int(3) +} \ No newline at end of file diff --git a/ext/standard/tests/array/array_intersect_uassoc_basic.phpt b/ext/standard/tests/array/array_intersect_uassoc_basic.phpt new file mode 100644 index 0000000000..1a2d57ec3d --- /dev/null +++ b/ext/standard/tests/array/array_intersect_uassoc_basic.phpt @@ -0,0 +1,24 @@ +--TEST-- +array_intersect_uassoc(): Basic test +--FILE-- + $b) ? 1 : -1; +} +$array1 = array("a" => "green", "b" => "brown", "c" => "blue", "red"); +$array2 = array("a" => "green", "yellow", "red"); +$result = array_intersect_uassoc($array1, $array2, "key_compare_func"); +var_dump($result); +?> +--EXPECT-- +array(1) { + ["a"]=> + string(5) "green" +} \ No newline at end of file diff --git a/ext/standard/tests/array/array_intersect_ukey_basic.phpt b/ext/standard/tests/array/array_intersect_ukey_basic.phpt new file mode 100644 index 0000000000..db21b9b01e --- /dev/null +++ b/ext/standard/tests/array/array_intersect_ukey_basic.phpt @@ -0,0 +1,24 @@ +--TEST-- +array_intersect_ukey(): Basic test. +--FILE-- + $key2) return 1; + else return -1; +} +$array1 = array('blue' => 1, 'red' => 2, 'green' => 3, 'purple' => 4); +$array2 = array('green' => 5, 'blue' => 6, 'yellow' => 7, 'cyan' => 8); +var_dump(array_intersect_ukey($array1, $array2, 'key_compare_func')); +?> +--EXPECT-- +array(2) { + ["blue"]=> + int(1) + ["green"]=> + int(3) +} diff --git a/ext/standard/tests/array/array_udiff_assoc_basic.phpt b/ext/standard/tests/array/array_udiff_assoc_basic.phpt new file mode 100644 index 0000000000..769bafb76b --- /dev/null +++ b/ext/standard/tests/array/array_udiff_assoc_basic.phpt @@ -0,0 +1,41 @@ +--TEST-- +array_udiff_assoc(): Test return type and value for expected input +--FILE-- +priv_member = $val; + } + static function comp_func_cr($a, $b) { + if ($a->priv_member === $b->priv_member) return 0; + return ($a->priv_member > $b->priv_member) ? 1 : -1; + } +} +$a = array("0.1" => new cr(9), "0.5" => new cr(12), 0 => new cr(23), 1 => new cr(4), 2 => new cr(-15),); +$b = array("0.2" => new cr(9), "0.5" => new cr(22), 0 => new cr(3), 1 => new cr(4), 2 => new cr(-15),); +$result = array_udiff_assoc($a, $b, array("cr", "comp_func_cr")); +var_dump($result); +?> +--EXPECTF-- +array(3) { + ["0.1"]=> + object(cr)#%d (1) { + ["priv_member":"cr":private]=> + int(9) + } + ["0.5"]=> + object(cr)#%d (1) { + ["priv_member":"cr":private]=> + int(12) + } + [0]=> + object(cr)#%d (1) { + ["priv_member":"cr":private]=> + int(23) + } +} \ No newline at end of file diff --git a/ext/standard/tests/array/array_udiff_basic.phpt b/ext/standard/tests/array/array_udiff_basic.phpt new file mode 100644 index 0000000000..3da1b60c5c --- /dev/null +++ b/ext/standard/tests/array/array_udiff_basic.phpt @@ -0,0 +1,36 @@ +--TEST-- +array_udiff():Test return type and value for expected input +--FILE-- +priv_member = $val; + } + static function comp_func_cr($a, $b) { + if ($a->priv_member === $b->priv_member) return 0; + return ($a->priv_member > $b->priv_member) ? 1 : -1; + } +} +$a = array("0.1" => new cr(9), "0.5" => new cr(12), 0 => new cr(23), 1 => new cr(4), 2 => new cr(-15),); +$b = array("0.2" => new cr(9), "0.5" => new cr(22), 0 => new cr(3), 1 => new cr(4), 2 => new cr(-15),); +$result = array_udiff($a, $b, array("cr", "comp_func_cr")); +var_dump($result); +?> +--EXPECTF-- +array(2) { + ["0.5"]=> + object(cr)#%d (1) { + ["priv_member":"cr":private]=> + int(12) + } + [0]=> + object(cr)#%d (1) { + ["priv_member":"cr":private]=> + int(23) + } +} \ No newline at end of file diff --git a/ext/standard/tests/array/array_udiff_uassoc_basic.phpt b/ext/standard/tests/array/array_udiff_uassoc_basic.phpt new file mode 100644 index 0000000000..6095696f41 --- /dev/null +++ b/ext/standard/tests/array/array_udiff_uassoc_basic.phpt @@ -0,0 +1,45 @@ +--TEST-- +array_udiff_uassoc(): Test return type and value for expected input +--FILE-- +priv_member = $val; + } + static function comp_func_cr($a, $b) { + if ($a->priv_member === $b->priv_member) return 0; + return ($a->priv_member > $b->priv_member) ? 1 : -1; + } + static function comp_func_key($a, $b) { + if ($a === $b) return 0; + return ($a > $b) ? 1 : -1; + } +} +$a = array("0.1" => new cr(9), "0.5" => new cr(12), 0 => new cr(23), 1 => new cr(4), 2 => new cr(-15),); +$b = array("0.2" => new cr(9), "0.5" => new cr(22), 0 => new cr(3), 1 => new cr(4), 2 => new cr(-15),); +$result = array_udiff_uassoc($a, $b, array("cr", "comp_func_cr"), array("cr", "comp_func_key")); +var_dump($result); +?> +--EXPECTF-- +array(3) { + ["0.1"]=> + object(cr)#%d (1) { + ["priv_member":"cr":private]=> + int(9) + } + ["0.5"]=> + object(cr)#%d (1) { + ["priv_member":"cr":private]=> + int(12) + } + [0]=> + object(cr)#%d (1) { + ["priv_member":"cr":private]=> + int(23) + } +} \ No newline at end of file diff --git a/ext/standard/tests/array/array_uintersect_assoc_basic.phpt b/ext/standard/tests/array/array_uintersect_assoc_basic.phpt new file mode 100644 index 0000000000..7e9fff7875 --- /dev/null +++ b/ext/standard/tests/array/array_uintersect_assoc_basic.phpt @@ -0,0 +1,36 @@ +--TEST-- +array_uintersect_assoc(): Test return type and value for expected input +--FILE-- +priv_member = $val; + } + static function comp_func_cr($a, $b) { + if ($a->priv_member === $b->priv_member) return 0; + return ($a->priv_member > $b->priv_member) ? 1 : -1; + } +} +$a = array("0.1" => new cr(9), "0.5" => new cr(12), 0 => new cr(23), 1 => new cr(4), 2 => new cr(-15),); +$b = array("0.2" => new cr(9), "0.5" => new cr(22), 0 => new cr(3), 1 => new cr(4), 2 => new cr(-15),); +$result = array_uintersect_assoc($a, $b, array("cr", "comp_func_cr")); +var_dump($result); +?> +--EXPECTF-- +array(2) { + [1]=> + object(cr)#%d (1) { + ["priv_member":"cr":private]=> + int(4) + } + [2]=> + object(cr)#%d (1) { + ["priv_member":"cr":private]=> + int(-15) + } +} \ No newline at end of file diff --git a/ext/standard/tests/array/array_uintersect_basic.phpt b/ext/standard/tests/array/array_uintersect_basic.phpt new file mode 100644 index 0000000000..8d4b803589 --- /dev/null +++ b/ext/standard/tests/array/array_uintersect_basic.phpt @@ -0,0 +1,41 @@ +--TEST-- +array_uintersect(): Test return type and value for expected input +--FILE-- +priv_member = $val; + } + static function comp_func_cr($a, $b) { + if ($a->priv_member === $b->priv_member) return 0; + return ($a->priv_member > $b->priv_member) ? 1 : -1; + } +} +$a = array("0.1" => new cr(9), "0.5" => new cr(12), 0 => new cr(23), 1 => new cr(4), 2 => new cr(-15),); +$b = array("0.2" => new cr(9), "0.5" => new cr(22), 0 => new cr(3), 1 => new cr(4), 2 => new cr(-15),); +$result = array_uintersect($a, $b, array("cr", "comp_func_cr")); +var_dump($result); +?> +--EXPECTF-- +array(3) { + ["0.1"]=> + object(cr)#%d (1) { + ["priv_member":"cr":private]=> + int(9) + } + [1]=> + object(cr)#%d (1) { + ["priv_member":"cr":private]=> + int(4) + } + [2]=> + object(cr)#%d (1) { + ["priv_member":"cr":private]=> + int(-15) + } +} \ No newline at end of file diff --git a/ext/standard/tests/array/array_uintersect_uassoc_basic.phpt b/ext/standard/tests/array/array_uintersect_uassoc_basic.phpt new file mode 100644 index 0000000000..a474bc7ff5 --- /dev/null +++ b/ext/standard/tests/array/array_uintersect_uassoc_basic.phpt @@ -0,0 +1,40 @@ +--TEST-- +array_uintersect_uassoc(): Test return type and value for expected input +--FILE-- +priv_member = $val; + } + static function comp_func_cr($a, $b) { + if ($a->priv_member === $b->priv_member) return 0; + return ($a->priv_member > $b->priv_member) ? 1 : -1; + } + static function comp_func_key($a, $b) { + if ($a === $b) return 0; + return ($a > $b) ? 1 : -1; + } +} +$a = array("0.1" => new cr(9), "0.5" => new cr(12), 0 => new cr(23), 1 => new cr(4), 2 => new cr(-15),); +$b = array("0.2" => new cr(9), "0.5" => new cr(22), 0 => new cr(3), 1 => new cr(4), 2 => new cr(-15),); +$result = array_uintersect_uassoc($a, $b, array("cr", "comp_func_cr"), array("cr", "comp_func_key")); +var_dump($result); +?> +--EXPECTF-- +array(2) { + [1]=> + object(cr)#%d (1) { + ["priv_member":"cr":private]=> + int(4) + } + [2]=> + object(cr)#%d (1) { + ["priv_member":"cr":private]=> + int(-15) + } +} \ No newline at end of file