Para los que van a hacer más de los 1000, los símbolos son los mismos que los anteriores a excepción que tienen una línea encima y eso lo puedes lograr con CSS.
Código PHP:
Ver original/*
Los que son de más de 1000 son
5000 -> '<span style="text-decoration: overline">V</span>
10000 -> '<span style="text-decoration: overline">X</span>
50000 -> '<span style="text-decoration: overline">L</span>
100000 -> '<span style="text-decoration: overline">C</span>
500000 -> '<span style="text-decoration: overline">D</span>
1000000 -> '<span style="text-decoration: overline">M</span>
*/
function assert_equals($string1, $string2)
{
return($string1 == $string2);
}
4 => 'IV',
16 => 'XVI',
66 => 'LXVI',
21 => 'XXI',
67 => 'LXVII',
13 => 'XIII',
14 => 'XIV',
34 => 'XXXIV',
100 => 'C',
50 => 'L',
129 => 'CXXIX',
750 => 'DCCL',
933 => 'CMXXXIII',
1000 => 'M',
473 => 'CDLXXIII',
333 => 'CCCXXXIII',
70 => 'LXX',
705 => 'DCCV',
0 => '',
10888 => '<span style="text-decoration: overline">X</span>DCCCLXXXVIII',
888888 => '<span style="text-decoration: overline">D</span><span style="text-decoration: overline">C</span><span style="text-decoration: overline">C</span><span style="text-decoration: overline">C</span><span style="text-decoration: overline">L</span><span style="text-decoration: overline">X</span><span style="text-decoration: overline">X</span><span style="text-decoration: overline">X</span><span style="text-decoration: overline">V</span>MMMDCCCLXXXVIII',
888 => 'DCCCLXXXVIII',
789 => 'DCCLXXXIX',
987 => 'CMLXXXVII',
385 => 'CCCLXXXV',
1001 => 'MI',
3333 => 'MMMCCCXXXIII',
389 => 'CCCLXXXIX',
760 => 'DCCLX',
999 => 'CMXCIX',
);
echo "SALIDA DE romanNumber:<br />\n";
echo "<table><tr><th>Prueba</th><th>Esperado</th><th>Salida</th><th>Resultado</th></tr>";
foreach ($tests as $test => $result) {
$rresult = romanNumber($test);
echo "<tr><td>$test</td><td>$result</td><td>$rresult</td><td>". (assert_equals($rresult, $result) ? 'OK' : 'FAIL') . "</td></tr>";
}
echo "</table>";
Debe dar algo parecido a
Código PHP:
Ver originalSALIDA DE romanNumber:
Prueba Esperado Salida Resultado
4 IV IV OK
16 XVI XVI OK
66 LXVI LXVI OK
21 XXI XXI OK
67 LXVII LXVII OK
13 XIII XIII OK
14 XIV XIV OK
34 XXXIV XXXIV OK
100 C C OK
50 L L OK
129 CXXIX CXXIX OK
750 DCCL DCCL OK
933 CMXXXIII CMXXXIII OK
1000 M M OK
473 CDLXXIII CDLXXIII OK
333 CCCXXXIII CCCXXXIII OK
70 LXX LXX OK
705 DCCV DCCV OK
0 OK
10888 XDCCCLXXXVIII XDCCCLXXXVIII OK
888888 DCCCLXXXVMMMDCCCLXXXVIII DCCCLXXXVMMMDCCCLXXXVIII OK
888 DCCCLXXXVIII DCCCLXXXVIII OK
789 DCCLXXXIX DCCLXXXIX OK
987 CMLXXXVII CMLXXXVII OK
385 CCCLXXXV CCCLXXXV OK
1001 MI MI OK
3333 MMMCCCXXXIII MMMCCCXXXIII OK
389 CCCLXXXIX CCCLXXXIX OK
760 DCCLX DCCLX OK
999 CMXCIX CMXCIX OK