From 38c322d3db620b6efe0900e6d8d431976a0b039b Mon Sep 17 00:00:00 2001 From: Robert Nicholson Date: Fri, 25 Jan 2008 00:17:34 +0000 Subject: [PATCH] - add some basic tests for array diff and intersection functions --- .../tests/array/array_diff_key_basic.phpt | 26 ++++++ .../array/array_diff_key_variation1.phpt | 89 +++++++++++++++++++ .../tests/array/array_diff_uassoc_basic.phpt | 37 ++++++++ .../tests/array/array_diff_ukey_basic.phpt | 31 +++++++ .../array/array_intersect_key_basic.phpt | 26 ++++++ .../array/array_intersect_uassoc_basic.phpt | 29 ++++++ .../array/array_intersect_ukey_basic.phpt | 31 +++++++ .../tests/array/array_udiff_assoc_basic.phpt | 59 ++++++++++++ .../tests/array/array_udiff_basic.phpt | 49 ++++++++++ .../tests/array/array_udiff_uassoc_basic.phpt | 63 +++++++++++++ .../array/array_uintersect_assoc_basic.phpt | 49 ++++++++++ .../tests/array/array_uintersect_basic.phpt | 59 ++++++++++++ .../array/array_uintersect_uassoc_basic.phpt | 53 +++++++++++ 13 files changed, 601 insertions(+) create mode 100644 ext/standard/tests/array/array_diff_key_basic.phpt create mode 100644 ext/standard/tests/array/array_diff_key_variation1.phpt create mode 100644 ext/standard/tests/array/array_diff_uassoc_basic.phpt create mode 100644 ext/standard/tests/array/array_diff_ukey_basic.phpt create mode 100644 ext/standard/tests/array/array_intersect_key_basic.phpt create mode 100644 ext/standard/tests/array/array_intersect_uassoc_basic.phpt create mode 100644 ext/standard/tests/array/array_intersect_ukey_basic.phpt create mode 100644 ext/standard/tests/array/array_udiff_assoc_basic.phpt create mode 100644 ext/standard/tests/array/array_udiff_basic.phpt create mode 100644 ext/standard/tests/array/array_udiff_uassoc_basic.phpt create mode 100644 ext/standard/tests/array/array_uintersect_assoc_basic.phpt create mode 100644 ext/standard/tests/array/array_uintersect_basic.phpt create mode 100644 ext/standard/tests/array/array_uintersect_uassoc_basic.phpt 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..5514e30df4 --- /dev/null +++ b/ext/standard/tests/array/array_diff_key_basic.phpt @@ -0,0 +1,26 @@ +--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) +} +--UEXPECT-- +array(2) { + [u"red"]=> + int(2) + [u"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..e1f8b5b523 --- /dev/null +++ b/ext/standard/tests/array/array_diff_uassoc_basic.phpt @@ -0,0 +1,37 @@ +--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" +} +--UEXPECT-- +array(3) { + [u"b"]=> + unicode(5) "brown" + [u"c"]=> + unicode(4) "blue" + [0]=> + unicode(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..8eab1961ca --- /dev/null +++ b/ext/standard/tests/array/array_diff_ukey_basic.phpt @@ -0,0 +1,31 @@ +--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) +} +--UEXPECT-- +array(2) { + [u"red"]=> + int(2) + [u"purple"]=> + int(4) +} \ No newline at end of file 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..324a5af728 --- /dev/null +++ b/ext/standard/tests/array/array_intersect_key_basic.phpt @@ -0,0 +1,26 @@ +--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) +} +--UEXPECT-- +array(2) { + [u"blue"]=> + int(1) + [u"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..ea8a3e94f6 --- /dev/null +++ b/ext/standard/tests/array/array_intersect_uassoc_basic.phpt @@ -0,0 +1,29 @@ +--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" +} +--UEXPECT-- +array(1) { + [u"a"]=> + unicode(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..09791e0357 --- /dev/null +++ b/ext/standard/tests/array/array_intersect_ukey_basic.phpt @@ -0,0 +1,31 @@ +--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) +} +--UEXPECT-- +array(2) { + [u"blue"]=> + int(1) + [u"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..f2da7982d2 --- /dev/null +++ b/ext/standard/tests/array/array_udiff_assoc_basic.phpt @@ -0,0 +1,59 @@ +--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) + } +} +--UEXPECTF-- +array(3) { + [u"0.1"]=> + object(cr)#%d (1) { + [u"priv_member":u"cr":private]=> + int(9) + } + [u"0.5"]=> + object(cr)#%d (1) { + [u"priv_member":u"cr":private]=> + int(12) + } + [0]=> + object(cr)#%d (1) { + [u"priv_member":u"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..32dca57460 --- /dev/null +++ b/ext/standard/tests/array/array_udiff_basic.phpt @@ -0,0 +1,49 @@ +--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) + } +} +--UEXPECTF-- +array(2) { + [u"0.5"]=> + object(cr)#%d (1) { + [u"priv_member":u"cr":private]=> + int(12) + } + [0]=> + object(cr)#%d (1) { + [u"priv_member":u"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..2a7d142a52 --- /dev/null +++ b/ext/standard/tests/array/array_udiff_uassoc_basic.phpt @@ -0,0 +1,63 @@ +--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) + } +} +--UEXPECTF-- +array(3) { + [u"0.1"]=> + object(cr)#%d (1) { + [u"priv_member":u"cr":private]=> + int(9) + } + [u"0.5"]=> + object(cr)#%d (1) { + [u"priv_member":u"cr":private]=> + int(12) + } + [0]=> + object(cr)#%d (1) { + [u"priv_member":u"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..8dcfc7906f --- /dev/null +++ b/ext/standard/tests/array/array_uintersect_assoc_basic.phpt @@ -0,0 +1,49 @@ +--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) + } +} +--UEXPECTF-- +array(2) { + [1]=> + object(cr)#%d (1) { + [u"priv_member":u"cr":private]=> + int(4) + } + [2]=> + object(cr)#%d (1) { + [u"priv_member":u"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..02a47881ae --- /dev/null +++ b/ext/standard/tests/array/array_uintersect_basic.phpt @@ -0,0 +1,59 @@ +--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) + } +} +--UEXPECTF-- +array(3) { + [u"0.1"]=> + object(cr)#%d (1) { + [u"priv_member":u"cr":private]=> + int(9) + } + [1]=> + object(cr)#%d (1) { + [u"priv_member":u"cr":private]=> + int(4) + } + [2]=> + object(cr)#%d (1) { + [u"priv_member":u"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..8cf823399b --- /dev/null +++ b/ext/standard/tests/array/array_uintersect_uassoc_basic.phpt @@ -0,0 +1,53 @@ +--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) + } +} +--UEXPECTF-- +array(2) { + [1]=> + object(cr)#%d (1) { + [u"priv_member":u"cr":private]=> + int(4) + } + [2]=> + object(cr)#%d (1) { + [u"priv_member":u"cr":private]=> + int(-15) + } +} \ No newline at end of file -- 2.50.1