Return to levenshtein.phpt CVS log | Up to [ELWIX - Embedded LightWeight unIX -] / embedaddon / php / ext / standard / tests / strings |
1.1 misho 1: --TEST-- 2: levenshtein() function test 3: --FILE-- 4: <?php 5: 6: function test_me($title,$expect,$text1,$text2,$cost1="",$cost2="",$cost3="") { 7: 8: if ($cost1=="") { 9: $result=levenshtein($text1,$text2); 10: } 11: elseif ($cost2=="") { 12: $result=levenshtein($text1,$text2,$cost1); 13: } 14: else { 15: $result=levenshtein($text1,$text2,$cost1,$cost2,$cost3); 16: } 17: if($result==$expect) return 0; 18: 19: echo "$title: result is $result instead of $expect "; 20: echo "for '$text1'/'$text2' "; 21: if($cost1) echo "($cost1:$cost2:$cost3)"; 22: echo "\n"; 23: 24: return 1; 25: } 26: 27: $n=0; 28: 29: $n += test_me("equal" , 0, "12345", "12345"); 30: $n += test_me("1st empty" , 3, "", "xzy"); 31: $n += test_me("2nd empty" , 3, "xzy", ""); 32: $n += test_me("both empty" , 0, "", ""); 33: $n += test_me("1 char" , 1, "1", "2"); 34: $n += test_me("2 char swap", 2, "12", "21"); 35: 36: $n += test_me("inexpensive delete", 2, "2121", "11", 2, 1, 1); 37: $n += test_me("expensive delete" , 10, "2121", "11", 2, 1, 5); 38: $n += test_me("inexpensive insert", 2, "11", "2121", 1, 1, 1); 39: $n += test_me("expensive insert" , 10, "11", "2121", 5, 1, 1); 40: 41: $n += test_me("expensive replace" , 3, "111", "121", 2, 3, 2); 42: $n += test_me("very expensive replace", 4, "111", "121", 2, 9, 2); 43: 44: $n += test_me("bug #7368", 2, "13458", "12345"); 45: $n += test_me("bug #7368", 2, "1345", "1234"); 46: 47: $n += test_me("bug #6562", 1, "debugg", "debug"); 48: $n += test_me("bug #6562", 1, "ddebug", "debug"); 49: $n += test_me("bug #6562", 2, "debbbug", "debug"); 50: $n += test_me("bug #6562", 1, "debugging", "debuging"); 51: 52: $n += test_me("bug #16473", 2, "a", "bc"); 53: $n += test_me("bug #16473", 2, "xa", "xbc"); 54: $n += test_me("bug #16473", 2, "xax", "xbcx"); 55: $n += test_me("bug #16473", 2, "ax", "bcx"); 56: 57: $n += test_me("custom", -1, "111", "121", "my_levcode"); 58: $n += test_me("lt maxlength1", 254, "AbcdefghijklmnopqrstuvwxyzAbcdefghijklmnopqrstuvwxyzAbcdefghijklmnopqrstuvwxyzAbcdefghijklmnopqrstuvwxyzAbcdefghijklmnopqrtsuvwxyzAbcdefghijklmnopqrtsuvwxyzAbcdefghijklmnopqrtsuvwxyzAbcdefghijklmnopqrtsuvwxyzAbcdefghijklmnopqrtsuvwxyzAbcdefghijklmnopqrtsu", "A"); 59: $n += test_me("gt maxlength1", -1, "AbcdefghijklmnopqrstuvwxyzAbcdefghijklmnopqrstuvwxyzAbcdefghijklmnopqrstuvwxyzAbcdefghijklmnopqrstuvwxyzAbcdefghijklmnopqrtsuvwxyzAbcdefghijklmnopqrtsuvwxyzAbcdefghijklmnopqrtsuvwxyzAbcdefghijklmnopqrtsuvwxyzAbcdefghijklmnopqrtsuvwxyzAbcdefghijklmnopqrtsuv", "A"); 60: 61: $n += test_me("lt maxlength2", 254, "A", "AbcdefghijklmnopqrstuvwxyzAbcdefghijklmnopqrstuvwxyzAbcdefghijklmnopqrstuvwxyzAbcdefghijklmnopqrstuvwxyzAbcdefghijklmnopqrtsuvwxyzAbcdefghijklmnopqrtsuvwxyzAbcdefghijklmnopqrtsuvwxyzAbcdefghijklmnopqrtsuvwxyzAbcdefghijklmnopqrtsuvwxyzAbcdefghijklmnopqrtsu"); 62: $n += test_me("gt maxlength2", -1, "A", "AbcdefghijklmnopqrstuvwxyzAbcdefghijklmnopqrstuvwxyzAbcdefghijklmnopqrstuvwxyzAbcdefghijklmnopqrstuvwxyzAbcdefghijklmnopqrtsuvwxyzAbcdefghijklmnopqrtsuvwxyzAbcdefghijklmnopqrtsuvwxyzAbcdefghijklmnopqrtsuvwxyzAbcdefghijklmnopqrtsuvwxyzAbcdefghijklmnopqrtsuv"); 63: 64: echo ($n==0)?"all passed\n":"$n failed\n"; 65: 66: var_dump(levenshtein(array(), array())); 67: var_dump(levenshtein("", "", -1, -1, -1)); 68: var_dump(levenshtein("", "", 10, 10, 10)); 69: var_dump(levenshtein("")); 70: 71: ?> 72: --EXPECTF-- 73: Warning: levenshtein(): The general Levenshtein support is not there yet in %s on line %d 74: 75: Warning: levenshtein(): Argument string(s) too long in %s on line %d 76: 77: Warning: levenshtein(): Argument string(s) too long in %s on line %d 78: all passed 79: 80: Warning: levenshtein() expects parameter 1 to be string, array given in %s on line %d 81: NULL 82: int(0) 83: int(0) 84: 85: Warning: Wrong parameter count for levenshtein() in %s on line %d 86: NULL