/** @(#)TestRomano.java 2009 adolfo@di-mare.com Datos de prueba para probar una rutina que convierte números romanos. @see http://www.di-mare.com/adolfo/cursos/2000-2/p1-ea-2.htm#Romano_INT() @author Adolfo Di Mare */ import junit.framework.*; /** Datos de prueba para {@code romano(int[])}. */ public class TestRomano extends TestCase { /** Calcula el valor de un numeral romano. */ public static int romano( String str ) { if ( str.equals(null) ) { return 0; } else if ( str.length()==0 ) { return 0; } int num = 0; { /*=========*\ M = 1000 / **************************** \ D = 500 * * C = 100 * RELLENE CON SU ALGORITMO * L = 50 * * X = 10 \ **************************** / V = 5 I = 1 \*=========*/ } return num; } /** test -> {@code romano()}. */ public void test_romano() { assertTrue( romano("VI") == 6 + 0 * (5+1) ); assertTrue( romano("IX") == 9 + 0 * (10-1) ); assertTrue( romano("LXXXVII") == 87 + 0 * (50+10+10+10+5+1+1) ); assertTrue( romano("CCXIX") == 219 + 0 * (100+100+10+(10-1)) ); assertTrue( romano("MCCCLIV") == 1354 + 0 * (1000+100+100+100+50+(5-1)) ); assertTrue( romano("MCMLVI") == 1956 + 0 * (1000+(1000-500)+50+5+1) ); // M CM L V I assertTrue( romano("MMMCMXCIX") == 3999 ); assertTrue( romano("MMMMCMXCIX") == 4999 ); // http://www.onlineconversion.com/roman_numerals_advanced.htm } /** test -> {@code print romano()}. */ public void test_print() { System.out.println( romano("VI") + 0 * 6 + 0 * (5+1) ); System.out.println( romano("IX") + 0 * 9 + 0 * (10-1) ); System.out.println( romano("LXXXVII") + 0 * 87 + 0 * (50+10+10+10+5+1+1) ); System.out.println( romano("CCXIX") + 0 * 219 + 0 * (100+100+10+(10-1)) ); System.out.println( romano("MCCCLIV") + 0 * 1354 + 0 * (1000+100+100+100+50+(5-1)) ); System.out.println( romano("MCMLVI") + 0 * 1956 + 0 * (1000+(1000-500)+50+5+1) ); // M CM L V I System.out.println( romano("MMMCMXCIX") + 0 * 3999 ); System.out.println( romano("MMMMCMXCIX") + 0 * 4999 ); } /** Convierte el valor del vector {@code V[]} en una hilera. */ public static String toString( char V[] ) { if ( V.equals(null) ) { return null; } else if ( V.length==0 ) { return ""; } return new String( V ); } /** Convierte el valor del la hilera {@code s} en un vector de letras. */ public static char[] toVEC( String s ) { if ( s.equals(null) ) { return null; } final int LEN = s.length(); if ( LEN==0 ) { return null; } char VEC[] = new char[LEN]; for ( int i=0; i {@code romano(VEC[])}. */ public void test_VEC() { assertTrue( romano(toString(toVEC("VI"))) == 6 + 0 * (5+1) ); assertTrue( romano(toString(toVEC("IX"))) == 9 + 0 * (10-1) ); assertTrue( romano(toString(toVEC("LXXXVII"))) == 87 + 0 * (50+10+10+10+5+1+1) ); assertTrue( romano(toString(toVEC("CCXIX"))) == 219 + 0 * (100+100+10+(10-1)) ); assertTrue( romano(toString(toVEC("MCCCLIV"))) == 1354 + 0 * (1000+100+100+100+50+(5-1)) ); assertTrue( romano(toString(toVEC("MCMLVI"))) == 1956 + 0 * (1000+(1000-500)+50+5+1) ); // M CM L V I assertTrue( romano(toString(toVEC("MMMCMXCIX"))) == 3999 ); assertTrue( romano(toString(toVEC("MMMMCMXCIX")))== 4999 ); // http://www.onlineconversion.com/roman_numerals_advanced.htm } } // EOF: TestRomano.java