Annotation of embedaddon/php/ext/standard/tests/general_functions/003.phpt, revision 1.1.1.1

1.1       misho       1: --TEST--
                      2: levenshtein() function test
                      3: --FILE--
                      4: <?php 
                      5: 
                      6: function test_me($title,$expect,$text1,$text2,$cost1=0,$cost2=0,$cost3=0) {
                      7: 
                      8:   if($cost1==0) 
                      9:          $result=levenshtein($text1,$text2);
                     10:        else
                     11:     $result=levenshtein($text1,$text2,$cost1,$cost2,$cost3);
                     12: 
                     13:        if($result==$expect) return 0;
                     14: 
                     15:        echo "$title: result is $result instead of $expect ";
                     16:        echo "for '$text1'/'$text2' ";
                     17:        if($cost1) echo "($cost1:$cost2:$cost3)";
                     18:        echo "\n";
                     19:        
                     20:        return 1;               
                     21: }
                     22: 
                     23: $n=0;
                     24: 
                     25: $n += test_me("equal"      , 0, "12345", "12345");
                     26: $n += test_me("1st empty"  , 3,      "",   "xzy");
                     27: $n += test_me("2nd empty"  , 3,   "xzy",      "");
                     28: $n += test_me("both empty" , 0,      "",      "");
                     29: $n += test_me("1 char"     , 1,     "1",     "2");
                     30: $n += test_me("2 char swap", 2,    "12",    "21");
                     31: 
                     32: $n += test_me("inexpensive delete",  2, "2121",   "11", 2, 1, 1);
                     33: $n += test_me("expensive delete"  , 10, "2121",   "11", 2, 1, 5);
                     34: $n += test_me("inexpensive insert",  2,   "11", "2121", 1, 1, 1);
                     35: $n += test_me("expensive insert"  , 10,   "11", "2121", 5, 1, 1);
                     36: 
                     37: $n += test_me("expensive replace"     , 3, "111", "121", 2, 3, 2);
                     38: $n += test_me("very expensive replace", 4, "111", "121", 2, 9, 2);
                     39: 
                     40: $n += test_me("bug #7368", 2,     "13458",    "12345");
                     41: $n += test_me("bug #7368", 2,      "1345",     "1234");
                     42: 
                     43: $n += test_me("bug #6562", 1,    "debugg",    "debug");
                     44: $n += test_me("bug #6562", 1,    "ddebug",    "debug");
                     45: $n += test_me("bug #6562", 2,   "debbbug",    "debug");
                     46: $n += test_me("bug #6562", 1, "debugging", "debuging");
                     47: 
                     48: $n += test_me("bug #16473", 2, "a", "bc");
                     49: $n += test_me("bug #16473", 2, "xa", "xbc");
                     50: $n += test_me("bug #16473", 2, "xax", "xbcx");
                     51: $n += test_me("bug #16473", 2, "ax", "bcx");
                     52: 
                     53: 
                     54: echo ($n==0)?"all passed\n":"$n failed\n";
                     55: 
                     56: ?>
                     57: --EXPECT--
                     58: all passed

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>