Ver Mensaje Individual
  #4 (permalink)  
Antiguo 02/07/2010, 21:55
Avatar de GatorV
GatorV
$this->role('moderador');
 
Fecha de Ingreso: mayo-2006
Ubicación: /home/ams/
Mensajes: 38.567
Antigüedad: 17 años, 11 meses
Puntos: 2135
Respuesta: [Desafío PHP] Función reduce()

Enviado mi código por MP, por cierto, desarrolle este script simple para que hagan pruebas:
Código PHP:
Ver original
  1. <?php
  2. include('reduce.php'); // o el archivo donde tengan su funcion
  3. function assert_equals($string1, $string2)
  4. {
  5.     return($string1 == $string2);
  6. }
  7.  
  8. $tests = array(
  9.     'abcd' => 'a-d',
  10.     'hijlbcd' => 'h-jlb-d',
  11.     'ihdlkioabcihgfe' => 'ihdlkioa-ci-e',
  12.     'cba' => 'c-a',
  13.     'zyx' => 'z-x',
  14.     'abcdcba' => 'a-d-a',
  15.     'abcddcba' => 'a-dd-a',
  16.     'abcba' => 'a-c-a',
  17.     'abcbabcdefgfec' => 'a-c-a-g-ec',
  18.     'abcdefghijklmnopqrstuvwxyz' => 'a-z',
  19.     'abhijklmnopqrstucdefgvwxyz' => 'abh-uc-gv-z',
  20.     'zzzyxqrstuv' => 'zzz-xq-v',
  21. );
  22. echo "SALIDA DE REDUCE:<br />\n";
  23. echo "<table><tr><th>Prueba</th><th>Esperado</th><th>Salida</th><th>Resultado</th></tr>";
  24. foreach ($tests as $test => $result) {
  25.     $rresult = reduce($test);
  26.     echo "<tr><td>$test</td><td>$result</td><td>$rresult</td><td>". (assert_equals($rresult, $result) ? 'OK' : 'FAIL') . "</td></tr>";
  27. }
  28. echo "</table>";

Suerte a todos