Curso B谩sico de Testing en Java

Curso B谩sico de Testing en Java

Ferran Maylinch Carrasco

Ferran Maylinch Carrasco

Reto 2: Pr谩ctica de TDD

15/24

Lectura

FizzBuzz

Para practicar TDD, realizaremos este ejercicio cl谩sico.

...

Reg铆strate o inicia sesi贸n para leer el resto del contenido.

Aportes 188

Preguntas 0

Ordenar por:

驴Quieres ver m谩s aportes, preguntas y respuestas de la comunidad?

package com.platzi.javatest.fizzbuzz;

public class FizzBuzz {

    public String fizzBuzz(int n) {
        String result = "";

        if(n%3 == 0) result += "Fizz";
        if(n%5 == 0) result += "Buzz";

        return result.isEmpty() ? String.valueOf(n) : result;
    }
}

public class RomanNumerals {

    enum RomanNumeral {

        M(1000),CM(900),D(500),CD(400),
        C(100),XC(90),L(50),XL(40),
        X(10),IX(9),V(5),IV(4),
        I(1);

        private int value;

        RomanNumeral(int value) {
            this.value = value;
        }

        public int getValue() {
            return value;
        }

        public static List<RomanNumeral> getRomanNumerals() {
            return Arrays.asList(RomanNumeral.values());
        }

    }

    public static String arabicToRoman(int n) {

        StringBuilder collator = new StringBuilder();
        List<RomanNumeral> romanNumerals= RomanNumeral.getRomanNumerals();

        //Valida que el n煤mero sea menor a 4000 debido a que el formato cambia
        if (n > 0 && n < 4000) {

            int i = 0;
            while(n>0 && i<romanNumerals.size()){
                RomanNumeral currentRoman = romanNumerals.get(i);
                if(n>=currentRoman.getValue()){
                    collator.append(currentRoman);
                    n -= currentRoman.getValue();
                } else {
                    i++;
                }

            }

            String roman = collator.toString();
            return roman;

        } else {
            throw new IllegalArgumentException( n + "no est谩 en el rango (0,4000)");
        }
    }

}

Reto # 2

M茅todo refactorizado

public static String arabicToRoman(int n) {
String result = "";
	HashMap<String, Integer> romanNumerals = new LinkedHashMap();

	romanNumerals.put("M", 1000);
	romanNumerals.put("CM", 900);
	romanNumerals.put("D", 500);
	romanNumerals.put("CD", 400);
	romanNumerals.put("C", 100);
	romanNumerals.put("XC", 90);
	romanNumerals.put("L", 50);
	romanNumerals.put("XL", 40);
	romanNumerals.put("X", 10);
	romanNumerals.put("IX", 9);
	romanNumerals.put("V", 5);
	romanNumerals.put("IV", 4);
	romanNumerals.put("I", 1);

	

	for (Map.Entry<String, Integer> entry : romanNumerals.entrySet()) {
		String roman = entry.getKey();
		Integer arabic = entry.getValue();

		if (arabic == 1000 || arabic == 100 || arabic == 10 || arabic == 1) {
			while (n >= arabic) {
				result += roman;
				n = n - arabic;
			}
		} else {
			if (n >= arabic) {
				result += roman;
				n = n - arabic;
			}
		}
	}

	return result;
}

M茅todo sin refactorizar

public static String arabicToRoman(int n) {

	String result = "";

	while (n >= 1000) {
		result += "M";
		n = n - 1000;
	}

	if (n >= 900) {
		result += "CM";
		n = n - 900;
	}

	if (n >= 500) {
		result += "D";
		n = n - 500;
	}

	if (n >= 400) {
		result += "CD";
		n = n - 400;
	}

	while (n >= 100) {
		result += "C";
		n = n - 100;
	}

	if (n >= 90) {
		result += "XC";
		n = n - 90;
	}

	if (n >= 50) {
		result += "L";
		n = n - 50;
	}

	if (n >= 40) {
		result += "XL";
		n = n - 40;
	}

	while (n >= 10) {
		result += "X";
		n = n - 10;
	}

	if (n >= 9) {
		result += "IX";
		n = n - 9;
	}

	if (n >= 5) {
		result += "V";
		n = n - 5;
	}

	if (n >= 4) {
		result += "IV";
		n = n - 4;
	}

	while (n > 0) {
		result += "I";
		n--;
	}

	return result;
}

Tests


/**
 * arabicToRoman(1) => "I" 
 * arabicToRoman(2) => "II" 
 * arabicToRoman(3) => "III"
 * 
 * arabicToRoman(5) => "V" 
 * arabicToRoman(6) => "VI" 
 * arabicToRoman(7) => "VII"
 * 
 * arabicToRoman(10) => "X" 
 * arabicToRoman(11) => "XI" 
 * arabicToRoman(15) => "XV"
 * arabicToRoman(16) => "XVI"
 * 
 * arabicToRoman(50) => "L" 
 * arabicToRoman(51) => "LI" 
 * arabicToRoman(55) => "LV"
 * arabicToRoman(56) => "LVI" 
 * arabicToRoman(60) => "LX" 
 * arabicToRoman(70) => "LXX"
 * 
 * arabicToRoman(80) => "LXXX" 
 * arabicToRoman(81) => "LXXXI" 
 * arabicToRoman(85) => "LXXXV" 
 * arabicToRoman(86) => "LXXXVI"
 * 
 * arabicToRoman(126) => "CXXVI"
 * 
 * arabicToRoman(2507) => "MMDVII"
 */


@Test
public void roman_numbers_when_1_2_3() {

	assertThat(RomanNumerals.arabicToRoman(1), CoreMatchers.is("I"));
	assertThat(RomanNumerals.arabicToRoman(2), CoreMatchers.is("II"));
	assertThat(RomanNumerals.arabicToRoman(3), CoreMatchers.is("III"));

}

@Test
public void roman_numbers_when_5_6_7() {

	assertThat(RomanNumerals.arabicToRoman(5), CoreMatchers.is("V"));
	assertThat(RomanNumerals.arabicToRoman(6), CoreMatchers.is("VI"));
	assertThat(RomanNumerals.arabicToRoman(7), CoreMatchers.is("VII"));

}

@Test
public void roman_numbers_when_10_11_15_16() {

	assertThat(RomanNumerals.arabicToRoman(10), CoreMatchers.is("X"));
	assertThat(RomanNumerals.arabicToRoman(11), CoreMatchers.is("XI"));
	assertThat(RomanNumerals.arabicToRoman(15), CoreMatchers.is("XV"));
	assertThat(RomanNumerals.arabicToRoman(16), CoreMatchers.is("XVI"));

}

@Test
public void roman_numbers_when_50_51_55_56() {

	assertThat(RomanNumerals.arabicToRoman(50), CoreMatchers.is("L"));
	assertThat(RomanNumerals.arabicToRoman(51), CoreMatchers.is("LI"));
	assertThat(RomanNumerals.arabicToRoman(55), CoreMatchers.is("LV"));
	assertThat(RomanNumerals.arabicToRoman(56), CoreMatchers.is("LVI"));

}

@Test
public void roman_numbers_when_60_70() {

	assertThat(RomanNumerals.arabicToRoman(60), CoreMatchers.is("LX"));
	assertThat(RomanNumerals.arabicToRoman(70), CoreMatchers.is("LXX"));

}

@Test
public void roman_numbers_when_80_81_85_86() {

	assertThat(RomanNumerals.arabicToRoman(80), CoreMatchers.is("LXXX"));
	assertThat(RomanNumerals.arabicToRoman(81), CoreMatchers.is("LXXXI"));
	assertThat(RomanNumerals.arabicToRoman(85), CoreMatchers.is("LXXXV"));
	assertThat(RomanNumerals.arabicToRoman(86), CoreMatchers.is("LXXXVI"));

}

@Test
public void roman_numbers_when_126() {

	assertThat(RomanNumerals.arabicToRoman(126), CoreMatchers.is("CXXVI"));
}

@Test
public void roman_numbers_when_2507() {

	assertThat(RomanNumerals.arabicToRoman(2507), CoreMatchers.is("MMDVII"));
}

/**
 * arabicToRoman(4) => "IV" 
 * arabicToRoman(14) => "XIV"
 * arabicToRoman(24) => "XXIV" 
 * 
 * arabicToRoman(40) => "XL"
 * arabicToRoman(44) => "XLIV"
 * 
 * arabicToRoman(400) => "CD" 
 * 
 * arabicToRoman(9) => "IX" 
 * arabicToRoman(19) => "XIX" 
 * arabicToRoman(49) => "XLIX" 
 * 
 * arabicToRoman(90) => "XC" 
 * arabicToRoman(99) => "XCIX" 
 * 
 * arabicToRoman(900) => "CM"
 */

@Test
public void roman_numbers_when_4_14_24() {

	assertThat(RomanNumerals.arabicToRoman(4), CoreMatchers.is("IV"));
	assertThat(RomanNumerals.arabicToRoman(14), CoreMatchers.is("XIV"));
	assertThat(RomanNumerals.arabicToRoman(24), CoreMatchers.is("XXIV"));

}

@Test
public void roman_numbers_when_40() {
	
	assertThat(RomanNumerals.arabicToRoman(40), CoreMatchers.is("XL"));
	assertThat(RomanNumerals.arabicToRoman(44), CoreMatchers.is("XLIV"));

}

@Test
public void roman_numbers_when_400() {
	
	assertThat(RomanNumerals.arabicToRoman(400), CoreMatchers.is("CD"));

}

@Test
public void roman_numbers_when_9_19_49() {

	assertThat(RomanNumerals.arabicToRoman(9), CoreMatchers.is("IX"));
	assertThat(RomanNumerals.arabicToRoman(19), CoreMatchers.is("XIX"));
	assertThat(RomanNumerals.arabicToRoman(49), CoreMatchers.is("XLIX"));

}

@Test
public void roman_numbers_when_90_99() {
	
	assertThat(RomanNumerals.arabicToRoman(90), CoreMatchers.is("XC"));
	assertThat(RomanNumerals.arabicToRoman(99), CoreMatchers.is("XCIX"));

}

@Test
public void roman_numbers_when_900() {
	
	assertThat(RomanNumerals.arabicToRoman(900), CoreMatchers.is("CM"));

}

Reto #1

public static String fizzBuzz(int i) {
        String result = "";
        boolean divisible = false;
        if(i % 3 == 0){
            result += "Fizz";
            divisible = true;
        }
        if(i % 5 == 0){
            result += "Buzz";
            divisible = true;
        }
        return divisible ? result: ""+i ;
    }

Reto #2

public static String arabicToRoman(int n) {
        String result = "";

        for (int i = 0; i < n; i++) {
            result += "I";

            result = result.replaceAll("IIII", "IV");
            result = result.replaceAll("IVI", "V");

            result = result.replaceAll("VIV", "IX");
            result = result.replaceAll("IXI", "X");

            result = result.replaceAll("XXXX", "XL");
            result = result.replaceAll("XLX", "L");

            result = result.replaceAll("LXL", "XC");
            result = result.replaceAll("XCX", "C");

            result = result.replaceAll("CCCC", "CD");
            result = result.replaceAll("CDC", "D");

            result = result.replaceAll("DCD", "CM");
            result = result.replaceAll("CMC", "M");
        }
        return result;    
}

Practica 馃捇
Reto 1

public class RomanNumerals {

    public static String arabicToRoman(int n){

        String number = "";

        while(n >= 1000) { number += "M"; n -= 1000; }
        if(n >= 900) { number +="CM"; n -= 900; }
        if(n>=900) {number += "CM"; n -= 900;}
        if(n>=500) {number += "D"; n -= 500;}
        if(n>=400) {number += "CD"; n -= 400;}
        while(n>=100){number += "C"; n -= 100;}
        if(n>=90){number += "XC"; n -= 90;}
        if(n>=50){number += "L"; n -= 50;}
        if(n>=40){number += "XL"; n -=40;}
        while(n>=10){number += "X"; n -= 10;}
        if(n>=9){number += "IX"; n -=9;}
        if(n>=5){number += "V"; n -=5;}
        if(n>=4){number += "IV"; n -=4;}
        while(n>=1){number += "I"; n -= 1;}

        return number;
    }
}```
package com.practicas.tdd;

public class RomanNumerals {

	public static String arabicToRoman(int n) {

		if (n == 1000) {
			return "M";
		} else if (n > 1000) {
			return "M" + arabicToRoman(n - 1000);
		}

		if (n == 500) {
			return "D";
		} else if (n > 500 && n < 900) {
			return "D" + arabicToRoman(n - 500);
		}

		if (n == 100) {
			return "C";
		} else if (n >= 400 || n >= 900) {
			return "C" + arabicToRoman(n + 100);
		} else if (n > 100) {
			return "C" + arabicToRoman(n - 100);
		}

		if (n == 50) {
			return "L";
		} else if (n > 50 && n < 90) {
			return "L" + arabicToRoman(n - 50);
		}

		if (n == 10) {
			return "X";
		} else if (n >= 40 || n >= 90) {
			return "X" + arabicToRoman(n + 10);
		} else if (n > 10) {
			return "X" + arabicToRoman(n - 10);
		}

		if (n == 5) {
			return "V";
		} else if (n > 5 && n != 9) {
			return "V" + arabicToRoman(n - 5);
		}

		if (n == 4 || n == 9) {
			return "I" + arabicToRoman(n + 1);
		} else if (n > 1) {
			return "I" + arabicToRoman(n - 1);
		}

		return "I";

	}

}

Creo que hay un error en la parte de los n煤meros romanos:

arabicToRoman(55)"DV"
arabicToRoman(56)"DVI"
arabicToRoman(60)"DX"
arabicToRoman(70)"DXX"
arabicToRoman(80)"DXXX"
arabicToRoman(81)"DXXXI"
arabicToRoman(85)"DXXXV"
arabicToRoman(86)"DXXXVI"

Aqu铆 en lugar de ser la D creo que deber铆a ser la L.

Este peque帽o reto me hizo pensar bastante.

public class RomanNumerals {
    public static HashMap<Integer,String> numberToOneToTen = new HashMap<Integer,String>();
    public static void loadToOneToTen(){
        numberToOneToTen.put(0,"");
        numberToOneToTen.put(1,"I");
        numberToOneToTen.put(2,"II");
        numberToOneToTen.put(3,"III");
        numberToOneToTen.put(4,"IV");
        numberToOneToTen.put(5,"V");
        numberToOneToTen.put(6,"VI");
        numberToOneToTen.put(7,"VII");
        numberToOneToTen.put(8,"VII");
        numberToOneToTen.put(9,"IX");
    }
    public static String arabicToRoman(String number) {
        StringBuilder result = new StringBuilder();
        for (int i = number.length() - 1,aux = 0; i >= 0 ; i--,aux++) {
            int n = Integer.parseInt(String.valueOf(number.charAt(i)));
            if(aux == 0){
                result.append(String.format("%s",numberToOneToTen.get(n).toString()));
            }else if(aux == 1){
                String value = result.toString();
                result.setLength(0);
                result.append(String.format("%s%s",getDecimals(n),value));
            }else if(aux == 2){
                String value = result.toString();
                result.setLength(0);
                result.append(String.format("%s%s",getHundreds(n),value));
            }else if(aux == 3){
                String value = result.toString();
                result.setLength(0);
                result.append(String.format("%s%s",getThousand(n),value));
            }
        }
        return result.toString();
    }
    public static String getThousand(int number){
        StringBuilder result = new StringBuilder();
        switch (number){
            case 0:
                result.append("");
                break;
            case 1:
                result.append("M");
                break;
            case 2:
                result.append("MM");

        }
        return result.toString();
    }
    public static String getHundreds(int number){
        StringBuilder result = new StringBuilder();
        switch (number){
            case 0:
                result.append("");
                break;
            case 1:
                result.append("C");
                break;
            case 4:
                result.append("CD");
                break;
            case 5:
                result.append("D");
                break;
            case 9:
                result.append("CM");
                break;
        }
        return result.toString();
    }
    public static String getDecimals(int number){
        StringBuilder result = new StringBuilder();
        switch (number){
            case 0:
                result.append("");
                break;
            case 1:
                result.append("X");
                break;
            case 2:
                result.append("XX");
                break;
            case 3:
                result.append("XXX");
                break;
            case 4:
                result.append("XL");
                break;
            case 5:
                result.append("L");
                break;
            case 6:
                result.append("LX");
                break;
            case 7:
                result.append("LXX");
                break;
            case 8:
                result.append("LXXX");
                break;
            case 9:
                result.append("XC");
                break;
        }
        return result.toString();
    }
}
public class RomanNumeralsTest {

    @Before
    public void set(){
        RomanNumerals.loadToOneToTen();
    }
    @Test
    public void valid_number_1_to_roman(){
        assertEquals("I",RomanNumerals.arabicToRoman("1"));
    }
    @Test
    public void valid_number_2_to_roman(){
        assertEquals("II",RomanNumerals.arabicToRoman("2"));
    }
    @Test
    public void valid_number_3_to_roman(){
        assertEquals("III",RomanNumerals.arabicToRoman("3"));
    }
    @Test
    public void valid_number_5_to_roman(){
        assertEquals("V",RomanNumerals.arabicToRoman("5"));
    }

    @Test
    public void valid_number_6_to_roman(){
        assertEquals("VI",RomanNumerals.arabicToRoman("6"));
    }
    @Test
    public void valid_number_7_to_roman(){
        assertEquals("VII",RomanNumerals.arabicToRoman("7"));
    }
    @Test
    public void valid_number_10_to_roman(){
        assertEquals("X",RomanNumerals.arabicToRoman("10"));
    }
    @Test
    public void valid_number_11_to_roman(){
        assertEquals("XI",RomanNumerals.arabicToRoman("11"));
    }
    @Test
    public void valid_number_15_to_roman(){
        assertEquals("XV",RomanNumerals.arabicToRoman("15"));
    }
    @Test
    public void valid_number_16_to_roman(){
        assertEquals("XVI",RomanNumerals.arabicToRoman("16"));
    }
    @Test
    public void valid_number_50_to_roman(){
        assertEquals("L",RomanNumerals.arabicToRoman("50"));
    }
    @Test
    public void valid_number_51_to_roman(){
        assertEquals("LI",RomanNumerals.arabicToRoman("51"));
    }
    @Test
    public void valid_number_55_to_roman(){
        assertEquals("LV",RomanNumerals.arabicToRoman("55"));
    }
    @Test
    public void valid_number_56_to_roman(){
        assertEquals("LVI",RomanNumerals.arabicToRoman("56"));
    }
    @Test
    public void valid_number_60_to_roman(){
        assertEquals("LX",RomanNumerals.arabicToRoman("60"));
    }
    @Test
    public void valid_number_70_to_roman(){
        assertEquals("LXX",RomanNumerals.arabicToRoman("70"));
    }
    @Test
    public void valid_number_80_to_roman(){
        assertEquals("LXXX",RomanNumerals.arabicToRoman("80"));
    }
    @Test
    public void valid_number_81_to_roman(){
        assertEquals("LXXXI",RomanNumerals.arabicToRoman("81"));
    }
    @Test
    public void valid_number_85_to_roman(){
        assertEquals("LXXXV",RomanNumerals.arabicToRoman("85"));
    }
    @Test
    public void valid_number_86_to_roman(){
        assertEquals("LXXXVI",RomanNumerals.arabicToRoman("86"));
    }
    @Test
    public void valid_number_126_to_roman(){
        assertEquals("CXXVI",RomanNumerals.arabicToRoman("126"));
    }
    @Test
    public void valid_number_2507_to_roman(){
        assertEquals("MMDVII",RomanNumerals.arabicToRoman("2507"));
    }
    @Test
    public void valid_number_4_to_roman(){
        assertEquals("IV",RomanNumerals.arabicToRoman("4"));
    }
    @Test
    public void valid_number_9_to_roman(){
        assertEquals("IX",RomanNumerals.arabicToRoman("9"));
    }
    @Test
    public void valid_number_14_to_roman(){
        assertEquals("XIV",RomanNumerals.arabicToRoman("14"));
    }
    @Test
    public void valid_number_19_to_roman(){
        assertEquals("XIX",RomanNumerals.arabicToRoman("19"));
    }
    @Test
    public void valid_number_24_to_roman(){
        assertEquals("XXIV",RomanNumerals.arabicToRoman("24"));
    }
    @Test
    public void valid_number_40_to_roman(){
        assertEquals("XL",RomanNumerals.arabicToRoman("40"));
    }
    @Test
    public void valid_number_49_to_roman(){
        assertEquals("XLIX",RomanNumerals.arabicToRoman("49"));
    }
    @Test
    public void valid_number_90_to_roman(){
        assertEquals("XC",RomanNumerals.arabicToRoman("90"));
    }
    @Test
    public void valid_number_99_to_roman(){
        assertEquals("XCIX",RomanNumerals.arabicToRoman("99"));
    }
    @Test
    public void valid_number_400_to_roman(){
        assertEquals("CD",RomanNumerals.arabicToRoman("400"));
    }
    @Test
    public void valid_number_900_to_roman(){
        assertEquals("CM",RomanNumerals.arabicToRoman("900"));
    }
}

Reto extra: N煤meros Romanos

Luego de mucho analisis lo logre! buen ejercicio para entrenar la logica, la clave para mi estaba en entender como va el patron de conversi贸n de numeros enteros a numeros romanos, antes de escribir culquier linea de codigo, luego de encontrar el patron si comence con el algoritmo, modularice la funcionalidad para no cargar toda la logica en la funci贸n principal arabicToRoman el codigo por ahora solo transforma numeros del 1 (I) al 3999 (MMMCMXCIX), se puede seguir desarrollando para agregar mas pero por ahora lo deje asi, tambien controla que los numeros sean mayores a 0, ahora la clase RomanNumerals:

package com.platzi.javatest.reto2;

public class RomanNumerals {

    public static String arabicToRoman(int n){
        String numeroRomanoFinal = "";

        if (n <= 0){
            numeroRomanoFinal = "Error";
        }else if (Integer.toString(n).length() == 1){
            numeroRomanoFinal = evaluaDecimal(n);
        }else {
            while (n > 0) {
                int fraccionDecimal = numeroDecimalRestar(n);
                String fraccionRomana = evaluaDecimal(fraccionDecimal);
                numeroRomanoFinal = numeroRomanoFinal + fraccionRomana;
                n = n - fraccionDecimal;
            }
        }

        return numeroRomanoFinal;
    }

    public static Integer numeroDecimalRestar(int n){
        char[] arrayNumeroSeparado = Integer.toString(n).toCharArray();
        char primerNumero = arrayNumeroSeparado[0];
        int cantidadCeros = arrayNumeroSeparado.length - 1;
        int auxcantidadCeros = cantidadCeros;
        String ceros = "";
        while (auxcantidadCeros > 0){
            ceros = ceros + "0";
            auxcantidadCeros--;
        }
        String numeroDecimal = primerNumero + ceros;

        return Integer.parseInt(numeroDecimal);
    }

    public static String evaluaDecimal(int n){
        String numeroRomano = "";
        switch (n){
            case 1:
                numeroRomano = "I";
                break;
            case 2:
                numeroRomano = "II";
                break;
            case 3:
                numeroRomano = "III";
                break;
            case 4:
                numeroRomano = "IV";
                break;
            case 5:
                numeroRomano = "V";
                break;
            case 6:
                numeroRomano = "VI";
                break;
            case 7:
                numeroRomano = "VII";
                break;
            case 8:
                numeroRomano = "VIII";
                break;
            case 9:
                numeroRomano = "IX";
                break;
            case 10:
                numeroRomano = "X";
                break;
            case 20:
                numeroRomano = "XX";
                break;
            case 30:
                numeroRomano = "XXX";
                break;
            case 40:
                numeroRomano = "XL";
                break;
            case 50:
                numeroRomano = "L";
                break;
            case 60:
                numeroRomano = "LX";
                break;
            case 70:
                numeroRomano = "LXX";
                break;
            case 80:
                numeroRomano = "LXXX";
                break;
            case 90:
                numeroRomano = "XC";
                break;
            case 100:
                numeroRomano = "C";
                break;
            case 200:
                numeroRomano = "CC";
                break;
            case 300:
                numeroRomano = "CCC";
                break;
            case 400:
                numeroRomano = "CD";
                break;
            case 500:
                numeroRomano = "D";
                break;
            case 600:
                numeroRomano = "DC";
                break;
            case 700:
                numeroRomano = "DCC";
                break;
            case 800:
                numeroRomano = "DCC";
                break;
            case 900:
                numeroRomano = "CM";
                break;
            case 1000:
                numeroRomano = "M";
                break;
            case 2000:
                numeroRomano = "MM";
                break;
            case 3000:
                numeroRomano = "MMM";
                break;
        }
        return numeroRomano;
    }
}

Ahora la clase de test:

package com.platzi.javatest.reto2;

import org.junit.Test;

import static org.junit.Assert.*;

public class RomanNumeralsTest {

    @Test
    public void return_I_when_number_is_1(){
        assertEquals("I", RomanNumerals.arabicToRoman(1));
    }

    @Test
    public void return_II_when_number_is_2(){
        assertEquals("II", RomanNumerals.arabicToRoman(2));
    }

    @Test
    public void return_III_when_number_is_3(){
        assertEquals("III", RomanNumerals.arabicToRoman(3));
    }

    @Test
    public void return_V_when_number_is_5(){
        assertEquals("V", RomanNumerals.arabicToRoman(5));
    }

    @Test
    public void return_VI_when_number_is_6(){
        assertEquals("VI", RomanNumerals.arabicToRoman(6));
    }

    @Test
    public void return_VII_when_number_is_7(){
        assertEquals("VII", RomanNumerals.arabicToRoman(7));
    }

    @Test
    public void return_X_when_number_is_10(){
        assertEquals("X", RomanNumerals.arabicToRoman(10));
    }

    @Test
    public void return_XCIX_when_number_is_99(){
        assertEquals("XCIX", RomanNumerals.arabicToRoman(99));
    }

    @Test
    public void return_MMMCMXCIX_when_number_is_3999(){
        assertEquals("MMMCMXCIX", RomanNumerals.arabicToRoman(3999));
    }

    @Test
    public void return_MDCCXXXVIII_when_number_is_1738(){
        assertEquals("MDCCXXXVIII", RomanNumerals.arabicToRoman(1738));
    }

    @Test
    public void return_CMXLIII_when_number_is_943(){
        assertEquals("CMXLIII", RomanNumerals.arabicToRoman(943));
    }

    @Test
    public void return_Error_when_number_is_0(){
        assertEquals("Error", RomanNumerals.arabicToRoman(0));
    }

    @Test
    public void return_Error_when_number_is_negative(){
        assertEquals("Error", RomanNumerals.arabicToRoman(-56));
    }
}
public class FizzBuzz {

    public static String comprueba (Integer num){
        if ((num%5==0)&&(num%3==0)){return "FIZZBUZZ";}
        if ((num%3==0)){return "FIZZ";}
        if ((num%5==0)){return "BUZZ";}

        return (num.toString());
    }

}
public class FizzBuzzTest {

    @Test
    public void fizzbuzz_3(){assertEquals("FIZZ", FizzBuzz.comprueba(3)); }
    @Test
    public void fizzbuzz_6(){
        assertEquals("FIZZ", FizzBuzz.comprueba(6));
    }
    @Test
    public void fizzbuzz_5(){
        assertEquals("BUZZ", FizzBuzz.comprueba(5));
    }
    @Test
    public void fizzbuzz_10(){
        assertEquals("BUZZ", FizzBuzz.comprueba(10));
    }
    @Test
    public void fizzbuzz_15(){
        assertEquals("FIZZBUZZ", FizzBuzz.comprueba(15));
    }
    @Test
    public void fizzbuzz_30(){
        assertEquals("FIZZBUZZ", FizzBuzz.comprueba(30));
    }
    @Test
    public void fizzbuzz_2(){
        assertEquals("2", FizzBuzz.comprueba(2));
    }
    @Test
    public void fizzbuzz_16(){
        assertEquals("16", FizzBuzz.comprueba(16));
    }

}

Reto #1

package com.platzi.javatests.challenges;

public class FizzBuzz {

    public static String fizzBuzz(int n){

        String result = "";

        if ( n % 3 == 0 && n % 5 == 0){
            result = "FizzBuzz";
        } else if ( n % 3 == 0 ) {
            result = "Fizz";
        } else if (n % 5 == 0){
            result = "Buzz";
        } else {
            result = String.valueOf(n);
        }

        return result;
    }
}

Reto #2

package com.platzi.javatests.challenges;

public class RomanNumerals {

    public static String arabicToRoman(int n) {

        int i, miles, centenas, decenas, unidades;
        String romano = "";
        //obtenemos cada cifra del n煤mero
        miles = n / 1000;
        centenas = n / 100 % 10;
        decenas = n / 10 % 10;
        unidades = n % 10;

        //millar
        for (i = 1; i <= miles; i++) {
            romano = romano + "M";
        }

        //centenas
        if (centenas == 9) {
            romano = romano + "CM";
        } else if (centenas >= 5) {
            romano = romano + "D";
            for (i = 6; i <= centenas; i++) {
                romano = romano + "C";
            }
        } else if (centenas == 4) {
            romano = romano + "CD";
        } else {
            for (i = 1; i <= centenas; i++) {
                romano = romano + "C";
            }
        }

        //decenas
        if (decenas == 9) {
            romano = romano + "XC";
        } else if (decenas >= 5) {
            romano = romano + "L";
            for (i = 6; i <= decenas; i++) {
                romano = romano + "X";
            }
        } else if (decenas == 4) {
            romano = romano + "XL";
        } else {
            for (i = 1; i <= decenas; i++) {
                romano = romano + "X";
            }
        }

        //unidades
        if (unidades == 9) {
            romano = romano + "IX";
        } else if (unidades >= 5) {
            romano = romano + "V";
            for (i = 6; i <= unidades; i++) {
                romano = romano + "I";
            }
        } else if (unidades == 4) {
            romano = romano + "IV";
        } else {
            for (i = 1; i <= unidades; i++) {
                romano = romano + "I";
            }
        }
        return romano;

    }

}

public class RomanNumerals {

	private static String romanOne = "I";
	private static String romanFive = "V";
	private static String romanTen = "X";
	private static String romanFifty = "L";
	private static String romanHundred = "C";
	private static String romanFiveHundred = "D";
	private static String romanThounsand = "M";
	private static String romanNumeralResult = "";

	public static String arabicToRoman(int n) {

		if(n >= 1000 && n < 4000) {
			appendRomanNumeral(romanThounsand);
			arabicToRoman(n - 1000);
		}
		if(n >= 900 && n < 1000) {
			appendRomanNumeral(romanHundred + romanThounsand);
			arabicToRoman(n - 900);
		}
		if(n >= 500 && n < 900){
			appendRomanNumeral(romanFiveHundred);
			arabicToRoman(n - 500);
		}
		if(n >= 400 && n < 500) {
			appendRomanNumeral(romanHundred + romanFiveHundred);
			arabicToRoman(n - 400);
		}
		if(n >= 100 && n < 400) {
			appendRomanNumeral(romanHundred);
			arabicToRoman(n - 100);
		}
		if(n >= 90 && n < 100) {
			appendRomanNumeral(romanTen + romanHundred);
			arabicToRoman(n - 90);
		}
		if(n >= 50 && n < 90) {
			appendRomanNumeral(romanFifty);
			arabicToRoman(n - 50);
		}
		if(n >= 40 && n < 50) {
			appendRomanNumeral(romanTen + romanFifty);
			arabicToRoman(n - 40);
		}
		if(n >= 10 && n < 40) {
			appendRomanNumeral(romanTen);
			arabicToRoman(n - 10);
		}
		if(n == 9) {
			appendRomanNumeral(romanOne + romanTen);
			arabicToRoman(n - 9);
		}
		if(n >= 5 && n < 9) {
			appendRomanNumeral(romanFive);
			arabicToRoman(n - 5);
		}
		if(n == 4) {
			appendRomanNumeral(romanOne + romanFive);
			arabicToRoman(n - 4);
		}
		if(n >= 1 && n < 4) {
			appendRomanNumeral(romanOne);
			arabicToRoman(n - 1);
		}
		return romanNumeralResult;
	}

	private static void appendRomanNumeral(String romanNumeral) {
		romanNumeralResult += romanNumeral;
	}

	public static void cleanRomanNumeral() {
		romanNumeralResult = "";
	}
}

Reto extra: N煤meros Romanos

package com.platzi.javatests.reto2;

public class RomanNumerals {
    public static String arabicToRoman(int n) {

        int aux, contador = 0, factor, descomponer;
        String individual = "", total="";

        aux = n;

        while(aux!=0){

            aux = aux/ 10;
            contador++;

        }

        factor = (int) Math.pow(10, (contador-1));

        while(factor!=0){

            n = (int) (n%(Math.pow(10, contador)));

            descomponer = (n/factor)*factor;

            System.out.println("numero: " + descomponer);

            contador--;

            factor = factor/10;

            switch (descomponer){
                case 0: individual = "";
                    break;
                case 1: individual = "I";
                    break;
                case 2: individual = "II";
                    break;
                case 3: individual = "III";
                    break;
                case 4: individual = "IV";
                    break;
                case 5: individual = "V";
                    break;
                case 6: individual = "VI";
                    break;
                case 7: individual = "VII";
                    break;
                case 8: individual = "VIII";
                    break;
                case 9: individual = "IX";
                    break;
                case 10: individual = "X";
                    break;
                case 20: individual = "XX";
                    break;
                case 30: individual = "XXX";
                    break;
                case 40: individual = "XL";
                    break;
                case 50: individual = "L";
                    break;
                case 60: individual = "LX";
                    break;
                case 70: individual = "LXX";
                    break;
                case 80: individual = "LXXX";
                    break;
                case 90: individual = "XC";
                    break;
                case 100: individual = "C";
                    break;
                case 200: individual = "CC";
                    break;
                case 300: individual = "CCC";
                    break;
                case 400: individual = "CD";
                    break;
                case 500: individual = "D";
                    break;
                case 600: individual = "DC";
                    break;
                case 700: individual = "DCC";
                    break;
                case 800: individual = "DCCC";
                    break;
                case 900: individual = "CM";
                    break;
                case 1000: individual = "M";
                    break;
                case 2000: individual = "MM";
                    break;
                case 3000: individual = "MMM";
                    break;
            }

            total = total+individual;

        }

        return total;

    }
}
package com.platzi.javatests.reto2;

import org.junit.Test;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.*;

public class RomanNumeralsShould {

    @Test
    public void when_number_is_1() {
        assertThat(RomanNumerals.arabicToRoman(1), is("I"));
    }

    @Test
    public void when_number_is_2() {
        assertThat(RomanNumerals.arabicToRoman(2), is("II"));
    }

    @Test
    public void when_number_is_3() {
        assertThat(RomanNumerals.arabicToRoman(3), is("III"));
    }

    @Test
    public void when_number_is_4() {
        assertThat(RomanNumerals.arabicToRoman(4), is("IV"));
    }

    @Test
    public void when_number_is_5() {
        assertThat(RomanNumerals.arabicToRoman(5), is("V"));
    }

    @Test
    public void when_number_is_6() {
        assertThat(RomanNumerals.arabicToRoman(6), is("VI"));
    }

    @Test
    public void when_number_is_7() {
        assertThat(RomanNumerals.arabicToRoman(7), is("VII"));
    }

    @Test
    public void when_number_is_8() {
        assertThat(RomanNumerals.arabicToRoman(8), is("VIII"));
    }

    @Test
    public void when_number_is_9() {
        assertThat(RomanNumerals.arabicToRoman(9), is("IX"));
    }

    @Test
    public void when_number_is_10() {
        assertThat(RomanNumerals.arabicToRoman(10), is("X"));
    }

    @Test
    public void when_number_is_11() {
        assertThat(RomanNumerals.arabicToRoman(11), is("XI"));
    }

    @Test
    public void when_number_is_14() {
        assertThat(RomanNumerals.arabicToRoman(14), is("XIV"));
    }

    @Test
    public void when_number_is_15() {
        assertThat(RomanNumerals.arabicToRoman(15), is("XV"));
    }

    @Test
    public void when_number_is_16() {
        assertThat(RomanNumerals.arabicToRoman(16), is("XVI"));
    }

    @Test
    public void when_number_is_19() {
        assertThat(RomanNumerals.arabicToRoman(19), is("XIX"));
    }

    @Test
    public void when_number_is_24() {
        assertThat(RomanNumerals.arabicToRoman(24), is("XXIV"));
    }

    @Test
    public void when_number_is_40() {
        assertThat(RomanNumerals.arabicToRoman(40), is("XL"));
    }

    @Test
    public void when_number_is_49() {
        assertThat(RomanNumerals.arabicToRoman(49), is("XLIX"));
    }

    @Test
    public void when_number_is_50() {
        assertThat(RomanNumerals.arabicToRoman(50), is("L"));
    }

    @Test
    public void when_number_is_51() {
        assertThat(RomanNumerals.arabicToRoman(51), is("LI"));
    }

    @Test
    public void when_number_is_55() {
        assertThat(RomanNumerals.arabicToRoman(55), is("LV"));
    }

    @Test
    public void when_number_is_56() {
        assertThat(RomanNumerals.arabicToRoman(56), is("LVI"));
    }

    @Test
    public void when_number_is_60() {
        assertThat(RomanNumerals.arabicToRoman(60), is("LX"));
    }

    @Test
    public void when_number_is_70() {
        assertThat(RomanNumerals.arabicToRoman(70), is("LXX"));
    }

    @Test
    public void when_number_is_80() {
        assertThat(RomanNumerals.arabicToRoman(80), is("LXXX"));
    }

    @Test
    public void when_number_is_81() {
        assertThat(RomanNumerals.arabicToRoman(81), is("LXXXI"));
    }

    @Test
    public void when_number_is_85() {
        assertThat(RomanNumerals.arabicToRoman(85), is("LXXXV"));
    }

    @Test
    public void when_number_is_86() {
        assertThat(RomanNumerals.arabicToRoman(86), is("LXXXVI"));
    }

    @Test
    public void when_number_is_90() {
        assertThat(RomanNumerals.arabicToRoman(90), is("XC"));
    }

    @Test
    public void when_number_is_99() {
        assertThat(RomanNumerals.arabicToRoman(99), is("XCIX"));
    }

    @Test
    public void when_number_is_126() {
        assertThat(RomanNumerals.arabicToRoman(126), is("CXXVI"));
    }

    @Test
    public void when_number_is_400() {
        assertThat(RomanNumerals.arabicToRoman(400), is("CD"));
    }

    @Test
    public void when_number_is_900() {
        assertThat(RomanNumerals.arabicToRoman(900), is("CM"));
    }

    @Test
    public void when_number_is_2507() {
        assertThat(RomanNumerals.arabicToRoman(2507), is("MMDVII"));
    }
}```

Reto #1:

public class FizzBuzz {
    public static String fizzBuzz(int num){
        return (num % 3) + (num % 5) == 0 ?  "FizzBuzz" : num % 3 == 0 ? "Fizz" : num % 5 ==0 ? "Buzz": num+"";
    }
}

Reto extra:
RomanNumerals

public class RomanNumerals {

    public static String arabicToRoman(int number) {

        StringBuilder romanNumber = new StringBuilder();

        final int ARABIC_NUMBER_1    = 1;
        final int ARABIC_NUMBER_5    = 5;
        final int ARABIC_NUMBER_10   = 10;
        final int ARABIC_NUMBER_50   = 50;
        final int ARABIC_NUMBER_100  = 100;
        final int ARABIC_NUMBER_500  = 500;
        final int ARABIC_NUMBER_1000 = 1000;

        final String ROMAN_NUMBER_I = "I";
        final String ROMAN_NUMBER_V = "V";
        final String ROMAN_NUMBER_X = "X";
        final String ROMAN_NUMBER_L = "L";
        final String ROMAN_NUMBER_C = "C";
        final String ROMAN_NUMBER_D = "D";
        final String ROMAN_NUMBER_M = "M";

        while (number > 0) {

            if (number >= ARABIC_NUMBER_1000) { //miles OK
                number -= ARABIC_NUMBER_1000;
                romanNumber.append(ROMAN_NUMBER_M);
            } else if (number >= 900) {
                number -= 900;
                romanNumber.append(ROMAN_NUMBER_C);
                romanNumber.append(ROMAN_NUMBER_M);
            } else if (number >= ARABIC_NUMBER_500) { //quinientos OK
                number -= ARABIC_NUMBER_500;
                romanNumber.append(ROMAN_NUMBER_D);
            } else if (number >=400) {
                number -= 400;
                romanNumber.append(ROMAN_NUMBER_C);
                romanNumber.append(ROMAN_NUMBER_D);
            } else if (number >= ARABIC_NUMBER_100) { //cientos OK
                number -= ARABIC_NUMBER_100;
                romanNumber.append(ROMAN_NUMBER_C);
            } else if (number >= 90) {
                number -= 90;
                romanNumber.append(ROMAN_NUMBER_X);
                romanNumber.append(ROMAN_NUMBER_C);
            } else if (number >= ARABIC_NUMBER_50) { //cincuentas OK
                number -= ARABIC_NUMBER_50;
                romanNumber.append(ROMAN_NUMBER_L);
            } else if (number >= 40) {
                number -= 40;
                romanNumber.append(ROMAN_NUMBER_X);
                romanNumber.append(ROMAN_NUMBER_L);
            } else if (number >= ARABIC_NUMBER_10) { //decenas OK
                number -= ARABIC_NUMBER_10;
                romanNumber.append(ROMAN_NUMBER_X);
            } else if (number >= 9) {
                number -= 9;
                romanNumber.append(ROMAN_NUMBER_I);
                romanNumber.append(ROMAN_NUMBER_X);
            } else if (number >= ARABIC_NUMBER_5) { //cincos OK
                number -= ARABIC_NUMBER_5;
                romanNumber.append(ROMAN_NUMBER_V);
            } else if (number >= 4) {
                number -= 4;
                romanNumber.append(ROMAN_NUMBER_I);
                romanNumber.append(ROMAN_NUMBER_V);
            } else {
                number -= ARABIC_NUMBER_1;
                romanNumber.append(ROMAN_NUMBER_I);
            }
        }

        return romanNumber.toString().toString();
    }
}

RomanNumeralsShould

class RomanNumeralsShould {

    @Test
    public void be_I_when_the_input_is_one() {
        assertEquals("I",RomanNumerals.arabicToRoman(1));
    }

    @Test
    public void be_II_when_the_input_is_two() {
        assertEquals("II",RomanNumerals.arabicToRoman(2));
    }

    @Test
    public void be_III_when_the_input_is_three() {
        assertEquals("III",RomanNumerals.arabicToRoman(3));
    }

    @Test
    public void be_V_when_the_input_is_five() {
        assertEquals("V",RomanNumerals.arabicToRoman(5));
    }

    @Test
    public void be_VI_when_the_input_is_six() {
        assertEquals("VI",RomanNumerals.arabicToRoman(6));
    }

    @Test
    public void be_VII_when_the_input_is_seven() {
        assertEquals("VII",RomanNumerals.arabicToRoman(7));
    }

    @Test
    public void be_X_when_the_input_is_ten() {
        assertEquals("X",RomanNumerals.arabicToRoman(10));
    }

    @Test
    public void be_XI_when_the_input_is_eleven() {
        assertEquals("XI",RomanNumerals.arabicToRoman(11));
    }

    @Test
    public void be_XV_when_the_input_is_fiveteen() {
        assertEquals("XV",RomanNumerals.arabicToRoman(15));
    }

    @Test
    public void be_XVI_when_the_input_is_sixteen() {
        assertEquals("XVI",RomanNumerals.arabicToRoman(16));
    }

    @Test
    public void be_L_when_the_input_is_fivety() {
        assertEquals("L",RomanNumerals.arabicToRoman(50));
    }

    @Test
    public void be_LI_when_the_input_is_fivety_one() {
        assertEquals("LI",RomanNumerals.arabicToRoman(51));
    }

    @Test
    public void be_LV_when_the_input_is_fivety_five() {
        assertEquals("LV",RomanNumerals.arabicToRoman(55));
    }

    @Test
    public void be_LVI_when_the_input_is_fivety_six() {
        assertEquals("LVI",RomanNumerals.arabicToRoman(56));
    }

    @Test
    public void be_LX_when_the_input_is_sixty() {
        assertEquals("LX",RomanNumerals.arabicToRoman(60));
    }

    @Test
    public void be_LXX_when_the_input_is_seventy() {
        assertEquals("LXX",RomanNumerals.arabicToRoman(70));
    }

    @Test
    public void be_LXXX_when_the_input_is_eighty() {
        assertEquals("LXXX",RomanNumerals.arabicToRoman(80));
    }

    @Test
    public void be_LXXXI_when_the_input_is_eighty_one() {
        assertEquals("LXXXI",RomanNumerals.arabicToRoman(81));
    }

    @Test
    public void be_LXXXV_when_the_input_is_eighty_five() {
        assertEquals("LXXXV",RomanNumerals.arabicToRoman(85));
    }

    @Test
    public void be_LXXXVI_when_the_input_is_eighty_six() {
        assertEquals("LXXXVI",RomanNumerals.arabicToRoman(86));
    }

    @Test
    public void be_CXXVI_when_the_input_is_one_hundred_thenty_six() {
        assertEquals("CXXVI",RomanNumerals.arabicToRoman(126));
    }

    @Test
    public void be_MMDVII_when_the_input_is_two_thousand_five_hundred_seven() {
        assertEquals("MMDVII",RomanNumerals.arabicToRoman(2507));
    }

    @Test
    public void be_IV_when_the_input_is_four() {
        assertEquals("IV",RomanNumerals.arabicToRoman(4));
    }

    @Test
    public void be_IX_when_the_input_is_nine() {
        assertEquals("IX",RomanNumerals.arabicToRoman(9));
    }

    @Test
    public void be_XIV_when_the_input_is_fourteen() {
        assertEquals("XIV",RomanNumerals.arabicToRoman(14));
    }

    @Test
    public void be_XIX_when_the_input_is_nineteen() {
        assertEquals("XIX",RomanNumerals.arabicToRoman(19));
    }

    @Test
    public void be_XXIV_when_the_input_is_twenty_four() {
        assertEquals("XXIV",RomanNumerals.arabicToRoman(24));
    }

    @Test
    public void be_XL_when_the_input_is_fourty() {
        assertEquals("XL",RomanNumerals.arabicToRoman(40));
    }

    @Test
    public void be_XLIX_when_the_input_is_fourty_nine() {
        assertEquals("XLIX",RomanNumerals.arabicToRoman(49));
    }

    @Test
    public void be_XC_when_the_input_is_ninety() {
        assertEquals("XC",RomanNumerals.arabicToRoman(90));
    }

    @Test
    public void be_XCIX_when_the_input_is_ninety_nine() {
        assertEquals("XCIX",RomanNumerals.arabicToRoman(99));
    }

    @Test
    public void be_CD_when_the_input_is_four_hundred() {
        assertEquals("CD",RomanNumerals.arabicToRoman(400));
    }

    @Test
    public void be_CM_when_the_input_is_nine_hundred() {
        assertEquals("CM",RomanNumerals.arabicToRoman(900));
    }
}
public class RomanNumber implements Comparable<RomanNumber>{
    private String romanNumber;
    private int arabicValue;
    private int cantRepetitions;

    public RomanNumber(String romanNumber, int arabicValue,int cantRepetitions) {
        this.romanNumber = romanNumber;
        this.arabicValue = arabicValue;
        this.cantRepetitions = cantRepetitions;
    }

    public String getRomanNumber() {
        return romanNumber;
    }

    public int getArabicValue() {
        return arabicValue;
    }

    @Override
    public int compareTo(RomanNumber comparator) {
        return comparator.getArabicValue();
    }

    public int getCantRepetitions() {
        return cantRepetitions;
    }

    public String toString(){
        return romanNumber;
    }

    public int getMaxCantValue(){
        return cantRepetitions * arabicValue;
    }
}

public class RomanNumerals {

    private final static List <RomanNumber> romanNumbers  = new ArrayList<>();
    private final static Map <String, RomanNumber> substractionRules = new HashMap<>();

    static {
        RomanNumber romanNumberI = new RomanNumber("I", 1, 3);
        RomanNumber romanNumberV = new RomanNumber("V", 5, 1);
        RomanNumber romanNumberX = new RomanNumber("X", 10, 3);
        RomanNumber romanNumberL = new RomanNumber("L", 50, 1);
        RomanNumber romanNumberC = new RomanNumber("C", 100, 3);
        RomanNumber romanNumberD = new RomanNumber("D", 500, 1);
        RomanNumber romanNumberM = new RomanNumber("M", 1000, 3);

        romanNumbers.add(romanNumberI);
        romanNumbers.add(romanNumberV);
        romanNumbers.add(romanNumberX);
        romanNumbers.add(romanNumberL);
        romanNumbers.add(romanNumberC);
        romanNumbers.add(romanNumberD);
        romanNumbers.add(romanNumberM);

        Collections.sort(romanNumbers,(x,y)-> x.getArabicValue() < y.getArabicValue() ? -1 : 1);

        substractionRules.put("V",romanNumberI);
        substractionRules.put("X",romanNumberI);
        substractionRules.put("L",romanNumberX);
        substractionRules.put("C",romanNumberX);
        substractionRules.put("D",romanNumberC);
        substractionRules.put("M",romanNumberC);
    }

    public static String arabicToRoman(int number){
        return arabicToRoman(number,new StringBuilder());
    }

    public static String arabicToRoman(int number,StringBuilder stringBuilder){
        RomanNumber maxRomanNumberRepresentation = getMaxRomanNumberRepresentation(number);
        if(maxRomanNumberRepresentation.getArabicValue() > number){
            RomanNumber substractionRomanNumber = substractionRules.get(maxRomanNumberRepresentation.getRomanNumber());
            int substraction = maxRomanNumberRepresentation.getArabicValue() - substractionRomanNumber.getArabicValue();
            if(number - substraction == 0)
                stringBuilder
                        .append(substractionRomanNumber.getRomanNumber())
                        .append(maxRomanNumberRepresentation.getRomanNumber());
            else{
                int maxCantValue = substractionRomanNumber.getMaxCantValue();
                if(maxCantValue < number && substraction < number){
                    stringBuilder
                            .append(substractionRomanNumber)
                            .append(maxRomanNumberRepresentation);
                    int result = number - maxRomanNumberRepresentation.getArabicValue() + substractionRomanNumber.getArabicValue();
                    if(result != 0)
                        arabicToRoman(result, stringBuilder);
                }else {
                    RomanNumber inmediateInferior = getInmediateInferior(maxRomanNumberRepresentation);
                    stringBuilder.append(inmediateInferior);
                    int result = number - inmediateInferior.getArabicValue();
                    if (result != 0)
                        arabicToRoman(result, stringBuilder);
                }
            }
        }else{
            int result = appendWhileMaxNumber(number, maxRomanNumberRepresentation, stringBuilder);
            if(result != 0)
                arabicToRoman(result,stringBuilder);
        }

        return stringBuilder.toString();
    }


    private static int appendWhileMaxNumber(int number,RomanNumber maxRomanNumberRepresentation,StringBuilder stringBuilder){
        int result = number;
        int maxCharacter = countCharacter(stringBuilder.toString(),maxRomanNumberRepresentation.getRomanNumber().toCharArray()[0]);
        if(number >= maxRomanNumberRepresentation.getArabicValue() && maxCharacter < maxRomanNumberRepresentation.getCantRepetitions() && number != 0){
            stringBuilder.append(maxRomanNumberRepresentation);
            result = number - maxRomanNumberRepresentation.getArabicValue();
        }
        return result;
    }

    private static int countCharacter(String str,char character){
        char[] chars = str.toCharArray();
        int count = 0;
        for (char aChar : chars) {
            if(aChar == character)
                count++;
        }
        return count;
    }

    private static RomanNumber getInmediateInferior(RomanNumber superior){
        RomanNumber result = superior;
        for (RomanNumber romanNumber : romanNumbers) {
            if(romanNumber.getArabicValue() < superior.getArabicValue())
                result = romanNumber;
        }
        return result;
    }

    private static RomanNumber getMaxRomanNumberRepresentation(int number,RomanNumber maxRomanNumberRepresentation){
        int maxCantNumber = maxRomanNumberRepresentation.getArabicValue() * maxRomanNumberRepresentation.getCantRepetitions();
        int resta = number - maxCantNumber;
        if(resta > 0){
            Optional<RomanNumber> first = romanNumbers
                    .stream()
                    .filter(rn -> rn.getArabicValue() > maxRomanNumberRepresentation.getArabicValue())
                    .findFirst();
            if(first.isPresent())
                return getMaxRomanNumberRepresentation(number,first.get());
            else return maxRomanNumberRepresentation;
        }else return maxRomanNumberRepresentation;
    }

    private static   RomanNumber getMaxRomanNumberRepresentation(int number) {
        RomanNumber romanNumberResult = null;
        for (RomanNumber romanNumber : romanNumbers) {
            if(romanNumber.getArabicValue() <= number)
                romanNumberResult = romanNumber;
        }
        return getMaxRomanNumberRepresentation(number,romanNumberResult);
    }
}
public class RomanNumeralsTest {

    @Test
    public void sum_roman_numbers_test_case(){
        String romanNumber1 = RomanNumerals.arabicToRoman(1);
        String romanNumber2 = RomanNumerals.arabicToRoman(2);
        String romanNumber3 = RomanNumerals.arabicToRoman(3);
        String romanNumber5 = RomanNumerals.arabicToRoman(5);
        String romanNumber6 = RomanNumerals.arabicToRoman(6);
        String romanNumber7= RomanNumerals.arabicToRoman(7);
        String romanNumberX= RomanNumerals.arabicToRoman(10);
        String romanNumberXI= RomanNumerals.arabicToRoman(11);
        String romanNumberXV= RomanNumerals.arabicToRoman(15);
        String romanNumberXVI= RomanNumerals.arabicToRoman(16);
        String romanNumberL = RomanNumerals.arabicToRoman(50);
        String romanNumberLVI = RomanNumerals.arabicToRoman(56);
        String romanNumberLX = RomanNumerals.arabicToRoman(60);
        String romanNumberLXX = RomanNumerals.arabicToRoman(70);
        String romanNumberLXXX = RomanNumerals.arabicToRoman(80);
        String romanNumberLXXXI = RomanNumerals.arabicToRoman(81);
        String romanNumberLXXXV = RomanNumerals.arabicToRoman(85);
        String romanNumberLXXXVI = RomanNumerals.arabicToRoman(86);
        String romanNumberCXXVI = RomanNumerals.arabicToRoman(126);
        String romanNumberMMDVII = RomanNumerals.arabicToRoman(2507);
        Assert.assertThat(romanNumber1,is("I"));
        Assert.assertThat(romanNumber2,is("II"));
        Assert.assertThat(romanNumber3,is("III"));
        Assert.assertThat(romanNumber5,is("V"));
        Assert.assertThat(romanNumber6,is("VI"));
        Assert.assertThat(romanNumber7,is("VII"));
        Assert.assertThat(romanNumberX,is("X"));
        Assert.assertThat(romanNumberXI,is("XI"));
        Assert.assertThat(romanNumberXV,is("XV"));
        Assert.assertThat(romanNumberXVI,is("XVI"));
        Assert.assertThat(romanNumberL,is("L"));
        Assert.assertThat(romanNumberLVI,is("LVI"));
        Assert.assertThat(romanNumberLX,is("LX"));
        Assert.assertThat(romanNumberLXX,is("LXX"));
        Assert.assertThat(romanNumberLXXX,is("LXXX"));
        Assert.assertThat(romanNumberLXXXI,is("LXXXI"));
        Assert.assertThat(romanNumberLXXXV,is("LXXXV"));
        Assert.assertThat(romanNumberLXXXVI,is("LXXXVI"));
        Assert.assertThat(romanNumberCXXVI,is("CXXVI"));
        Assert.assertThat(romanNumberMMDVII,is("MMDVII"));
    }

    @Test
    public void substraction_roman_numbers_test_case(){
        String romanNumberIV = RomanNumerals.arabicToRoman(4);
        String romanNumberIX = RomanNumerals.arabicToRoman(9);
        String romanNumberXIV = RomanNumerals.arabicToRoman(14);
        String romanNumberXIX = RomanNumerals.arabicToRoman(19);
        String romanNumberXXIV = RomanNumerals.arabicToRoman(24);
        String romanNumberXL= RomanNumerals.arabicToRoman(40);
        String romanNumberXLIX= RomanNumerals.arabicToRoman(49);
        String romanNumberXC= RomanNumerals.arabicToRoman(90);
        String romanNumberXXIX= RomanNumerals.arabicToRoman(99);
        String romanNumberCD= RomanNumerals.arabicToRoman(400);
        String romanNumberCM= RomanNumerals.arabicToRoman(900);
        Assert.assertThat(romanNumberIV,is("IV"));
        Assert.assertThat(romanNumberIX,is("IX"));
        Assert.assertThat(romanNumberXIV,is("XIV"));
        Assert.assertThat(romanNumberXIX,is("XIX"));
        Assert.assertThat(romanNumberXXIV,is("XXIV"));
        Assert.assertThat(romanNumberXL,is("XL"));
        Assert.assertThat(romanNumberXLIX,is("XLIX"));
        Assert.assertThat(romanNumberXC,is("XC"));
        Assert.assertThat(romanNumberXXIX,is("XCIX"));
        Assert.assertThat(romanNumberCD,is("CD"));
        Assert.assertThat(romanNumberCM,is("CM"));
    }
}

Mi soluci贸n de conversi贸n a n煤meros romanos.

Clase RomanNumerals

private static List<String> startRomanNumbers = new ArrayList<String>();
    private static List<String> middleRomanNumbers = new ArrayList<String>();

    public RomanNumerals(){
        // n煤meros menores a 3 en tipificaci贸n de longitud
        startRomanNumbers.add("I"); // unidad
        startRomanNumbers.add("X"); // decena
        startRomanNumbers.add("C"); // centena
        startRomanNumbers.add("M"); // miles
        // n煤meros de 5 en longitud
        middleRomanNumbers.add("V"); // unidad
        middleRomanNumbers.add("L"); // decena
        middleRomanNumbers.add("D"); // centena
        middleRomanNumbers.add("V+"); // miles
    }

    public static String repeatCharacterNTimes(String character, int times){
        String newCharacter = "";
        for (int i = 0; i < times; i++) {
            newCharacter+=character;
        }
        return newCharacter;
    }

    public static String getNumber(int number, int position){
        if(number <= 3 && number > 0){
            return repeatCharacterNTimes(startRomanNumbers.get(position), number);
        }
        if(number == 4){
            return startRomanNumbers.get(position) + middleRomanNumbers.get(position);
        }
        if(number == 5){
            return middleRomanNumbers.get(position);
        }
        if(number <= 8 && number > 0){
            int numberLessThanFive = number - 5;
            return middleRomanNumbers.get(position) + repeatCharacterNTimes(startRomanNumbers.get(position), numberLessThanFive);
        }
        if(number == 9){
            return startRomanNumbers.get(position) + startRomanNumbers.get(position+1);
        }

        return "";
    }
    public static String arabicToRoman(int number) {
        String[] parts = String.valueOf(number).split("");
        if(number >= 10000 || number < 0){
            return "Error cantidad";
        }
        String romanNumber = "";
        int counter = (parts.length-1);
        for (int i = 0; i < parts.length; i++) {
            int num = Integer.parseInt(parts[i]);
            romanNumber += getNumber(num, counter);
            counter--;
        }
        return romanNumber;
    }

Clase de Test - RomanNumeralsTest

private RomanNumerals roman;
    /* funci贸n que convierta un n煤mero en el equivalente romano. */
    @Before
    public void setUp(){
        roman = new RomanNumerals();
    }

    @Test
    public void check_base_numbers(){
        Assert.assertThat(roman.arabicToRoman(1), is("I"));
        Assert.assertThat(roman.arabicToRoman(2), is("II"));
        Assert.assertThat(roman.arabicToRoman(3), is("III"));
        Assert.assertThat(roman.arabicToRoman(4), is("IV"));
        Assert.assertThat(roman.arabicToRoman(5), is("V"));
        Assert.assertThat(roman.arabicToRoman(6), is("VI"));
        Assert.assertThat(roman.arabicToRoman(7), is("VII"));
        Assert.assertThat(roman.arabicToRoman(8), is("VIII"));
        Assert.assertThat(roman.arabicToRoman(9), is("IX"));
        Assert.assertThat(roman.arabicToRoman(10), is("X"));
        Assert.assertThat(roman.arabicToRoman(50), is("L"));
        Assert.assertThat(roman.arabicToRoman(100), is("C"));
        Assert.assertThat(roman.arabicToRoman(1000), is("M"));
    }

    @Test
    public void check_random_numbers(){
        Assert.assertThat(roman.arabicToRoman(11), is("XI"));
        Assert.assertThat(roman.arabicToRoman(15), is("XV"));
        Assert.assertThat(roman.arabicToRoman(16), is("XVI"));
        Assert.assertThat(roman.arabicToRoman(51), is("LI"));
        Assert.assertThat(roman.arabicToRoman(55), is("LV"));
        Assert.assertThat(roman.arabicToRoman(56), is("LVI"));
        Assert.assertThat(roman.arabicToRoman(60), is("LX"));
        Assert.assertThat(roman.arabicToRoman(70), is("LXX"));
        Assert.assertThat(roman.arabicToRoman(80), is("LXXX"));
        Assert.assertThat(roman.arabicToRoman(81), is("LXXXI"));
        Assert.assertThat(roman.arabicToRoman(85), is("LXXXV"));
        Assert.assertThat(roman.arabicToRoman(86), is("LXXXVI"));
        Assert.assertThat(roman.arabicToRoman(126), is("CXXVI"));
        Assert.assertThat(roman.arabicToRoman(2507), is("MMDVII"));
    }

    @Test
    public void errorConvertNumber(){
        Assert.assertThat(roman.arabicToRoman(11000), is("Error cantidad"));
    }

Gracias.

Ejercicio FizzBuzz

public class FizzBuzz {

    public static String fizzBuzz(int n) {

        if ((n % 3 == 0) && (n % 5 == 0)) return "FizzBuzz";

        if (n % 3 == 0) return "Fizz";

        if (n % 5 == 0) return "Buzz";

        return String.valueOf(n);
    }
}
public class FizzBuzzShould {

    @Test
    public void return_Fizz_for_3_divided_by_3() {

        FizzBuzz fizzBuzz = new FizzBuzz();
        assertThat(fizzBuzz.fizzBuzz(3), is("Fizz"));
    }

    @Test
    public void return_Fizz_for_6_divided_by_3() {

        FizzBuzz fizzBuzz = new FizzBuzz();
        assertThat(fizzBuzz.fizzBuzz(6), is("Fizz"));
    }

    @Test
    public void return_Buzz_for_5_divided_by_5() {

        FizzBuzz fizzBuzz = new FizzBuzz();
        assertThat(fizzBuzz.fizzBuzz(5), is("Buzz"));
    }

    @Test
    public void return_Buzz_for_10_divided_by_5() {

        FizzBuzz fizzBuzz = new FizzBuzz();
        assertThat(fizzBuzz.fizzBuzz(10), is("Buzz"));
    }

    @Test
    public void return_Buzz_for_15_divided_by_3_and_5() {

        FizzBuzz fizzBuzz = new FizzBuzz();
        assertThat(fizzBuzz.fizzBuzz(15), is("FizzBuzz"));
    }

    @Test
    public void return_Buzz_for_30_divided_by_3_and_5() {

        FizzBuzz fizzBuzz = new FizzBuzz();
        assertThat(fizzBuzz.fizzBuzz(30), is("FizzBuzz"));
    }

    @Test
    public void return_2_for_2() {

        FizzBuzz fizzBuzz = new FizzBuzz();
        assertThat(fizzBuzz.fizzBuzz(2), is("2"));
    }
    @Test
    public void return_16_for_16() {

        FizzBuzz fizzBuzz = new FizzBuzz();
        assertThat(fizzBuzz.fizzBuzz(16), is("16"));
    }
}

public class FizzBuzzTest {
	
	@Test
	public void num_divisible_three() {
		FizzBuzz fb = new FizzBuzz();		
		assertThat(fb.getAnswer(3), is("Fizz"));
	}
	
	@Test
	public void num_divisible_five() {
		FizzBuzz fb = new FizzBuzz();		
		assertThat(fb.getAnswer(5), is("Buzz"));
	}
	
	@Test
	public void num_divisible_three_and_five() {
		FizzBuzz fb = new FizzBuzz();		
		assertThat(fb.getAnswer(15), is("FizzBuzz"));
	}
	
	@Test
	public void num_not_divisible_three_and_five() {
		FizzBuzz fb = new FizzBuzz();		
		assertThat(fb.getAnswer(2), is("2"));
	}
}
public class FizzBuzz {

	public String getAnswer(int i) {
		String respuesta = String.valueOf(i);
		
		if(i%5==0 && i%3==0) {
			respuesta="FizzBuzz";
		}else if(i%3==0){
			respuesta="Fizz";
		}else if(i%5==0) {
			respuesta="Buzz";
		}
					
		return respuesta;
	}

}

FizzBuzz

package com.platzi.javatests.reto2;

public class FizzBuzz {
    public static String fizzBuzz(int n){
        if (n % 3 == 0 && n % 5 == 0){
            return "FizzBuzz";
        }else {
            if (n % 3 == 0) {
                return "Fizz";
            } else if (n % 5 == 0) {
                return "Buzz";
            } else {
                return String.valueOf(n);
            }
        }
    }
}
package com.platzi.javatests.reto2;

import org.junit.Test;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.*;

public class FizzBuzzShould {

    @Test
    public void when_number_is_divisible_by_3() {
        assertThat(FizzBuzz.fizzBuzz(3), is("Fizz"));
        assertThat(FizzBuzz.fizzBuzz(6), is("Fizz"));
    }

    @Test
    public void when_number_is_divisible_by_5() {
        assertThat(FizzBuzz.fizzBuzz(5), is("Buzz"));
        assertThat(FizzBuzz.fizzBuzz(10), is("Buzz"));
    }

    @Test
    public void when_number_is_divisible_by_3_and_5() {
        assertThat(FizzBuzz.fizzBuzz(15), is("FizzBuzz"));
        assertThat(FizzBuzz.fizzBuzz(30), is("FizzBuzz"));
    }

    @Test
    public void when_number_is_not_divisible_by_3_or_5() {
        assertThat(FizzBuzz.fizzBuzz(2), is("2"));
        assertThat(FizzBuzz.fizzBuzz(16), is("16"));
    }
}

clase

package com.platzi.javatest.fizzbuzz;

public class FizzBuzz {

    public static final String FIZZ = "Fizz";
    public static final String BUZZ = "Buzz";
    public static final String FIZZBUZZ = "FizzBuzz";

    public static String fizzBuzz(int n) {
        return (n%3 == 0) ? ((n%5 == 0) ? FIZZBUZZ : FIZZ ) :
                ((n%5 == 0) ? BUZZ : String.valueOf(n) );
    }
}

test

package com.platzi.javatest.fizzbuzz;

import org.junit.Test;

import static org.junit.Assert.*;

/*
Si el n煤mero es divisible por 3, retorna 鈥淔izz鈥
Si el n煤mero es divisible por 5, retorna 鈥淏uzz鈥
Si el n煤mero es divisible por 3 y por 5, retorna 鈥淔izzBuzz鈥
En otro caso, retorna el mismo n煤mero
 */

public class FizzBuzzTest {
    @Test
    public void when_the_number_is_divisible_by_3_return_fizz() {
        assertEquals(FizzBuzz.FIZZ, FizzBuzz.fizzBuzz(9));
    }

    @Test
    public void when_the_number_is_divisible_by_5_return_buzz() {
        assertEquals(FizzBuzz.BUZZ, FizzBuzz.fizzBuzz(5));
    }

    @Test
    public void when_the_number_is_divisible_by_3_and_5_return_fizzbuzz() {
        assertEquals(FizzBuzz.FIZZBUZZ, FizzBuzz.fizzBuzz(15));
    }

    @Test
    public void when_the_number_is_not_divisible_by_3_and_5_return_the_number() {
        assertEquals("14", FizzBuzz.fizzBuzz(14));
    }
}

```java public class RomanNumerals { private static Map<Integer, String> equivalences = new HashMap<>(); public static String arabicToRoman(int n) { loadEquivalences(); StringBuilder result = new StringBuilder(); boolean flag = true; int nextNumber = n; int sum = 0; while (flag) { Object equivalence = equivalences.get(nextNumber); if (Objects.isNull(equivalence)) { nextNumber = nextNumber - 1; } else { sum += nextNumber; result.append(equivalence); if (sum == n) { flag = false; } else { nextNumber = n - sum; } } } return result.toString(); } private static void loadEquivalences() { equivalences.put(1, "I"); equivalences.put(4, "IV"); equivalences.put(5, "V"); equivalences.put(9, "IX"); equivalences.put(10, "X"); equivalences.put(40, "XL"); equivalences.put(50, "L"); equivalences.put(90, "XC"); equivalences.put(100, "C"); equivalences.put(400, "CD"); equivalences.put(500, "D"); equivalences.put(900, "CM"); equivalences.put(1000, "M"); } } public class RomanNumeralsShould { @Test public void return_I_when_number_is_1() { assertEquals("I", RomanNumerals.arabicToRoman(1)); } @Test public void return_II_when_number_is_2() { assertEquals("II", RomanNumerals.arabicToRoman(2)); } @Test public void return_III_when_number_is_3() { assertEquals("III", RomanNumerals.arabicToRoman(3)); } @Test public void return_V_when_number_is_5() { assertEquals("V", RomanNumerals.arabicToRoman(5)); } @Test public void return_VI_when_number_is_6() { assertEquals("VI", RomanNumerals.arabicToRoman(6)); } @Test public void return_VII_when_number_is_7() { assertEquals("VII", RomanNumerals.arabicToRoman(7)); } @Test public void return_VIII_when_number_is_8() { assertEquals("VIII", RomanNumerals.arabicToRoman(8)); } @Test public void return_X_when_number_is_10() { assertEquals("X", RomanNumerals.arabicToRoman(10)); } @Test public void return_XI_when_number_is_11() { assertEquals("XI", RomanNumerals.arabicToRoman(11)); } @Test public void return_XV_when_number_is_15() { assertEquals("XV", RomanNumerals.arabicToRoman(15)); } @Test public void return_XVI_when_number_is_16() { assertEquals("XVI", RomanNumerals.arabicToRoman(16)); } @Test public void return_L_when_number_is_50() { assertEquals("L", RomanNumerals.arabicToRoman(50)); } @Test public void return_LI_when_number_is_51() { assertEquals("LI", RomanNumerals.arabicToRoman(51)); } @Test public void return_LV_when_number_is_55() { assertEquals("LV", RomanNumerals.arabicToRoman(55)); } @Test public void return_LVI_when_number_is_56() { assertEquals("LVI", RomanNumerals.arabicToRoman(56)); } @Test public void return_LX_when_number_is_60() { assertEquals("LX", RomanNumerals.arabicToRoman(60)); } @Test public void return_LXX_when_number_is_70() { assertEquals("LXX", RomanNumerals.arabicToRoman(70)); } @Test public void return_LXXX_when_number_is_80() { assertEquals("LXXX", RomanNumerals.arabicToRoman(80)); } @Test public void return_LXXXI_when_number_is_81() { assertEquals("LXXXI", RomanNumerals.arabicToRoman(81)); } @Test public void return_LXXXV_when_number_is_85() { assertEquals("LXXXV", RomanNumerals.arabicToRoman(85)); } @Test public void return_LXXXVI_when_number_is_86() { assertEquals("LXXXVI", RomanNumerals.arabicToRoman(86)); } @Test public void return_CXXVI_when_number_is_126() { assertEquals("CXXVI", RomanNumerals.arabicToRoman(126)); } @Test public void return_MMD0VII_when_number_is_2507() { assertEquals("MMDVII", RomanNumerals.arabicToRoman(2507)); } @Test public void return_IV_when_number_is_4() { assertEquals("IV", RomanNumerals.arabicToRoman(4)); } @Test public void return_IX_when_number_is_9() { assertEquals("IX", RomanNumerals.arabicToRoman(9)); } @Test public void return_XIV_when_number_is_14() { assertEquals("XIV", RomanNumerals.arabicToRoman(14)); } @Test public void return_XIX_when_number_is_19() { assertEquals("XIX", RomanNumerals.arabicToRoman(19)); } @Test public void return_XXIV_when_number_is_24() { assertEquals("XXIV", RomanNumerals.arabicToRoman(24)); } @Test public void return_XL_when_number_is_40() { assertEquals("XL", RomanNumerals.arabicToRoman(40)); } @Test public void return_XLIX_when_number_is_49() { assertEquals("XLIX", RomanNumerals.arabicToRoman(49)); } @Test public void return_XC_when_number_is_90() { assertEquals("XC", RomanNumerals.arabicToRoman(90)); } @Test public void return_XCIX_when_number_is_99() { assertEquals("XCIX", RomanNumerals.arabicToRoman(99)); } @Test public void return_CD_when_number_is_400() { assertEquals("CD", RomanNumerals.arabicToRoman(400)); } @Test public void return_CM_when_number_is_900() { assertEquals("CM", RomanNumerals.arabicToRoman(900)); } @Test public void return_MCDXCIV_when_number_is_1494() { assertEquals("MCDXCIV", RomanNumerals.arabicToRoman(1494)); } } ```public class RomanNumerals { private static Map\<Integer, String> *equivalences* = new HashMap<>(); public static String arabicToRoman(int n) { *loadEquivalences*(); StringBuilder result = new StringBuilder(); boolean flag = true; int nextNumber = n; int sum = 0; while (flag) { Object equivalence = *equivalences*.get(nextNumber); if (Objects.*isNull*(equivalence)) { nextNumber = nextNumber - 1; } else { sum += nextNumber; result.append(equivalence); if (sum == n) { flag = false; } else { nextNumber = n - sum; } } } return result.toString(); } private static void loadEquivalences() { *equivalences*.put(1, "I"); *equivalences*.put(4, "IV"); *equivalences*.put(5, "V"); *equivalences*.put(9, "IX"); *equivalences*.put(10, "X"); *equivalences*.put(40, "XL"); *equivalences*.put(50, "L"); *equivalences*.put(90, "XC"); *equivalences*.put(100, "C"); *equivalences*.put(400, "CD"); *equivalences*.put(500, "D"); *equivalences*.put(900, "CM"); *equivalences*.put(1000, "M"); } }
# Arabic a Roman Este ejercicio me sac贸 los pelos de la cabeza, pero se logr贸. ```js public class RomanNumeral { private final static TreeMap<Integer, String> romanNumerals = new TreeMap<>(); static {/* bloque de inicializaci贸n est谩tica. * Es un bloque de c贸digo que se ejecuta cuando la clase se carga en la JVM * y solo se ejecuta una vez, independientemente de la cantidad de instancias * de la clase que se creen. Puedes utilizarlo para inicializar variables est谩ticas * o realizar otras acciones de inicializaci贸n espec铆ficas de la clase.*/ romanNumerals.put(1000, "M"); romanNumerals.put(900, "CM"); romanNumerals.put(500, "D"); romanNumerals.put(400, "CD"); romanNumerals.put(100, "C"); romanNumerals.put(90, "XC"); romanNumerals.put(50, "L"); romanNumerals.put(40, "XL"); romanNumerals.put(10, "X"); romanNumerals.put(9, "IX"); romanNumerals.put(5, "V"); romanNumerals.put(4, "IV"); romanNumerals.put(1, "I"); } /** * Convierte y retorna un n煤mero ar谩bico a romano. Si el n煤mero ingresado no se encuentra en el romanNumerals, el m茅todo arabicToRoman se llamar谩 recursivamente factorizando el n煤mero hasta convertirlo en n煤mero romano. * @param number n煤mero ar谩bico a convertir * @return devuelve el n煤mero ar谩bico en n煤mero Romano */ public static String arabicToRoman(int number) { int lowestNearestKey = romanNumerals.floorKey(number); if (number == lowestNearestKey) { return romanNumerals.get(number); } return romanNumerals.get(lowestNearestKey) + arabicToRoman(number - lowestNearestKey); } } ```
Les dejo mi aporte public class FizzBuzz { public static String doCalc(int number){ if (number % 3 == 0 && number % 5 == 0) { return "FizzBuzz"; } else if (number % 3 == 0) { return "Fizz"; } else if (number % 5 == 0) { return "Buzz"; } else { return String.*valueOf*(number); } } } Test public class FizzBuzzTest { @Test public void it\_should\_return\_fizz\_when\_number\_is\_divisible\_by\_3(){ String result = FizzBuzz.*doCalc*(3); *assertEquals*("Fizz", result); } @Test public void it\_should\_return\_buzz\_when\_number\_is\_divisible\_by\_5(){ String result = FizzBuzz.*doCalc*(5); *assertEquals*("Buzz", result); } @Test public void it\_should\_return\_fizzbuzz\_when\_number\_is\_divisible\_by\_3\_and\_5(){ String result = FizzBuzz.*doCalc*(15); *assertEquals*("FizzBuzz", result); } @Test public void it\_should\_return\_same\_number\_otherwise(){ String result = FizzBuzz.*doCalc*(1); *assertEquals*("1", result); } }
Reto01: ```java import lombok.Data; @SuppressWarnings("nls") @Data public class FizzBuzz { public static final String FIZZ = "Fizz"; public static final String BUZZ = "Buzz"; public static final String FIZZBUZZ = "FizzBuzz"; private Double number; public FizzBuzz(final Double value) { this.number = value; } private Boolean isFizz() { if (this.number == null) { return Boolean.FALSE; } return Boolean.valueOf(this.number.doubleValue() % 3 == 0.0); } private Boolean isBuzz() { if (this.number == null) { return Boolean.FALSE; } return Boolean.valueOf(this.number.doubleValue() % 5 == 0.0); } public String getNumberType() { StringBuilder result = new StringBuilder(); if (isFizz().booleanValue()) { result.append(FizzBuzz.FIZZ); } if (isBuzz().booleanValue()) { result.append(FizzBuzz.BUZZ); } if (result.length() > 0) { return result.toString(); } return String.valueOf(this.number); } } ```import org.junit.jupiter.api.Assertions;```js import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; class FizzBuzzShould { @Test void return_fizz_when_number_divible_by_3() { FizzBuzz validator = new FizzBuzz(Double.valueOf(18)); Assertions.assertEquals(FizzBuzz.FIZZ, validator.getNumberType()); } @Test void return_buzz_when_number_divible_by_5() { FizzBuzz validator = new FizzBuzz(Double.valueOf(20)); Assertions.assertEquals(FizzBuzz.BUZZ, validator.getNumberType()); } @Test void return_fizzBuzz_when_number_divible_by_3_and_5() { FizzBuzz validator = new FizzBuzz(Double.valueOf(15)); Assertions.assertEquals(FizzBuzz.FIZZBUZZ, validator.getNumberType()); } @Test void return_number_when_number_is_not_divible_by_3_and_5() { String valueTest = "22.0"; //$NON-NLS-1$ FizzBuzz validator = new FizzBuzz(Double.valueOf(valueTest)); Assertions.assertEquals(valueTest, validator.getNumberType()); } } ```Reto 02 ```js public class RomanNumerals { @SuppressWarnings("nls") public static String arabicToRoman(final int numberParam) { if (numberParam < 1 || numberParam > 3999) { throw new IllegalArgumentException(String.format("The number %s must be between 1 and 3999", String.valueOf(numberParam))); } int[] arabicValues = { 1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1 }; String[] romanNumerals = { "M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I" }; StringBuilder result = new StringBuilder(); int number = numberParam; for (int i = 0; i < arabicValues.length; i++) { while (number >= arabicValues[i]) { result.append(romanNumerals[i]); number -= arabicValues[i]; } } return result.toString(); } } ```import java.util.concurrent.atomic.AtomicInteger;```js import java.util.concurrent.atomic.AtomicInteger; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; class RomanNumeralsShould { @Test void return_vii_when_number_is_7() { String romanNumber = RomanNumerals.arabicToRoman(7); Assertions.assertEquals("VII", romanNumber); } @Test void return_mmdvii_when_number_is_2507() { String romanNumber = RomanNumerals.arabicToRoman(2507); Assertions.assertEquals("MMDVII", romanNumber); } @Test void return_mmmcmxcix_when_number_is_3999() { String romanNumber = RomanNumerals.arabicToRoman(3999); Assertions.assertEquals("MMMCMXCIX", romanNumber); } @Test void return_exception_when_number_is_mayor_that_3999() { AtomicInteger numberTest = new AtomicInteger(); numberTest.set(45989); String errorMsg = String.format("The number %s must be between 1 and 3999", String.valueOf(numberTest.get())); IllegalArgumentException thrown = Assertions.assertThrows(IllegalArgumentException.class, // () -> { RomanNumerals.arabicToRoman(numberTest.get()); }, // errorMsg); Assertions.assertTrue(thrown.getMessage().contains(errorMsg)); } } ``` import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; class RomanNumeralsShould { @Test void return\_vii\_when\_number\_is\_7() { String romanNumber = RomanNumerals.*arabicToRoman*(7); Assertions.*assertEquals*("VII", romanNumber); } @Test void return\_mmdvii\_when\_number\_is\_2507() { String romanNumber = RomanNumerals.*arabicToRoman*(2507); Assertions.*assertEquals*("MMDVII", romanNumber); } @Test void return\_mmmcmxcix\_when\_number\_is\_3999() { String romanNumber = RomanNumerals.*arabicToRoman*(3999); Assertions.*assertEquals*("MMMCMXCIX", romanNumber); } @Test void return\_exception\_when\_number\_is\_mayor\_that\_3999() { AtomicInteger numberTest = new AtomicInteger(); numberTest.set(45989); String errorMsg = String.*format*("The number %s must be between 1 and 3999", String.*valueOf*(numberTest.get())); IllegalArgumentException thrown = Assertions.*assertThrows*(IllegalArgumentException.class, // () -> { RomanNumerals.*arabicToRoman*(numberTest.get()); }, // errorMsg); Assertions.*assertTrue*(thrown.getMessage().contains(errorMsg)); } }
**FizzBuzz** ```java package com.platzi.javatests.fizzbuzz; public class FizzBuzz { /* * fizzBuzz has to return one of the next values: * - If the number n is divisible by 3 return "Fizz" * - If the number n is divisible by 5 return "Buzz" * - If the number n is divisible by 3 and by 5 return "FizzBuzz" * - If the number n is NOT divisible by 3 and 5 return "n" */ public static String fizzBuzz(int n) { // First condition accomplished. String message = ""; if (n % 3 == 0) { message += "Fizz"; } if (n % 5 == 0) { message += "Buzz"; } else if (n % 3 != 0) { message += Integer.toString(n); } return message; } } ``` **N煤meros Romanos** ```java package com.platzi.javatests.romannumbers; public class RomanNumerals { public static String arabicToRoman(int n) { String romanNumber = ""; int idx = 0; int[] numbers = new int[]{ 1000, 500, 100, 50, 10, 5, 1 }; char[] romans = new char[]{ 'M', 'D', 'C', 'L', 'X', 'V', 'I' }; while (n != 0) { if (n / numbers[idx] != 0) { romanNumber += romans[idx]; n -= numbers[idx]; } else { int addIdx = 2 * switch(idx) { case 0, 1 -> 1; case 2, 3 -> 2; default -> 3; }; if (n + numbers[addIdx] >= numbers[idx]) { romanNumber += romans[addIdx] + "" + romans[idx]; n -= (n / numbers[addIdx] * numbers[addIdx]); } else { idx++; } } } return romanNumber; } } ```
public static String arabicToRoman(int n) { StringBuilder number = new StringBuilder(); int\[] values = {1000,500,100,50, 10, 5, 1}; String\[] numerals = {"M","D","C","L", "X", "V", "I"}; for (int i = 0; i < values.length; i++) { while (n >= values\[i]) { number.append(numerals\[i]); n -= values\[i]; } } return number.toString(); }
public class FizzBuzz {

    public static String divisible(int number){
        String result = "";

        if(number % 3 == 0){
            result += "Fizz";
        }

        if(number % 5 == 0){
            result += "Buzz";
        }

        if(result.isEmpty()){
            result = String.valueOf(number);
        }

        return result;

    }

}

Test

package org.cr3ativos.divisible;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;

class FizzBuzzTest {

    @Test
    public void divisible_by_3(){
        assertEquals(FizzBuzz.divisible(3), "Fizz");
    }

    @Test
    public void divisible_by_5(){
        assertEquals(FizzBuzz.divisible(5), "Buzz");
    }

    @Test
    public void divisible_by_3_and_5(){
        assertEquals(FizzBuzz.divisible(15), "FizzBuzz");
    }

    @Test
    public void not_divisible_by_3_or_5(){
        assertEquals(FizzBuzz.divisible(2), "2");
    }

    @Test
    public void divisible_by_3_and_5_with_0(){
        assertEquals(FizzBuzz.divisible(0), "FizzBuzz");
    }

}

RETO 1

 public static String fizzBuzz(int number) {
        StringBuilder stringBuilder = new StringBuilder();

        if(number % 3 == 0){
            stringBuilder.append("Fizz");
        }
        if (number % 5 == 0){
            stringBuilder.append("Buzz");
        }
        return (stringBuilder.length()>0)?
                    stringBuilder.toString():
                    String.valueOf(number);
    }

TEST

public class FizzBuzzTest {
    @Test
    public void return_fizz_when_number_is_divisible_by_3() {
        assertThat(FizzBuzz.fizzBuzz(3) ,is("Fizz"));
        assertThat(FizzBuzz.fizzBuzz(6) ,is("Fizz"));
    }

    @Test
    public void return_buzz_when_number_is_divisible_by_5() {
        assertThat(FizzBuzz.fizzBuzz(5) ,is("Buzz"));
        assertThat(FizzBuzz.fizzBuzz(10) ,is("Buzz"));
    }

    @Test
    public void return_FizzBuzz_when_number_is_divisible_by_3_and_5() {
        assertThat(FizzBuzz.fizzBuzz(15) ,is("FizzBuzz"));
        assertThat(FizzBuzz.fizzBuzz(30) ,is("FizzBuzz"));
    }

    @Test
    public void for_others_return_number() {
        assertThat(FizzBuzz.fizzBuzz(2) ,is("2"));
        assertThat(FizzBuzz.fizzBuzz(16) ,is("16"));
    }

}

RETO 2

public static String arabicToRoman(int number) {
        if (number < 1 || number > 3999) {
            throw new IllegalArgumentException("N煤mero fuera del rango v谩lido (1-3999)");
        }
        StringBuilder stringBuilder = new StringBuilder();

        for (RomanNumeral numeral : RomanNumeral.values()) {
            while (number >= numeral.getArabicValue()) {
                number -= numeral.getArabicValue();
                stringBuilder.append(numeral.getRomanSymbol());
            }
        }

        return stringBuilder.toString();
    }

Enum

 public enum RomanNumeral {
        M(1000, "M"),
        CM(900, "CM"),
        D(500, "D"),
        CD(400, "CD"),
        C(100, "C"),
        XC(90, "XC"),
        L(50, "L"),
        XL(40, "XL"),
        X(10, "X"),
        IX(9, "IX"),
        V(5, "V"),
        IV(4, "IV"),
        I(1, "I");

        private final int arabicValue;
        private final String romanSymbol;

        RomanNumeral(int arabicValue, String romanSymbol) {
            this.arabicValue = arabicValue;
            this.romanSymbol = romanSymbol;
        }

        public int getArabicValue() {
            return arabicValue;
        }

        public String getRomanSymbol() {
            return romanSymbol;
        }
    }

TEST

public class RomanNumeralsTest {

    @Test
    public void romanI() {
        assertThat(RomanNumerals.arabicToRoman(1),is("I"));
    }
    @Test
    public void romanII() {
        assertThat(RomanNumerals.arabicToRoman(2),is("II"));
    }
    @Test
    public void romanIII() {
        assertThat(RomanNumerals.arabicToRoman(3),is("III"));
    }
    @Test
    public void romanV() {
        assertThat(RomanNumerals.arabicToRoman(5),is("V"));
    }
    @Test
    public void romanVI() {
        assertThat(RomanNumerals.arabicToRoman(6),is("VI"));
    }
    @Test
    public void romanVII() {
        assertThat(RomanNumerals.arabicToRoman(7),is("VII"));
    }
    @Test
    public void romanX() {
        assertThat(RomanNumerals.arabicToRoman(10),is("X"));
    }
    @Test
    public void romanXI() {
        assertThat(RomanNumerals.arabicToRoman(11),is("XI"));
    }
    @Test
    public void romanXVI() {
        assertThat(RomanNumerals.arabicToRoman(16),is("XVI"));
    }
    @Test
    public void romanL() {
        assertThat(RomanNumerals.arabicToRoman(50),is("L"));
    }
    @Test
    public void romanLI() {
        assertThat(RomanNumerals.arabicToRoman(51),is("LI"));
    }
    @Test
    public void romanLV() {
        assertThat(RomanNumerals.arabicToRoman(55),is("LV"));
    }
    @Test
    public void romanLVI() {
        assertThat(RomanNumerals.arabicToRoman(56),is("LVI"));
    }
    @Test
    public void romanLX() {
        assertThat(RomanNumerals.arabicToRoman(60),is("LX"));
    }
    @Test
    public void romanLXX() {
        assertThat(RomanNumerals.arabicToRoman(70),is("LXX"));
    }
    @Test
    public void romanLXXX() {
        assertThat(RomanNumerals.arabicToRoman(80),is("LXXX"));
    }
    @Test
    public void romanLXXXI() {
        assertThat(RomanNumerals.arabicToRoman(81),is("LXXXI"));
    }
    @Test
    public void romanLXXXV() {
        assertThat(RomanNumerals.arabicToRoman(85),is("LXXXV"));
    }
    @Test
    public void romanLXXXVI() {
        assertThat(RomanNumerals.arabicToRoman(86),is("LXXXVI"));
    }
    @Test
    public void romanCXXVI() {
        assertThat(RomanNumerals.arabicToRoman(126),is("CXXVI"));
    }
    @Test
    public void romanMMDVII() {
        assertThat(RomanNumerals.arabicToRoman(2507),is("MMDVII"));
    }
    @Test
    public void romanIV() {
        assertThat(RomanNumerals.arabicToRoman(4),is("IV"));
    }
    @Test
    public void romanIX() {
        assertThat(RomanNumerals.arabicToRoman(9),is("IX"));
    }@Test
    public void romanXIV() {
        assertThat(RomanNumerals.arabicToRoman(14),is("XIV"));
    }@Test
    public void romanXIX() {
        assertThat(RomanNumerals.arabicToRoman(19),is("XIX"));
    }@Test
    public void romanXXIV() {
        assertThat(RomanNumerals.arabicToRoman(24),is("XXIV"));
    }@Test
    public void romanXL() {
        assertThat(RomanNumerals.arabicToRoman(40),is("XL"));
    }@Test
    public void romanXLIX() {
        assertThat(RomanNumerals.arabicToRoman(49),is("XLIX"));
    }@Test
    public void romanXC() {
        assertThat(RomanNumerals.arabicToRoman(90),is("XC"));
    }@Test
    public void romanXCIX() {
        assertThat(RomanNumerals.arabicToRoman(99),is("XCIX"));
    }@Test
    public void romanCD() {
        assertThat(RomanNumerals.arabicToRoman(400),is("CD"));
    }@Test
    public void romanCM() {
        assertThat(RomanNumerals.arabicToRoman(900),is("CM"));
    }
}

Reto #2

public static String toRomanNumeral(int i) {
        String unit = "";
        String ten = "";
        String hundred = "";
        String thousand = "";

        if (i > 0 && i < 4000) {
            String[] units = {"","I","II","III","IV","V","VI","VII","VIII","IX"};
            String[] tens = {"", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC"};
            String[] hundreds = {"", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM"};
            String[] thousands = {"", "M", "MM", "MMM"};

            String strNumber = Integer.toString(i);
            int length = strNumber.length();

            if (i/1000 >= 1) {
                thousand = thousands[Character.getNumericValue(strNumber.charAt(length-4))];
            }
            if(i/100 >= 1) {
                hundred = hundreds[Character.getNumericValue(strNumber.charAt(length-3))];
            }
            if(i/10 >= 1) {
                ten = tens[Character.getNumericValue(strNumber.charAt(length-2))];
            }
            unit = units[Character.getNumericValue(strNumber.charAt(length-1))];
        }

        return thousand + hundred + ten + unit;
    } 

Dificil, pero se pudo

package com.platzi.javatests.RomanNumbers;

public class RomanNumerals {
    public static String arabicToRoman(int num) {
        if (num < 1 || num > 3999) {
            throw new IllegalArgumentException("El n煤mero debe estar entre 1 y 3999");
        }

        String[] romanNumerals = {"M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"};
        int[] arabicValues = {1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1};

        StringBuilder result = new StringBuilder();

        for (int i = 0; i < romanNumerals.length; i++) {
            while (num >= arabicValues[i]) {
                result.append(romanNumerals[i]);
                num -= arabicValues[i];
            }
        }

        return result.toString();
    }
}

public class RomanNumeralConverter {

public static String arabicToRoman(int number) {
    if (number <= 0 || number > 3999) {
        throw new IllegalArgumentException("El n煤mero debe estar entre 1 y 3999.");
    }

    String[] romanSymbols = {"I", "IV", "V", "IX", "X", "XL", "L", "XC", "C", "CD", "D", "CM", "M"};
    int[] arabicValues = {1, 4, 5, 9, 10, 40, 50, 90, 100, 400, 500, 900, 1000};

    StringBuilder romanNumeral = new StringBuilder();

    int i = arabicValues.length - 1;
    while (number > 0) {
        if (number >= arabicValues[i]) {
            romanNumeral.append(romanSymbols[i]);
            number -= arabicValues[i];
        } else {
            i--;
        }
    }

    return romanNumeral.toString();
}

}

package org.example.javatests.fizzbuzz;

import org.hamcrest.CoreMatchers;
import org.junit.Test;

import java.io.IOException;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.*;

public class FizzBuzzTestShould {

    @Test
    public void return_fizz_when_is_divisible_by_3() {
        FizzBuzz fizzBuzz = new FizzBuzz();
        assertThat(fizzBuzz.getResult(3), is("Fizz"));
    }

    @Test
    public void return_buzz_when_is_divisible_by_5() {
        FizzBuzz fizzBuzz = new FizzBuzz();
        assertThat(fizzBuzz.getResult(5), is("Buzz"));
    }

    @Test
    public void return_fizzbuzz_when_is_divisible_by_3_and_5() {
        FizzBuzz fizzBuzz = new FizzBuzz();
        assertThat(fizzBuzz.getResult(15), is("FizzBuzz"));
    }

    @Test
    public void return_the_same_number_when_is_not_divisible_by_3_or_5() {
        FizzBuzz fizzBuzz = new FizzBuzz();
        assertThat(fizzBuzz.getResult(8), is("8"));
    }

    @Test(expected = IllegalArgumentException.class)
    public void return_exception_when_number_is_null() {
        FizzBuzz fizzBuzz = new FizzBuzz();
        fizzBuzz.getResult(null);
    }
}
package org.example.javatests.fizzbuzz;

public class FizzBuzz {
    public String getResult(Integer number) {
        if (number == null) throw new IllegalArgumentException("El valor debe ser un n煤mero");
        if (number % 3 == 0 && number % 5 == 0) return "FizzBuzz";
        if (number % 3 == 0) return "Fizz";
        if (number % 5 == 0) return "Buzz";

        return number.toString();
    }
}

public static String fizzBuzz(int number) {
        if (number % 3 == 0 && number % 5 == 0) {
            return "FizzBuzz";
        }
        if (number % 3 == 0) {
            return "Fizz";
        }
        if (number % 5 == 0) {
            return "Buzz";
        } else {
            return String.valueOf(number);
        }
    }
public class FizzBuzzTest {
    private int[] numbers = new int[1000];

    @Test
    public void caseReturnFizz() {

        for (int i = 2; i < numbers.length; i += 2) {
            if (i % 3 == 0 && i % 5 != 0) {
                assertEquals("Fizz", FizzBuzz.fizzBuzz(i));
            }
        }

    }
    @Test
    public void caseReturnBuzz() {
        for (int i = 2; i <numbers.length; i += 2) {
            if (i % 3 != 0 && i % 5 == 0) {
                assertEquals("Buzz", FizzBuzz.fizzBuzz(i));
            }
        }

    }
    @Test
    public void caseReturnFizzBuzz() {
        for (int i = 2; i < numbers.length; i += 2) {
            if (i % 3 == 0 && i % 5 == 0) {
                assertEquals("FizzBuzz", FizzBuzz.fizzBuzz(i));
            }
        }

    }
}

Reto # 1

Clase

public class FizzBuzz {
    public static String fizzBuzz(int n) throws IllegalArgumentException {
        if (n <= 0) {
            throw new IllegalArgumentException("El n煤mero debe ser mayor que cero.");
        }

        if (n % 3 == 0 && n % 5 == 0) {
            return "FizzBuzz";
        } else if (n % 5 == 0) {
            return "Buzz";
        } else if (n % 3 == 0) {
            return "Fizz";
        } else {
            return String.valueOf(n);
        }
    }

}

Test

public class FizzBuzzTest {
    @Test
    public void if_number_is_divisible_by_three_then_fizz() {
        Assert.assertEquals("Fizz",FizzBuzz.fizzBuzz(3));
    }
    @Test
    public void if_number_is_divisible_by_five_then_buzz() {
        Assert.assertEquals("Buzz",FizzBuzz.fizzBuzz(5));
    }
    @Test
    public void if_number_is_divisible_by_five_and_three_then_fizzBuzz() {
        Assert.assertEquals("FizzBuzz",FizzBuzz.fizzBuzz(15));
    }

    @Test
    public void if_number_is_less_than_zero() {
        Assert.assertEquals("FizzBuzz",FizzBuzz.fizzBuzz(-5));
    }
}
public class FizzBuzz {
    public String fizzBuzz(int num){
        if (num % 3 == 0 && num % 5 == 0){
            return "FizzBuzz";
        }else if (num % 3 == 0){
            return "Fizz";
        }else if (num % 5 == 0){
            return "Buzz";
        }else {
            return String.valueOf(num);
        }
    }
}


Test
public class FizzBuzzTest {

    @Test
    public void num_divisible_by_3() {
        FizzBuzz retorno = new FizzBuzz();

        assertEquals("Fizz", retorno.fizzBuzz(3));
    }
    @Test
    public void num_divisible_by_5() {
        FizzBuzz retorno = new FizzBuzz();

        assertEquals("Buzz", retorno.fizzBuzz(5));
    }
    @Test
    public void num_divisible_by_3_and_5() {
        FizzBuzz retorno = new FizzBuzz();

        assertEquals("FizzBuzz", retorno.fizzBuzz(15));
    }
    @Test
    public void num_other_case() {
        FizzBuzz retorno = new FizzBuzz();

        assertEquals("83", retorno.fizzBuzz(83));
    }

}
public class FizzBuzz {
    public static String checkNumber(int number) {
        if (number % 3 == 0 && number % 5 == 0) // divisible entre 3 y 5
            return "FizzBuzz";
        if (number % 3 == 0) // divisible entre 3
            return "Fizz";
        else if (number % 5 == 0) // divisible entre 5
            return "Buzz";
        else // cualquier otro caso
            return String.valueOf(number);
    }
}

RETO #2
Nota: El m茅todo repeat solo esta disponible en JAVA 11, por lo que se puede cambiar por un for que vaya cancatenando.

package com.platzi.javatests.romanNumerals;

public class RomanNumeral {
    public String arabicToRoman(int n) {
        String result = "";
        String romanNumber;
        int units, tens, hundreds, thousandsUnits;
        units = n % 10;
        tens = (n / 10) % 10;
        hundreds = (n / 100) % 10;
        thousandsUnits = (n / 1000) % 10;

        if(thousandsUnits > 3) return "The number must be less than 4000";
        if(units > 0) {
            romanNumber = "I".repeat(units);
            romanNumber = romanNumber.replaceFirst("IIII","IV");
            romanNumber = romanNumber.replaceFirst("IVI","V");
            romanNumber = romanNumber.replaceFirst("VIIII","IX");
            result = romanNumber + result;
        }
        if(tens > 0) {
            romanNumber = "X".repeat(tens);
            romanNumber = romanNumber.replaceFirst("XXXX","XL");
            romanNumber = romanNumber.replaceFirst("XLX","L");
            romanNumber = romanNumber.replaceFirst("LXXXX","XC");
            result = romanNumber + result;
        }
        if(hundreds > 0) {
            romanNumber = "C".repeat(hundreds);
            romanNumber = romanNumber.replaceFirst("CCCC","CD");
            romanNumber = romanNumber.replaceFirst("CDC","D");
            romanNumber = romanNumber.replaceFirst("DCCCC","CM");
            result = romanNumber + result;
        }
        if(thousandsUnits > 0) {
            romanNumber = "M".repeat(thousandsUnits);
            result = romanNumber + result;
        }

        return result;
    }
}

Acabe haciendo una edicion en la Wikipedia siendo que descubri eso, el reto extra si que me llevo a pensar a otro nivel eh

Fuentes

.)

Reto 1

<package com.testing.javatests.discounts;

public class FizzBuzzPrueba {

    public enum Response {
        Fizz, Buzz, FizzBuzz

    }
    public static Response getTotal(int num) {

        if ((num % 3 == 0) && (num % 5 != 0 )) {

            return Response.Fizz;
        } else if ((num % 5 == 0) && (num % 3 != 0)) {

            return  Response.Buzz;
        } else if ((num % 3 == 0) && (num % 5 == 0)) {

            return  Response.FizzBuzz;
        }

        return null;
        
    }
}> 
<package com.testing.javatests.discounts;

import org.junit.Test;

import static com.testing.javatests.discounts.FizzBuzzPrueba.Response.*;



import static org.junit.Assert.*;

public class FizzBuzzPruebaTest {

    @Test
    public void es_fizz_si_num_es_div_por_3() {

        assertEquals(Fizz, FizzBuzzPrueba.getTotal(6));
    }

    @Test
    public void es_fizz_si_num_es_div_por_5() {

        assertEquals(Buzz, FizzBuzzPrueba.getTotal(10));
    }

    @Test
    public void es_fizzbuzz_si_num_es_div_por_5_y_2() {

        assertEquals(FizzBuzz, FizzBuzzPrueba.getTotal(30));
    }

}> 

Reto 2

<package com.testing.javatests.discounts;

import org.junit.Test;

import static org.junit.Assert.*;

public class NumsRomarosTest {

    @Test
    public void validar_el_1_en_romano() {
        assertEquals("I", NumsRomaros.convertirARomano(1));
    }

    @Test
    public void validar_el_10_en_romano() {
        assertEquals("X", NumsRomaros.convertirARomano(10));
    }

    @Test
    public void validar_el_25_en_romano() {
        assertEquals("XXV", NumsRomaros.convertirARomano(25));
    }

    @Test
    public void validar_el_250_en_romano() {
        assertEquals("CCL", NumsRomaros.convertirARomano(250));
    }

}> 
<package com.testing.javatests.discounts;

public class NumsRomaros {

    public static String convertirARomano(int numero) {
        int[] valores = { 1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1 };
        String[] simbolos = { "M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I" };
        StringBuilder resultado = new StringBuilder();
        for (int i = 0; i < valores.length; i++) {
            while (numero >= valores[i]) {
                numero -= valores[i];
                resultado.append(simbolos[i]);
            }
        }
        return resultado.toString();
    }
}> 

Soluci贸n del Reto 2:

<code> 
public class RomanNumerals {
    public String arabicToRoman(int numberArabic) {
        String romanNumber="";
        for(int x=0; x<numberArabic; x++){
            romanNumber +="I";
            System.out.println(romanNumber+ " *");
            romanNumber = romanNumber.replaceAll("IIII", "IV");
            romanNumber = romanNumber.replaceAll("IVI", "V");

            romanNumber = romanNumber.replaceAll("VIV", "IX");
            romanNumber = romanNumber.replaceAll("IXI", "X");

            romanNumber = romanNumber.replaceAll("XXXX", "XL");
            romanNumber = romanNumber.replaceAll("XLX", "L");

            romanNumber = romanNumber.replaceAll("LXL", "XC");
            romanNumber = romanNumber.replaceAll("XCX", "C");

            romanNumber = romanNumber.replaceAll("CCCC", "CD");
            romanNumber = romanNumber.replaceAll("CDC", "D");

            romanNumber = romanNumber.replaceAll("DCD", "CM");
            romanNumber = romanNumber.replaceAll("CMC", "M");
        }

        return romanNumber;
    }
}


public class MathOperations {
public String validateDivisibleBy(int i) {
if (i % 3 == 0 && i % 5 == 0) return 鈥淔izzBuzz鈥;
if (i % 3 == 0) return 鈥淔izz鈥;
if (i % 5 == 0) return 鈥淏uzz鈥;
else return String.valueOf(i);

}

}

i
public class MathOperationsShould {
MathOperations mathOperations = new MathOperations();

@Test
public void fizz_when_three_is_divisible_by_three() {
    assertThat(mathOperations.validateDivisibleBy(3), is("Fizz"));
}

@Test
public void fizz_when_six_is_divisible_by_three() {
    assertThat(mathOperations.validateDivisibleBy(6), is("Fizz"));
}

@Test
public void buzz_when_five_is_divisible_by_five() {
    assertThat(mathOperations.validateDivisibleBy(5), is("Buzz"));
}

@Test
public void buzz_when_ten_is_divisible_by_five() {
    assertThat(mathOperations.validateDivisibleBy(10), is("Buzz"));
}

@Test
public void fizz_buzz_when_fiveteen_is_divisible_by_three_and_five() {
    assertThat(mathOperations.validateDivisibleBy(15), is("FizzBuzz"));
}

@Test
public void fizz_buzz_when_thirty_is_divisible_by_three_and_five() {
    assertThat(mathOperations.validateDivisibleBy(30), is("FizzBuzz"));
}

@Test
public void the_same_number_when_another_case_two() {
    assertThat(mathOperations.validateDivisibleBy(2), is("2"));
}

@Test
public void the_same_number_when_another_case_sixteen() {
    assertThat(mathOperations.validateDivisibleBy(16), is("16"));
}

}

Soluci贸n del primer ejercicio:

TEST:

class FizzBuzzTest {

    FizzBuzz fizzBuzz;
    @BeforeEach
    void setUp() {
        fizzBuzz = new FizzBuzz();
    }

    @Test
    void devolver_fizz_cuando_sea_divisible_entre_3() {
        assertEquals("Fizz", fizzBuzz.dividir(9));
        assertEquals("Fizz", fizzBuzz.dividir(183));
        assertEquals("Fizz", fizzBuzz.dividir(27));
    }

    @Test
    void devolver_buzz_cuando_sea_divisible_entre_5() {
        assertEquals("Buzz", fizzBuzz.dividir(5));
        assertEquals("Buzz", fizzBuzz.dividir(175));
        assertEquals("Buzz", fizzBuzz.dividir(25));
    }

    @Test
    void devolver_fizzbuzz_cuando_sea_divisible_entre_5_y_3() {
        assertEquals("FizzBuzz", fizzBuzz.dividir(300));
        assertEquals("FizzBuzz", fizzBuzz.dividir(150));
        assertEquals("FizzBuzz", fizzBuzz.dividir(60));
    }

    @Test
    void devolver_numero_cuando_no_sea_divisible_entre_5_ni_3() {
        assertEquals("2", fizzBuzz.dividir(2));
        assertEquals("8", fizzBuzz.dividir(8));
        assertEquals("11", fizzBuzz.dividir(11));
    }
}
 

CLASE:

package com.platzi.javatest.fizzbuzz;

public class FizzBuzz {
    public String dividir(Integer numero) {
        if (numero % 5 == 0 && numero % 3 == 0) {
            return "FizzBuzz";
        }
        return numero % 5 == 0
                ? "Buzz" : numero % 3 == 0
                ? "Fizz" : String.valueOf(numero);

    }
}
 
package com.platzi.Execices;

import com.platzi.utils.StringUtil;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class RomanNumerals {

    enum RomanNumeral {
        M(1000),
        CM(900),
        D(500),
        CD(400),
        C(100),
        XC(90),
        L(50),
        XL(40),
        X(10),
        IX(9),
        V(5),
        IV(4),
        I(1);

        private int decimal;

        RomanNumeral(int decimal) {
            this.decimal = decimal;
        }

        public int getValue() {
            return decimal;
        }

        public static List<RomanNumeral> getRomanNumerals() {
            return Arrays.asList(RomanNumeral.values());
        }

    }

    public static String arabicToRoman(int number) {
        List<RomanNumeral> romanNumerals = RomanNumeral.getRomanNumerals();
        String result = "";

        int i = 0;
        int numberTemp = number;

        while (numberTemp > 0) {
            int romanNumber = romanNumerals.get(i).decimal;
            if (numberTemp >= romanNumber) {
                numberTemp -= romanNumber;
                result += romanNumerals.get(i);
            } else {
                i++;
            }
        }

        return result;
    }


}

Ac谩 el ejercicio del reto extra, seguramente tendr谩 manera de mejorarlo pero despu茅s de tanto an谩lisis logr茅 completarlo, ejecutando las pruebas correspondientes se puede observar que puede calcular cualquier cifra siempre y cuando se le indique al atributo romanMap de la clase RomanNumerals como escribirlo, para indicarle como escribirlo lo podran observar en el interior de la clase correspondiente ac谩 el ejemplo

package dev.arsystem.util;

import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.Map.Entry;

public class RomanNumerals {
	
	public static String arabicToRoman(int number) {
		int decimal = getDecimal(number);
		int module = number % decimal;
		number = decimal;
		
		String retVal = getRomanValue(number);
		
		return retVal + (module > 0 ? arabicToRoman(module) : "");
	}
	
	public static String getRomanValue(int number) {
		
		String retVal = getRomanValueWithAdd(number);
		
		return Optional.ofNullable(!StringUtil.isEmpty(retVal) ? retVal : getRomanValueWithSubtract(number))
				.filter(val -> !val.isEmpty())
				.orElseThrow(() -> new RuntimeException("No se pudo calcular el valor, posiblemente deba indicar m谩s informaci贸n"));
	}
	
	public static String getRomanValueWithSubtract(int number) {
		Entry<Integer, String> nearHightLetter = getNearHigherLetter(number);
		
		if (nearHightLetter == null)
			return "";
		
		int cumulated = nearHightLetter.getKey();
		String retVal = nearHightLetter.getValue();
		
		for (Entry<Integer, String> letter = getNearLetter(cumulated, false); cumulated != number && letter != null;
				letter = cumulated != number ? getNearLetter(letter.getKey(), false) : letter)
		{
			cumulated = nearHightLetter.getKey();
			retVal = nearHightLetter.getValue();
			
			for (int i = 0; i < MAX_REPEAT_SUBTRACT && cumulated > number; i++)
			{
				cumulated -= letter.getKey();
				retVal = letter.getValue() + retVal;
			}
		}
		
		return retVal;
	}
	
	public static String getRomanValueWithAdd(int number) {
		Entry<Integer, String> nearLetter = getNearLetter(number, true);
		int cumulated = 0;
		String retVal = nearLetter.getValue();
		
		if (nearLetter.getKey().equals(number))
			return retVal;
		
		for (Entry<Integer, String> letter = nearLetter; cumulated != number && letter != null;
				letter = cumulated != number ? getNearLetter(letter.getKey(), false) : letter)
		{
			cumulated = nearLetter.getKey();
			retVal = nearLetter.getValue();
			
			int maxRepeat = letter.getValue().equals(nearLetter.getValue())
					? MAX_REPEAT_LETTER -1 : MAX_REPEAT_LETTER;
			
			for (int i = 0; i < maxRepeat && cumulated < number; i++)
			{
				cumulated += letter.getKey();
				retVal += letter.getValue();
			}
		}
		
		return cumulated == number ? retVal : "";
	}
	
	public static int getDec(int number) {
		int dec = 1;
		
		for (; dec * 10 <= number; dec *= 10);
		
		return dec;
	}
	
	public static int getDecimal(int number) {
		int decimal = getDec(number);
		
		return (number / decimal) * decimal;
	}
	
	public static Entry<Integer, String> getNearLetter(int number, boolean includeEquals) {
		return romanMap
				.entrySet()
				.stream()
				.filter(entry -> includeEquals ? entry.getKey().compareTo(number) <= 0 : entry.getKey().compareTo(number) < 0)
				.sorted((entry1, entry2) -> entry2.getKey().compareTo(entry1.getKey()))
				.findFirst()
				.orElse(null);
	}
	
	public static Entry<Integer, String> getNearHigherLetter(int number) {
		return romanMap
				.entrySet()
				.stream()
				.filter(entry -> entry.getKey().compareTo(number) > 0)
				.sorted((entry1, entry2) -> entry1.getKey().compareTo(entry2.getKey()))
				.findFirst()
				.orElse(null);
	}
	
	@SuppressWarnings("serial")
	private static Map<Integer, String> romanMap = new HashMap<Integer, String>() {{
		put(1, "I");
		put(5, "V");
		put(10, "X");
		put(50, "L");
		put(100, "C");
		put(500, "D");
		put(1000, "M");
	}};
	
	private static int MAX_REPEAT_LETTER = 3;
	private static int MAX_REPEAT_SUBTRACT = 1;
}

como podr谩n observar, despu茅s de cierta cifra si esta debe escribirse con una letra distinta a cualquiera que pueda estar en el mapa, esta debe indicarse, con esto ser谩 suficiente para que se efectuen los c谩lculos.

Ac谩 la clase del test

package dev.arsystem.test;

import static org.junit.Assert.*;

import static org.hamcrest.CoreMatchers.*;

import org.junit.Test;

import dev.arsystem.util.RomanNumerals;

public class RomanNumeralTest {
	
	@Test
	public void testDecimalNumber() {
		assertThat(RomanNumerals.getDec(102), is(100));
		assertThat(RomanNumerals.getDec(285), is(100));
		assertThat(RomanNumerals.getDec(588), is(100));
		assertThat(RomanNumerals.getDec(1024), is(1000));
		assertThat(RomanNumerals.getDec(2050), is(1000));
	}
	
	@Test
	public void testLastDecimalNumber() {
		assertThat(RomanNumerals.getDecimal(2500), is(2000));
		assertThat(RomanNumerals.getDecimal(3480), is(3000));
		assertThat(RomanNumerals.getDecimal(3540), is(3000));
		assertThat(RomanNumerals.getDecimal(8750), is(8000));
		assertThat(RomanNumerals.getDecimal(9800), is(9000));
		assertThat(RomanNumerals.getDecimal(10680), is(10000));
		assertThat(RomanNumerals.getDecimal(595), is(500));
	}
	
	@Test
	public void testNearLetter() {
		assertEquals("I", RomanNumerals.getNearLetter(3, true).getValue());
		assertEquals("V", RomanNumerals.getNearLetter(6, true).getValue());
		assertEquals("V", RomanNumerals.getNearLetter(8, true).getValue());
		assertEquals("X", RomanNumerals.getNearLetter(10, true).getValue());
		assertEquals("I", RomanNumerals.getNearLetter(2, true).getValue());
	}
	
	@Test
	public void testArabicToRomanWithSum() {
		assertEquals("I", RomanNumerals.arabicToRoman(1));
		assertEquals("V", RomanNumerals.arabicToRoman(5));
		assertEquals("VI", RomanNumerals.arabicToRoman(6));
		assertEquals("XI", RomanNumerals.arabicToRoman(11));
		assertEquals("XII", RomanNumerals.arabicToRoman(12));
		assertEquals("XV", RomanNumerals.arabicToRoman(15));
		assertEquals("XVI", RomanNumerals.arabicToRoman(16));
		assertEquals("LXXXVI", RomanNumerals.arabicToRoman(86));
		assertEquals("CXXVI", RomanNumerals.arabicToRoman(126));
		assertEquals("MMDXXV", RomanNumerals.arabicToRoman(2525));
		assertEquals("MMDVII", RomanNumerals.arabicToRoman(2507));
	}
	
	@Test
	public void testArabicToRomanWithSubtract() {
		assertEquals("IV", RomanNumerals.arabicToRoman(4));
		assertEquals("IX", RomanNumerals.arabicToRoman(9));
		assertEquals("XIV", RomanNumerals.arabicToRoman(14));
		assertEquals("XIX", RomanNumerals.arabicToRoman(19));
		assertEquals("XXIV", RomanNumerals.arabicToRoman(24));
		assertEquals("XL", RomanNumerals.arabicToRoman(40));
		assertEquals("XLIX", RomanNumerals.arabicToRoman(49));
		assertEquals("XC", RomanNumerals.arabicToRoman(90));
		assertEquals("MMMDXIV", RomanNumerals.arabicToRoman(3514));
		assertEquals("CM", RomanNumerals.arabicToRoman(900));
		assertEquals("XCIX", RomanNumerals.arabicToRoman(99));
	}
}

package dev.arsystem.util;

import java.util.Optional;

public class FizzBuzz {
	
	public static String fizzBuzz(int number) {
		
		String retVal = (number % 3 == 0 ? "Fizz" : "")
				+ (number % 5 == 0 ? "Buzz" : "");
		
		return Optional.ofNullable(retVal)
				.filter(ret -> !ret.isEmpty())
				.orElse(Integer.toString(number));
	}
}


public class FizzBuzz {
    enum resp {
        Fizz,FizzBuzz,Buzz
    }
    String fizzBuzz(int n){
        if((n % 3 == 0) && (n % 5 == 0)){
            return resp.FizzBuzz.toString();
        }
        if((n % 3 == 0)){
            return resp.Fizz.toString();
        }
        if((n % 5 == 0)){
            return resp.Buzz.toString();
        }

        return String.valueOf(Integer.valueOf(n));
    }
}

M茅todo

public class TddPractica {

    public static String fizzBuzz(int num) {
        return ((num % 5 == 0) & (num % 3 == 0) ? "FizzBuzz" :
                (num % 3 == 0) ? "Fizz" :
                        (num % 5 == 0) ? "Buzz" :
                                String.valueOf(num));
    }
}

Tests

import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;

import static org.junit.jupiter.api.Assertions.*;

class TddPracticaTest {
    TddPractica t = new TddPractica();

    @ParameterizedTest
    @ValueSource(ints = {3, 6})
    public void fizzBuzzShouldReturnFizz(int num) {
        assertEquals("Fizz", t.fizzBuzz(num));
    }

    @ParameterizedTest
    @ValueSource(ints = {5, 10})
    public void fizzBuzzShouldReturnBuzz(int num) {
        assertEquals("Buzz", t.fizzBuzz(num));
    }

    @ParameterizedTest
    @ValueSource(ints = {15, 30})
    public void fizzBuzzShouldReturnFizzBuzz(int num) {
        assertEquals("FizzBuzz", t.fizzBuzz(num));
    }

    @ParameterizedTest
    @ValueSource(ints = {2, 16})
    public void fizzBuzzShouldReturnSameNumber(int num) {
        assertEquals(String.valueOf(num), t.fizzBuzz(num));
    }
}

stackoverflow

    String result = "";
    int number = n;
    while(number > 0){
        Iterator<Map.Entry<String, Integer>> it = map.entrySet().iterator();
        while(it.hasNext()){
            Map.Entry<String, Integer> entry = it.next();
            if(number >= entry.getValue()){
                number -= entry.getValue();
                result += entry.getKey();
                break;
            }
        }
    }
    System.out.println(result);
    return result;
}
public static void populateMap(){
    map.put("M", 1000);
    map.put("CM", 900);
    map.put("D", 500);
    map.put("CD", 400);
    map.put("C", 100);
    map.put("XC", 90);
    map.put("L", 50);
    map.put("XL", 40);
    map.put("X", 10);
    map.put("IX", 9);
    map.put("V", 5);
    map.put("IV", 4);
    map.put("I", 1);
}
<code> 

Reto 2:
public class FizzBuzz {
public static void main(String[] args) {

    int num[]={3,6,5,10,15,30,2,16};
    for(int i=0;i<num.length;i++)
    {
        if(fizzBuzz(num[i])==""){System.out.println(num[i]);}else {System.out.println(fizzBuzz(num[i]));}
    }



}
public static String fizzBuzz(int num) {
    String resultado="";
    if(num % 3== 0){ resultado= "Fizz";}
    if(num % 5== 0){ resultado= resultado+"Buzz";}
    return resultado;

}

}

FizzBuzz
Test:

package com.platzi.javatests.fizzbuzz;

import org.junit.Test;

import static org.junit.Assert.*;

public class FizzBuzzTest {

    @Test
    public void fizzWhenDivisibleBy3() {
        assertEquals("Fizz", FizzBuzz.fizzBuzz(303));
    }

    @Test
    public void buzzWhenDivisibleBy5() {
        assertEquals("Buzz", FizzBuzz.fizzBuzz(100));
    }

    @Test
    public void FizzBuzzWhenDivisibleBy3And5() {
        assertEquals("FizzBuzz", FizzBuzz.fizzBuzz(1320));

    }

    @Test
    public void notFizzNorBuzzWhenNotDivisibleBy3Or5() {
        assertEquals("!FizzNorBuzz :(", FizzBuzz.fizzBuzz(9998));
    }
}

Program:

package com.platzi.javatests.fizzbuzz;

public class FizzBuzz {
    public static String fizzBuzz(int number) {
        if (number % 3 == 0 && number % 5 == 0){
            return "FizzBuzz";
        } else if (number % 3 == 0) {
            return "Fizz";
        } else if (number % 5 == 0) {
            return "Buzz";
        }
        return "!FizzNorBuzz :(";
    }
}

Roman Numerals, agarre un poco de guia con los aportes de los compa帽eros.
Test:

package com.platzi.javatests.romannumbers;

import org.junit.Test;

import static org.junit.Assert.assertEquals;

public class RomanNumbersTest {

    @Test
    public void valid_number_1_to_roman() {
        assertEquals("I", RomanNumbers.arabicToRoman(1));
    }

    @Test
    public void valid_number_2_to_roman() {
        assertEquals("II", RomanNumbers.arabicToRoman(2));
    }

    @Test
    public void valid_number_3_to_roman() {
        assertEquals("III", RomanNumbers.arabicToRoman(3));
    }

    @Test
    public void valid_number_5_to_roman() {
        assertEquals("V", RomanNumbers.arabicToRoman(5));
    }

    @Test
    public void valid_number_6_to_roman() {
        assertEquals("VI", RomanNumbers.arabicToRoman(6));
    }

    @Test
    public void valid_number_7_to_roman() {
        assertEquals("VII", RomanNumbers.arabicToRoman(7));
    }

    @Test
    public void valid_number_10_to_roman() {
        assertEquals("X", RomanNumbers.arabicToRoman(10));
    }

    @Test
    public void valid_number_11_to_roman() {
        assertEquals("XI", RomanNumbers.arabicToRoman(11));
    }

    @Test
    public void valid_number_15_to_roman() {
        assertEquals("XV", RomanNumbers.arabicToRoman(15));
    }

    @Test
    public void valid_number_16_to_roman() {
        assertEquals("XVI", RomanNumbers.arabicToRoman(16));
    }

    @Test
    public void valid_number_50_to_roman() {
        assertEquals("L", RomanNumbers.arabicToRoman(50));
    }

    @Test
    public void valid_number_51_to_roman() {
        assertEquals("LI", RomanNumbers.arabicToRoman(51));
    }

    @Test
    public void valid_number_55_to_roman() {
        assertEquals("LV", RomanNumbers.arabicToRoman(55));
    }

    @Test
    public void valid_number_56_to_roman() {
        assertEquals("LVI", RomanNumbers.arabicToRoman(56));
    }

    @Test
    public void valid_number_60_to_roman() {
        assertEquals("LX", RomanNumbers.arabicToRoman(60));
    }

    @Test
    public void valid_number_70_to_roman() {
        assertEquals("LXX", RomanNumbers.arabicToRoman(70));
    }

    @Test
    public void valid_number_80_to_roman() {
        assertEquals("LXXX", RomanNumbers.arabicToRoman(80));
    }

    @Test
    public void valid_number_81_to_roman() {
        assertEquals("LXXXI", RomanNumbers.arabicToRoman(81));
    }

    @Test
    public void valid_number_85_to_roman() {
        assertEquals("LXXXV", RomanNumbers.arabicToRoman(85));
    }

    @Test
    public void valid_number_86_to_roman() {
        assertEquals("LXXXVI", RomanNumbers.arabicToRoman(86));
    }

    @Test
    public void valid_number_126_to_roman() {
        assertEquals("CXXVI", RomanNumbers.arabicToRoman(126));
    }

    @Test
    public void valid_number_2507_to_roman() {
        assertEquals("MMDVII", RomanNumbers.arabicToRoman(2507));
    }

    @Test
    public void valid_number_4_to_roman() {
        assertEquals("IV", RomanNumbers.arabicToRoman(4));
    }

    @Test
    public void valid_number_9_to_roman() {
        assertEquals("IX", RomanNumbers.arabicToRoman(9));
    }

    @Test
    public void valid_number_14_to_roman() {
        assertEquals("XIV", RomanNumbers.arabicToRoman(14));
    }

    @Test
    public void valid_number_19_to_roman() {
        assertEquals("XIX", RomanNumbers.arabicToRoman(19));
    }

    @Test
    public void valid_number_24_to_roman() {
        assertEquals("XXIV", RomanNumbers.arabicToRoman(24));
    }

    @Test
    public void valid_number_40_to_roman() {
        assertEquals("XL", RomanNumbers.arabicToRoman(40));
    }

    @Test
    public void valid_number_49_to_roman() {
        assertEquals("XLIX", RomanNumbers.arabicToRoman(49));
    }

    @Test
    public void valid_number_90_to_roman() {
        assertEquals("XC", RomanNumbers.arabicToRoman(90));
    }

    @Test
    public void valid_number_99_to_roman() {
        assertEquals("XCIX", RomanNumbers.arabicToRoman(99));
    }

    @Test
    public void valid_number_400_to_roman() {
        assertEquals("CD", RomanNumbers.arabicToRoman(400));
    }

    @Test
    public void valid_number_900_to_roman() {
        assertEquals("CM", RomanNumbers.arabicToRoman(900));
    }
}

Program:

package com.platzi.javatests.romannumbers;

import java.util.Arrays;
import java.util.List;

public class RomanNumbers {
    enum RomanNumeral {

        M(1000), CM(900), D(500), CD(400),
        C(100), XC(90), L(50), XL(40),
        X(10), IX(9), V(5), IV(4),
        I(1);

        private final int value;

        RomanNumeral(int value) {
            this.value = value;
        }

        public int getValue() {
            return value;
        }

        public static List<RomanNumeral> getRomanNumerals() {
            return Arrays.asList(RomanNumeral.values());
        }

    }


    public static String arabicToRoman(int n) {
        StringBuilder numberInRoman = new StringBuilder();
        while (n >= 1000) {
            numberInRoman.append(RomanNumeral.M);
            n -= RomanNumeral.M.getValue();
        }
        while (n >= 900) {
            numberInRoman.append(RomanNumeral.CM);
            n -= RomanNumeral.CM.getValue();
        }
        while (n >= 500) {
            numberInRoman.append(RomanNumeral.D);
            n -= RomanNumeral.D.getValue();
        }
        while (n >= 400) {
            numberInRoman.append(RomanNumeral.CD);
            n -= RomanNumeral.CD.getValue();
        }
        while (n >= 100) {
            numberInRoman.append(RomanNumeral.C);
            n -= RomanNumeral.C.getValue();
        }
        while (n >= 90) {
            numberInRoman.append(RomanNumeral.XC);
            n -= RomanNumeral.XC.getValue();
        }
        while (n >= 50) {
            numberInRoman.append(RomanNumeral.L);
            n -= RomanNumeral.L.getValue();
        }
        while (n >= 40) {
            numberInRoman.append(RomanNumeral.XL);
            n -= RomanNumeral.XL.getValue();
        }
        while (n >= 10) {
            numberInRoman.append(RomanNumeral.X);
            n -= RomanNumeral.X.getValue();
        }
        while (n >= 9) {
            numberInRoman.append(RomanNumeral.IX);
            n -= RomanNumeral.IX.getValue();
        }
        while (n >= 5) {
            numberInRoman.append(RomanNumeral.V);
            n -= RomanNumeral.V.getValue();
        }
        while (n >= 4) {
            numberInRoman.append(RomanNumeral.IV);
            n -= RomanNumeral.IV.getValue();
        }
        while (n >= 1) {
            numberInRoman.append(RomanNumeral.I);
            n -= RomanNumeral.I.getValue();
        }


        return numberInRoman.toString();

    }
}

<public class FizzBuzz {
    public static String fizzBuzz(int num){
        return (num % 3) + (num % 5) == 0 ?  "FizzBuzz" : num % 3 == 0 ? "Fizz" : num % 5 ==0 ? "Buzz": num+"";
    }
}> 
<    @Test
    public void return_fizzbuzz_if_number_is_divibleby_3_and_5() {
        assertThat(FizzBuzz.fizzBuzz(15), is("FizzBuzz"));
    }

    @Test
    public void return_buzz_if_number_is_divisible_by_5() {
        assertThat(FizzBuzz.fizzBuzz(36), is("Fizz"));
    }

   @Test
    public void return_fizz_if_number_is_divisible_by_3() {
        assertThat(FizzBuzz.fizzBuzz(20), is("Buzz"));
    }

    @Test
    public void return_the_number() {
        assertThat(FizzBuzz.fizzBuzz(16), is("16"));
    }
> 

Con Junit Jupiter

public class FizzBuzz {
    public static String calcular(int numero) {
        if(numero % 3 == 0 && numero % 5 == 0){
            return "FizzBuzz";
        }
        if(numero % 3 == 0){
            return "Fizz";
        }
        if(numero % 5 == 0){
            return "Buzz";
        }
        return Integer.toString(numero);
    }
}
import javatests.util.FizzBuzz;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

class FizzBuzzTest {
    @Test
    public void is_divisible_by_3(){
        Assertions.assertEquals("Fizz", FizzBuzz.calcular(33));
    }
    @Test
    public void is_divisible_by_5(){
        Assertions.assertEquals("Buzz", FizzBuzz.calcular(55));
    }
    @Test
    public void is_divisible_by_3_5(){
        Assertions.assertEquals("FizzBuzz", FizzBuzz.calcular(30));
    }
    @Test
    public void is_numero(){
        Assertions.assertEquals("7", FizzBuzz.calcular(7));
    }
}
public class RomanNumerals {
    public static String arabicToRoman(int n) {
        StringBuilder result = new StringBuilder();

        do {
            if(n - 1000 >= 0) {result.append("M"); n -= 1000;}
            else if(n - 900 >= 0) {result.append("CM"); n -= 900;}
            else if(n - 500 >= 0) {result.append("D"); n -= 500;}
            else if(n - 400 >= 0) {result.append("CD"); n -= 400;}
            else if(n - 100 >= 0) {result.append("C"); n -= 100;}
            else if(n - 90 >= 0) {result.append("XC"); n -= 90;}
            else if(n - 50 >= 0) {result.append("L"); n -= 50;}
            else if(n - 40 >= 0 ) {result.append("XL"); n -= 40;}
            else if(n - 10 >= 0) {result.append("X"); n -= 10;}
            else if(n == 9) {result.append("IX"); n -= 9;}
            else if(n - 5 >= 0) {result.append("V"); n -= 5;}
            else if(n == 4) {result.append("IV"); n -= 4;}
            else if(n - 1 >= 0) {result.append("I"); n -= 1;}
        } while(n > 0);


        return result.toString();

    }
}

This code allows convert all numbers arabic to roman

public static String convertedNumberArabicToRoman(int numero) {
        String roman = "";
        while (numero >= 1000) {
            roman = roman + "M";
            numero = numero - 1000;
        }
        if (numero >= 900) {
            roman = roman + "CM";
            numero = numero - 900;
        }
        while (numero >= 500) {
            roman = roman + "D";
            numero = numero - 500;
        }
        if (numero >= 400) {
            roman = roman + "CD";
            numero = numero - 400;
        }
        while (numero >= 100) {
            roman = roman + "C";
            numero = numero - 100;
        }
        if (numero >= 90) {
            roman = roman + "XC";
            numero = numero - 90;
        }
        while (numero >= 50) {
            roman = roman + "L";
            numero = numero - 50;
        }
        if (numero >= 40) {
            roman = roman + "XL";
            numero = numero - 40;
        }
        while (numero >= 10) {
            roman = roman + "X";
            numero = numero - 10;
        }
        if (numero == 9) {
            roman = roman + "IX";
            numero = numero - 9;
        }
        while (numero >= 5) {
            roman = roman + "V";
            numero = numero - 5;// by subtracting 5 you can go directly to the next wile
        }
        if (numero == 4) {
            roman = roman + "IV";
            numero = numero - 4;
        }
        while (numero >= 1) {
            roman = roman + "I";
            numero = numero - 1;
        }
        return roman;
    }

Unit test

    @Test
    public void convertedToRoman() {
        assertThat(RomanNumerals.convertedNumberArabicToRoman(1), is("I"));
        assertThat(RomanNumerals.convertedNumberArabicToRoman(2), is("II"));
        assertThat(RomanNumerals.convertedNumberArabicToRoman(3), is("III"));
        assertThat(RomanNumerals.convertedNumberArabicToRoman(4), is("IV"));
        assertThat(RomanNumerals.convertedNumberArabicToRoman(5), is("V"));
        assertThat(RomanNumerals.convertedNumberArabicToRoman(6), is("VI"));
        assertThat(RomanNumerals.convertedNumberArabicToRoman(7), is("VII"));
        assertThat(RomanNumerals.convertedNumberArabicToRoman(8), is("VIII"));
        assertThat(RomanNumerals.convertedNumberArabicToRoman(9), is("IX"));
        assertThat(RomanNumerals.convertedNumberArabicToRoman(10), is("X"));
        assertThat(RomanNumerals.convertedNumberArabicToRoman(11), is("XI"));
        assertThat(RomanNumerals.convertedNumberArabicToRoman(15), is("XV"));
        assertThat(RomanNumerals.convertedNumberArabicToRoman(16), is("XVI"));
        assertThat(RomanNumerals.convertedNumberArabicToRoman(50), is("L"));
        assertThat(RomanNumerals.convertedNumberArabicToRoman(51), is("LI"));
        assertThat(RomanNumerals.convertedNumberArabicToRoman(55), is("LV"));
        assertThat(RomanNumerals.convertedNumberArabicToRoman(56), is("LVI"));
        assertThat(RomanNumerals.convertedNumberArabicToRoman(60), is("LX"));
        assertThat(RomanNumerals.convertedNumberArabicToRoman(70), is("LXX"));
        assertThat(RomanNumerals.convertedNumberArabicToRoman(80), is("LXXX"));
        assertThat(RomanNumerals.convertedNumberArabicToRoman(81), is("LXXXI"));
        assertThat(RomanNumerals.convertedNumberArabicToRoman(85), is("LXXXV"));
        assertThat(RomanNumerals.convertedNumberArabicToRoman(86), is("LXXXVI"));
        assertThat(RomanNumerals.convertedNumberArabicToRoman(90), is("XC"));
        assertThat(RomanNumerals.convertedNumberArabicToRoman(91), is("XCI"));
        assertThat(RomanNumerals.convertedNumberArabicToRoman(95), is("XCV"));
        assertThat(RomanNumerals.convertedNumberArabicToRoman(99), is("XCIX"));
        assertThat(RomanNumerals.convertedNumberArabicToRoman(101), is("CI"));
        assertThat(RomanNumerals.convertedNumberArabicToRoman(269), is("CCLXIX"));
        assertThat(RomanNumerals.convertedNumberArabicToRoman(385), is("CCCLXXXV"));
        assertThat(RomanNumerals.convertedNumberArabicToRoman(433), is("CDXXXIII"));
        assertThat(RomanNumerals.convertedNumberArabicToRoman(566), is("DLXVI"));
        assertThat(RomanNumerals.convertedNumberArabicToRoman(978), is("CMLXXVIII"));
        assertThat(RomanNumerals.convertedNumberArabicToRoman(2984), is("MMCMLXXXIV"));

    }

Fue muy divertido.

Hice las dos versiones.

Romano a Entero.

public static int arabicToRoman(String n) {
        int result = 0;
        Map<Character, Integer> romanNumbers = getRomanMap();
        for (int i = 0; i < n.length()-1; i++)
        {
            int currentValue = romanNumbers.get(n.charAt(i));

            if( currentValue < romanNumbers.get(n.charAt(i+1)) )
            {
                result -= currentValue;
            }
            else
            {
                result += currentValue;
            }

        }
        result += romanNumbers.get(n.charAt(n.length()-1));
        System.out.println( String.format("Romano: \t%1$s \tInteger: \t%2$s", n,result));

        return result;
    }

    public static Map<Character, Integer> getRomanMap()
    {
        Map<Character, Integer> romanNumber = new 	HashMap<Character, Integer>();
        romanNumber.put('I', 1);
        romanNumber.put('V', 5);
        romanNumber.put('X', 10);
        romanNumber.put('L', 50);
        romanNumber.put('C', 100);
        romanNumber.put('D', 500);
        romanNumber.put('M', 1000);
        return romanNumber;
    }

public void convert_roman_to_int()
    {
        assertEquals(RomanNumerals.arabicToRoman("IV"),4);
        assertEquals(RomanNumerals.arabicToRoman("IX"),9);
        assertEquals(RomanNumerals.arabicToRoman("XIV"),14);
        assertEquals(RomanNumerals.arabicToRoman("XIX"),19);
        assertEquals(RomanNumerals.arabicToRoman("XLIX"),49);
        assertEquals(RomanNumerals.arabicToRoman("XC"),90);
        assertEquals(RomanNumerals.arabicToRoman("XCIX"),99);
        assertEquals(RomanNumerals.arabicToRoman("CD"),400);
        assertEquals(RomanNumerals.arabicToRoman("CM"),900);

        assertEquals(RomanNumerals.arabicToRoman("I"),1);
        assertEquals(RomanNumerals.arabicToRoman("II"),2);
        assertEquals(RomanNumerals.arabicToRoman("III"),3);
        assertEquals(RomanNumerals.arabicToRoman("V"),5);
        assertEquals(RomanNumerals.arabicToRoman("VI"),6);
        assertEquals(RomanNumerals.arabicToRoman("VII"),7);
        assertEquals(RomanNumerals.arabicToRoman("X"),10);
        assertEquals(RomanNumerals.arabicToRoman("XI"),11);
        assertEquals(RomanNumerals.arabicToRoman("XV"),15);
        assertEquals(RomanNumerals.arabicToRoman("XVI"),16);
        assertEquals(RomanNumerals.arabicToRoman("L"),50);
        assertEquals(RomanNumerals.arabicToRoman("LI"),51);
        assertEquals(RomanNumerals.arabicToRoman("LV"),55);
        assertEquals(RomanNumerals.arabicToRoman("LVI"),56);
        assertEquals(RomanNumerals.arabicToRoman("LX"),60);
        assertEquals(RomanNumerals.arabicToRoman("LXX"),70);
        assertEquals(RomanNumerals.arabicToRoman("LXXX"),80);
        assertEquals(RomanNumerals.arabicToRoman("LXXXI"),81);
        assertEquals(RomanNumerals.arabicToRoman("LXXXV"),85);
        assertEquals(RomanNumerals.arabicToRoman("LXXXVI"),86);
        assertEquals(RomanNumerals.arabicToRoman("CXXVI"),126);
        assertEquals(RomanNumerals.arabicToRoman("MMDVII"),2507);
    }

Entero a Romano.

public static String arabicToRoman(int n)
    {
        String romano = "";
        int i, miles, centenas, decenas, unidades;

        //obtenemos cada cifra del n煤mero
        miles = n / 1000;
        centenas = n / 100 % 10;
        decenas = n / 10 % 10;
        unidades = n % 10;

        //millar
        for (i = 1; i <= miles; i++) {
            romano = romano + "M";
        }


        //centenas
        if (centenas == 9) {
            romano = romano + "CM";
        } else if (centenas >= 5) {
            romano = romano + "D";
            for (i = 6; i <= centenas; i++) {
                romano = romano + "C";
            }
        } else if (centenas == 4) {
            romano = romano + "CD";
        } else {
            for (i = 1; i <= centenas; i++) {
                romano = romano + "C";
            }
        }

        //decenas
        if (decenas == 9) {
            romano = romano + "XC";
        } else if (decenas >= 5) {
            romano = romano + "L";
            for (i = 6; i <= decenas; i++) {
                romano = romano + "X";
            }
        } else if (decenas == 4) {
            romano = romano + "XL";
        } else {
            for (i = 1; i <= decenas; i++) {
                romano = romano + "X";
            }
        }
        //unidades
        if (unidades == 9) {
            romano = romano + "IX";
        } else if (unidades >= 5) {
            romano = romano + "V";
            for (i = 6; i <= unidades; i++) {
                romano = romano + "I";
            }
        } else if (unidades == 4) {
            romano = romano + "IV";
        } else {
            for (i = 1; i <= unidades; i++) {
                romano = romano + "I";
            }
        }

        System.out.println( String.format("Integer: \t%1$s \tRomano: \t%2$s", n,romano));
        return romano;
    }

@Test
    public void convert_int_to_roman() {
        assertEquals(RomanNumerals.arabicToRoman(3000),"MMM");
        assertEquals(RomanNumerals.arabicToRoman(2000),"MM");
        assertEquals(RomanNumerals.arabicToRoman(500),"D");
        assertEquals(RomanNumerals.arabicToRoman(100),"C");
        assertEquals(RomanNumerals.arabicToRoman(50),"L");
        assertEquals(RomanNumerals.arabicToRoman(10),"X");
        assertEquals(RomanNumerals.arabicToRoman(5),"V");
        assertEquals(RomanNumerals.arabicToRoman(1),"I");

        assertEquals(RomanNumerals.arabicToRoman(1),"I");
        assertEquals(RomanNumerals.arabicToRoman(2),"II");
        assertEquals(RomanNumerals.arabicToRoman(3),"III");
        assertEquals(RomanNumerals.arabicToRoman(5),"V");
        assertEquals(RomanNumerals.arabicToRoman(6),"VI");
        assertEquals(RomanNumerals.arabicToRoman(7),"VII");
        assertEquals(RomanNumerals.arabicToRoman(10),"X");
        assertEquals(RomanNumerals.arabicToRoman(11),"XI");
        assertEquals(RomanNumerals.arabicToRoman(15),"XV");
        assertEquals(RomanNumerals.arabicToRoman(16),"XVI");
        assertEquals(RomanNumerals.arabicToRoman(50),"L");
        assertEquals(RomanNumerals.arabicToRoman(51),"LI");
        assertEquals(RomanNumerals.arabicToRoman(55),"LV");
        assertEquals(RomanNumerals.arabicToRoman(56),"LVI");
        assertEquals(RomanNumerals.arabicToRoman(60),"LX");
        assertEquals(RomanNumerals.arabicToRoman(70),"LXX");
        assertEquals(RomanNumerals.arabicToRoman(80),"LXXX");
        assertEquals(RomanNumerals.arabicToRoman(81),"LXXXI");
        assertEquals(RomanNumerals.arabicToRoman(85),"LXXXV");
        assertEquals(RomanNumerals.arabicToRoman(86),"LXXXVI");
        assertEquals(RomanNumerals.arabicToRoman(126),"CXXVI");
        assertEquals(RomanNumerals.arabicToRoman(2507),"MMDVII");

        assertEquals(RomanNumerals.arabicToRoman(4),"IV");
        assertEquals(RomanNumerals.arabicToRoman(9),"IX");
        assertEquals(RomanNumerals.arabicToRoman(14),"XIV");
        assertEquals(RomanNumerals.arabicToRoman(19),"XIX");
        assertEquals(RomanNumerals.arabicToRoman(24),"XXIV");
        assertEquals(RomanNumerals.arabicToRoman(40),"XL");
        assertEquals(RomanNumerals.arabicToRoman(49),"XLIX");
        assertEquals(RomanNumerals.arabicToRoman(90),"XC");
        assertEquals(RomanNumerals.arabicToRoman(99),"XCIX");
        assertEquals(RomanNumerals.arabicToRoman(400),"CD");
        assertEquals(RomanNumerals.arabicToRoman(900),"CM");
    }

public static String fizzBuzz(int n)
    {
        String result="";
        result += n % 3 == 0 ? "Fizz":"";
        result += n % 5 == 0 ? "Buzz":"";
        return result.trim().isEmpty() ? String.valueOf(n): result.trim() ;
    }
@Test
    public void is_divisible_by_3()
    {
        assertEquals(FizzBuzz.fizzBuzz(3), "Fizz");
    }

    @Test
    public void is_divisible_by_5()
    {
        assertEquals(FizzBuzz.fizzBuzz(5), "Buzz");
    }

    @Test
    public void is_divisible_by_3_and_5()
    {
        assertEquals(FizzBuzz.fizzBuzz(15), "FizzBuzz");
    }

    @Test
    public void is_not_divisible_by_3_and_5()
    {
        assertEquals(FizzBuzz.fizzBuzz(17), "17");
    }
public class FizzBuzz {

    public String fizzBuzzResponse(Integer num){
        if(num % 3 == 0 && num % 5 == 0)
            return "FizzBuzz";
        if(num % 3 == 0)
            return "Fizz";
        if(num % 5 == 0)
            return "Buzz";

        return String.valueOf(num);
    }
}

class FizzBuzzShould {

    /*
    Si el n煤mero es divisible por 3, retorna 鈥淔izz鈥
    Si el n煤mero es divisible por 5, retorna 鈥淏uzz鈥
    Si el n煤mero es divisible por 3 y por 5, retorna 鈥淔izzBuzz鈥
    En otro caso, retorna el mismo n煤mero
    */

    FizzBuzz fizzBuzz = new FizzBuzz();

    @Test
    void return_Fizz_when_number_is_divisible_by_3() {

        assertEquals("Fizz", fizzBuzz.fizzBuzzResponse(3));
    }

    @Test
    void return_Buzz_when_number_is_divisible_by_5() {
        assertEquals("Buzz", fizzBuzz.fizzBuzzResponse(5));
    }

    @Test
    void return_FizzBuzz_when_number_is_divisible_by_3_and_by_5() {

        assertEquals("FizzBuzz", fizzBuzz.fizzBuzzResponse(15));
    }

    @Test
    void return_same_number_in_other_cases() {

        assertEquals("7", fizzBuzz.fizzBuzzResponse(7));
    }

    @Test
    void all_Cases() {
        assertEquals("Fizz", fizzBuzz.fizzBuzzResponse(3));
        assertEquals("Fizz", fizzBuzz.fizzBuzzResponse(6));
        assertEquals("Buzz", fizzBuzz.fizzBuzzResponse(5));
        assertEquals("Buzz", fizzBuzz.fizzBuzzResponse(10));
        assertEquals("FizzBuzz", fizzBuzz.fizzBuzzResponse(15));
        assertEquals("FizzBuzz", fizzBuzz.fizzBuzzResponse(30));
        assertEquals("2", fizzBuzz.fizzBuzzResponse(2));
        assertEquals("16", fizzBuzz.fizzBuzzResponse(16));
    }
}

public String arabicToRoman(int n) {
        String romano = "";

        int miles = n / 1000;
        int centenas = n / 100 % 10;
        int decenas = n / 10 % 10;
        int unidades = n % 10;

        for (int i = 0; i < miles; i++) {
            romano += "M";
        }

        if (centenas == 9) {
            romano += "CM";
        } else if (centenas >= 5) {
            romano += "D";
            for (int i = 6; i <= centenas; i++) {
                romano += "C";
            }
        } else if (centenas == 4) {
            romano += "CD";
        } else {
            for (int i = 0; i < centenas; i++) {
                romano += "C";
            }
        }

        if (decenas == 9) {
            romano += "XC";
        } else if (decenas >= 5) {
            romano = romano + "L";
            for (int i = 6; i <= decenas; i++) {
                romano += "X";
            }
        } else if (decenas == 4) {
            romano += "XL";
        } else {
            for (int i = 0; i < decenas; i++) {
                romano += "X";
            }
        }

        if (unidades == 9) {
            romano += "IX";
        } else if (unidades >= 5) {
            romano += "V";
            for (int i = 6; i <= unidades; i++) {
                romano += "I";
            }
        } else if (unidades == 4) {
            romano += "IV";
        } else {
            for (int i = 0; i < unidades; i++) {
                romano += "I";
            }
        }


        return romano;
    }

FizzBuzz:

public String fizzBuzz(int number) {

        String result = "";

        if (number % 3 == 0) {
            result = "Fizz";
        }
        if (number % 5 == 0) {
            result += "Buzz";
        }

        return !result.equals("") ? result : String.valueOf(number);
    }

FizzBuzzTest:

public class FizzBuzzTest {

//    Si el n煤mero es divisible por 3, retorna 鈥淔izz鈥
//    Si el n煤mero es divisible por 5, retorna 鈥淏uzz鈥
//    Si el n煤mero es divisible por 3 y por 5, retorna 鈥淔izzBuzz鈥
//    En otro caso, retorna el mismo n煤mero

    private FizzBuzz fizzBuzz;

    @Before
    public void setup() {
        this.fizzBuzz = new FizzBuzz();
    }

    @Test
    public void fizBuzz_should_return_fizz_if_number_is_divisible_by_3() {
        assertEquals("Fizz", this.fizzBuzz.fizzBuzz(3));
        assertEquals("Fizz", this.fizzBuzz.fizzBuzz(6));
    }

    @Test
    public void fizBuzz_should_return_buzz_if_number_is_divisible_by_5() {
        assertEquals("Buzz", this.fizzBuzz.fizzBuzz(5));
        assertEquals("Buzz", this.fizzBuzz.fizzBuzz(10));
    }

    @Test
    public void fizBuzz_should_return_fizzbuzz_if_number_is_divisible_by_5_and_by_3() {
        assertEquals("FizzBuzz", this.fizzBuzz.fizzBuzz(15));
        assertEquals("FizzBuzz", this.fizzBuzz.fizzBuzz(30));
    }
}

public class FizzBuzz {
public static String fizzBuzz(int num){
return (num % 3) + (num % 5) == 0 ? 鈥淔izzBuzz鈥 : num % 3 == 0 ? 鈥淔izz鈥 : num % 5 ==0 ? 鈥淏uzz鈥: num+"";
}
}

Test
@Before
public void setup(){
     numberDivisible = new NumberDivisible();
}

@Test
public void number_is_divisible_by_tree() {
    assertThat(numberDivisible.valorNumber(3), is("Fizz"));
}

@Test
public void number_is_divisible_by_five() {
    assertThat(numberDivisible.valorNumber(5), is("Buzz"));
}

@Test
public void number_is_divisible_by_tree_and_five() {
    assertThat(numberDivisible.valorNumber(15), is("FizzBuzz"));
}

@Test
public void number_is_not_divisible_by_tree_or_five() {
    assertThat(numberDivisible.valorNumber(2), is("2"));
}
method
public String valorNumber(Integer number){
    return number%3==0 && number%5==0?"FizzBuzz":number%3==0?"Fizz":number%5==0?"Buzz":number.toString();
}

Reto 2

package com.platzi.javatests.practicas;

import java.util.Collections;
import java.util.Map;
import java.util.TreeMap;

public class RomanNumerals {

    private static final Map<Integer, String> romanSigns = new TreeMap<Integer, String>(Collections.reverseOrder()){{
        put(1000,"M");
        put(900,"CM");
        put(500,"D");
        put(400,"CD");
        put(100,"C");
        put(90,"XC");
        put(50,"L");
        put(40,"XL");
        put(10,"X");
        put(9,"IX");
        put(5,"V");
        put(4,"IV");
        put(1,"I");
    }};

    public static String arabicToRoman(int n) {
        String roman = "";
        while (n > 0){
            for (int valor : romanSigns.keySet()) {
                if(n >= valor){
                    roman+= romanSigns.get(valor);
                    n-= valor;
                    break;
                }
            }
        }
        return roman;
    }
}

public class RetoFizzBuzz {

public static String pruebaDivision(int num){

    String result = "";

    if (num % 3 == 0){
        result += "Fizz";
    }

    if (num % 5 == 0){
        result += "Buzz";
    }

    if ( result.isEmpty()){
        result = Integer.toString(num);
        //otra opcion para convertir
        // String.valueOf(num);
    }
    return result;
}

}

El reto 2 me puso a pensar, hace rato no lo hacia xd

package com.example.testsjava.roman;

import java.beans.PropertyEditorSupport;
import java.util.*;

public class RomanNumerals {
    private static Map<Integer, String> roman;
    static {
        roman = new HashMap<>();
        roman.put(1,"I");
        roman.put(5,"V");
        roman.put(10,"X");
        roman.put(50,"L");
        roman.put(100,"C");
        roman.put(500,"D");
        roman.put(1000,"M");
    }
    private static List<Integer> values = new ArrayList<>(){
        {
            add(1);
            add(5);
            add(10);
            add(50);
            add(100);
            add(500);
            add(1000);
        }
    };
    private static List<Character> letters = new ArrayList<>(){
        {
            add('I');
            add('V');
            add('X');
            add('L');
            add('C');
            add('D');
            add('M');
        }
    };
    /**
     * @param num integer to convert to string
     * @return recursive function to join letter roman
     * */
    public static String arabicToRoman(int num) {
        if(roman.containsKey(num)) return roman.get(num);
        int indexValue = values.indexOf(num);
        if (indexValue != -1) return letters.get(indexValue).toString();

        /*
        * Find the minimal value of letters roman and it's index
        * */
        int valueMinimal = 0;
        int indexValueMinimal = -1;
        for (int i = 0; i <= values.size() - 1; i++) {
            if(num <= values.get(i)){
                indexValueMinimal = i - 1;
                valueMinimal = values.get(indexValueMinimal);
                break;
            }
        }
        /*
        * If no find the minimal value, that will be the last
        * */
        if(valueMinimal == 0) {
            indexValueMinimal = values.size() - 1;
            valueMinimal = values.get(indexValueMinimal);
        }

        /*
        * Find the next value of range
        * */
        int nextLetter;
        if(indexValueMinimal < values.size() - 1){
            nextLetter = values.get(indexValueMinimal + 1);
        } else {
           nextLetter = values.get(indexValueMinimal);
        }

        boolean condition = num == 4
                || num == 9
                || num%40==0 && num<50
                || num%90==0 && num<100
                || num%400==0 && num<500
                || num%900==0 && num<1000;

        String result;
        if(condition){
            result = arabicToRoman(nextLetter - num) + roman.get(nextLetter);
            roman.put(num, result);
            return result;
        }
        if(num>10 && num%10 > 0){
            result = arabicToRoman(num - num%10) + arabicToRoman(num%10);
            roman.put(num, result);
            return result;
        }
        result = roman.get(valueMinimal) + arabicToRoman(num - valueMinimal);
        roman.put(num, result);
        return result;
    }
}

public class FizzBuzzReto {

    static String Fizz = "Fizz", Buzz = "Buzz", FizzBuzz = "FizzBuzz";

    public static String calc(int num) {
        if (num % 3 == 0 && num % 5 == 0){
            return FizzBuzz;
        }else if (num % 3 ==0){
            return Fizz;
        }else if (num % 5 == 0){
            return Buzz;
        }return String.valueOf(num);
    }
public class FizzBuzzRetoTest {
    /*
     *  Si el n煤mero es divisible por 3, retorna 鈥淔izz鈥
     *  Si el n煤mero es divisible por 5, retorna 鈥淏uzz鈥
     *  Si el n煤mero es divisible por 3 y por 5, retorna 鈥淔izzBuzz鈥
     *  En otro caso, retorna el mismo n煤mero
     * */

    @Test
    public void return_fizz() {
        assertEquals("Fizz",FizzBuzzReto.calc(3));
        assertEquals("Fizz",FizzBuzzReto.calc(6));
    }

    @Test
    public void return_buzz() {
        assertEquals("Buzz",FizzBuzzReto.calc(5));
        assertEquals("Buzz",FizzBuzzReto.calc(10));
    }

    @Test
    public void return_fizzbuzz() {
        assertEquals("FizzBuzz",FizzBuzzReto.calc(15));
        assertEquals("FizzBuzz",FizzBuzzReto.calc(30));
    }

    @Test
    public void return_other_case() {
        assertEquals("2",FizzBuzzReto.calc(2));
    }

} 

Reto de fizzBuzz:

    public static String fizzBuzz(int number) {
        String result = "";
        if (number % 3 == 0) result += "Fizz";
        if (number % 5 == 0) result += "Buzz";
        if (result.isEmpty()) result = Integer.toString(number);
        return result;
    }

Y la spruebas ser铆an las siguientes:

    @Test
    public void return_Fizz_if_number_is_divisible_between_3() {
        assertEquals("Fizz",FizzBuzz.fizzBuzz(3));
        assertEquals("Fizz",FizzBuzz.fizzBuzz(6));
    }

    @Test
    public void return_Buzz_if_number_is_divisible_between_5() {
        assertEquals("Buzz",FizzBuzz.fizzBuzz(5));
        assertEquals("Buzz",FizzBuzz.fizzBuzz(10));
    }

    @Test
    public void return_FizzBuzz_if_number_is_divisible_between_3_and_5() {
        assertEquals("FizzBuzz",FizzBuzz.fizzBuzz(15));
        assertEquals("FizzBuzz",FizzBuzz.fizzBuzz(30));
    }

    @Test
    public void return_same_number_if_number_is_not_divisible_between_3_or_5() {
        assertEquals("2",FizzBuzz.fizzBuzz(2));
        assertEquals("16",FizzBuzz.fizzBuzz(16));
    }

Finalmente los resultados:

Vamos, les comparto lo que realice para los n煤meros romanos:

   public static String arabicToRoman(int number) {
        String numeroRomano = "";
        Map<Integer, String> numeros = new LinkedHashMap<Integer, String>();
        numeros.put(1000, "M");
        numeros.put(900, "CM");
        numeros.put(500, "D");
        numeros.put(400, "CD");
        numeros.put(100, "C");
        numeros.put(90, "XC");
        numeros.put(50, "L");
        numeros.put(40, "XL");
        numeros.put(10, "X");
        numeros.put(9, "IX");
        numeros.put(5, "V");
        numeros.put(4, "IV");
        numeros.put(1, "I");
        for(Integer key : numeros.keySet()){
            while (number >= key) {
                numeroRomano += numeros.get(key);
                number-=key;
            }
        }
        return numeroRomano;
    }

Las pruebas que se realizaron :

   @Test
    public void convert_number_to_roman_number() {
        assertEquals("I",NumbersToRoman.arabicToRoman(1));
        assertEquals("II",NumbersToRoman.arabicToRoman(2));
        assertEquals("III",NumbersToRoman.arabicToRoman(3));
        assertEquals("V",NumbersToRoman.arabicToRoman(5));
        assertEquals("VI",NumbersToRoman.arabicToRoman(6));
        assertEquals("VII",NumbersToRoman.arabicToRoman(7));
        assertEquals("X",NumbersToRoman.arabicToRoman(10));
        assertEquals("XI",NumbersToRoman.arabicToRoman(11));
        assertEquals("XV",NumbersToRoman.arabicToRoman(15));
        assertEquals("XVI",NumbersToRoman.arabicToRoman(16));
        assertEquals("L",NumbersToRoman.arabicToRoman(50));
        assertEquals("LI",NumbersToRoman.arabicToRoman(51));
        assertEquals("LV",NumbersToRoman.arabicToRoman(55));
        assertEquals("LVI",NumbersToRoman.arabicToRoman(56));
        assertEquals("LX",NumbersToRoman.arabicToRoman(60));
        assertEquals("LXX",NumbersToRoman.arabicToRoman(70));
        assertEquals("LXXX",NumbersToRoman.arabicToRoman(80));
        assertEquals("LXXXI",NumbersToRoman.arabicToRoman(81));
        assertEquals("LXXXV",NumbersToRoman.arabicToRoman(85));
        assertEquals("LXXXVI",NumbersToRoman.arabicToRoman(86));
        assertEquals("CXXVI",NumbersToRoman.arabicToRoman(126));
        assertEquals("MMDVII",NumbersToRoman.arabicToRoman(2507));
    }

Y finalmente obtive el resultado correcto :

package com.authentic.javatest.examples;

public class FizzBuzz {

int number = 0;


public static Boolean getNumberDiv3and5(int number) {
    String result = "";
    boolean divisible = false;
    if (number % 15 == 0) {
        result = "FizzBuzz";
        divisible = true;
        System.out.println(number + result);

    }
    return divisible;
}

public static Boolean getNumberDiv5(int number) {
    String result = "";
    boolean divisible = false;
    if (number % 5 == 0) {
        result = "Buzz";
        divisible = true;
        System.out.println(number + result);

    }
    return divisible;
}


    public static Boolean getNumberDiv3 ( int number){
        String result = "";
        boolean divisible = false;
        if (number % 3 == 0) {
            result = "Fizz";
            divisible = true;
            System.out.println(number + result);
        }


        return divisible;
    }


}

Reto 1

public class FizzBuzz {
    public static String fizzBuzz(int n) {
        if (n % 3 == 0 && n % 5 == 0) return "FizzBuzz";
        else if (n % 3 == 0) return "Fizz";
        else if (n % 5 == 0) return "Buzz";
        else return String.valueOf(n);
    }
}
public class FizzBuzzShould {

    /*
        Requirements:
        If the number is divisible by 3 return "Fizz"
        If the number is divisible by 5 return "Buzz"
        If the number is divisible by 3 and 5 return "FizzBuzz"
        In other case return the same number
     */

    @Test
    public void returnFizzWhenTheNumberIsDivisibleBy3() {
        assertEquals("Fizz", FizzBuzz.fizzBuzz(3));
        assertEquals("Fizz", FizzBuzz.fizzBuzz(9));
    }

    @Test
    public void returnBuzzWhenTheNumberIsDivisibleBy5() {
        assertEquals("Buzz", FizzBuzz.fizzBuzz(5));
        assertEquals("Buzz", FizzBuzz.fizzBuzz(10));
    }

    @Test
    public void returnBuzzWhenTheNumberIsDivisibleBy3And5() {
        assertEquals("FizzBuzz", FizzBuzz.fizzBuzz(15));
        assertEquals("FizzBuzz", FizzBuzz.fizzBuzz(30));
    }

    @Test
    public void returnSameNumberWhenIsNotDivisibleBy3Or5() {
        assertEquals("2", FizzBuzz.fizzBuzz(2));
        assertEquals("11", FizzBuzz.fizzBuzz(11));
        assertEquals("98", FizzBuzz.fizzBuzz(98));
    }
}
public class FizzBuzz {

    public String fizzBuzz(Integer number) {

        String str = "";
        str = number % 3 == 0 ? str+="Fizz" : str;
        str = number % 5 == 0 ? str+="Buzz" : str;

        return str.isEmpty() ? number.toString() : str;
    }
}
package org.example.javatest.util;

public class RomanNumerals {
    public static String arabicToRoman(int n) {
        int i = 0;
        String result = "";
        while (i< n){
            if (n-i >= 1000){
                result += "M";
                i+=1000;
                continue;
            }
            if (n-i >= 500){
                result += "D";
                i+=500;
                continue;
            }
            if (n-i >= 100){
                result += "C";
                i+=100;
                continue;
            }
            if (n-i >= 50){
                result += "L";
                i+=50;
                continue;
            }
            if (n-i >= 10){
                result += "X";
                i+=10;
                continue;
            }
            if (n-i >= 5){
                result += "V";
                i+=5;
                continue;
            }
            result += "I";
            i++;
        }
        return result;
    }
}

package org.example.javatest.util;

import org.junit.Test;

import static org.junit.Assert.*;

public class RomanNumeralsTest {
    @Test
    public void number_roman_less_equal_3() {
        assertEquals("I",RomanNumerals.arabicToRoman(1));
        assertEquals("II",RomanNumerals.arabicToRoman(2));
        assertEquals("III",RomanNumerals.arabicToRoman(3));
    }

    @Test
    public void number_roman_5_by_7() {
        assertEquals("V",RomanNumerals.arabicToRoman(5));
        assertEquals("VI",RomanNumerals.arabicToRoman(6));
        assertEquals("VII",RomanNumerals.arabicToRoman(7));
    }
    @Test
    public void number_roman_10_by_11() {
        assertEquals("X",RomanNumerals.arabicToRoman(10));
        assertEquals("XI",RomanNumerals.arabicToRoman(11));
    }

    @Test
    public void number_roman_15_by_16() {
        assertEquals("XV",RomanNumerals.arabicToRoman(15));
        assertEquals("XVI",RomanNumerals.arabicToRoman(16));
    }

    @Test
    public void number_roman_50_by_51() {
        assertEquals("L",RomanNumerals.arabicToRoman(50));
        assertEquals("LI",RomanNumerals.arabicToRoman(51));
    }
    @Test
    public void number_roman_55_by_57() {
        assertEquals("LV",RomanNumerals.arabicToRoman(55));
        assertEquals("LVI",RomanNumerals.arabicToRoman(56));
    }

    @Test
    public void number_roman_60_by_80_in_10() {
        assertEquals("LX",RomanNumerals.arabicToRoman(60));
        assertEquals("LXX",RomanNumerals.arabicToRoman(70));
        assertEquals("LXXX",RomanNumerals.arabicToRoman(80));
    }
    @Test
    public void number_roman_81_85_86() {
        assertEquals("LXXXI",RomanNumerals.arabicToRoman(81));
        assertEquals("LXXXV",RomanNumerals.arabicToRoman(85));
        assertEquals("LXXXVI",RomanNumerals.arabicToRoman(86));
    }
    @Test
    public void number_roman_126() {
        assertEquals("CXXVI",RomanNumerals.arabicToRoman(126));
    }
    @Test
    public void number_roman_2507() {
        assertEquals("MMDVII",RomanNumerals.arabicToRoman(2507));
    }
}
package org.example.javatest.util;

public class Fizzbuzz {
    public static String fizzBuzz(int n) {
        String result = "";
        if (n % 3 == 0) {
            result += "Fizz";
        }
        if (n % 5 == 0) {
            result += "Buzz";
        }
        if (result.isEmpty()) {
            return String.valueOf(n);
    }
        return result;

    }
}

package org.example.javatest.util;

import org.junit.Test;

import static org.junit.Assert.*;

public class FizzbuzzTest {
    @Test
    public void number_is_div_by_3() {
        assertEquals(Fizzbuzz.fizzBuzz(3),"Fizz");
        assertEquals(Fizzbuzz.fizzBuzz(6),"Fizz");
        assertEquals(Fizzbuzz.fizzBuzz(9),"Fizz");
    }
    @Test
    public void number_is_div_by_5() {
        assertEquals(Fizzbuzz.fizzBuzz(5),"Buzz");
        assertEquals(Fizzbuzz.fizzBuzz(10),"Buzz");
        assertEquals(Fizzbuzz.fizzBuzz(20),"Buzz");
    }

    @Test
    public void number_is_div_by_5_and_3() {
        assertEquals(Fizzbuzz.fizzBuzz(15),"FizzBuzz");
        assertEquals(Fizzbuzz.fizzBuzz(30),"FizzBuzz");
        assertEquals(Fizzbuzz.fizzBuzz(45),"FizzBuzz");
    }
    @Test
    public void number_is_not_div_by_5_or_3() {
        assertEquals(Fizzbuzz.fizzBuzz(14),"14");
        assertEquals(Fizzbuzz.fizzBuzz(16),"16");
        assertEquals(Fizzbuzz.fizzBuzz(17),"17");
    }
}

public class FizzBuzz {

public String getText(int number) {
String fizz = 鈥淔izz鈥;
String buzz = 鈥淏uzz鈥;
String text = (number % 3 == 0 && number % 5 == 0)
? fizz.concat(buzz) : (number % 3 == 0)
? fizz : (number % 5 == 0)
? buzz : Integer.toString(number);
return text;
}
}

``
```
package com.platzi.javatests.util;

public class FizzBuzz {


    public static String validate_number(int i) {
        return i%3 == 0 && i%5 == 0? "FizzBuzz" : i%3 == 0 ? "Fizz" : i%5 == 0 ? "Buzz"  : i+"";





    }
}


me devolvera cualquier numero de 1 a 3999

 public static String arabicToRoman(int number) {
        String result = "";

        if (number >= 4000) {
            return "Allow 1 to 3999";
        }


        if (number == 1) {
            return "I";
        }
        if (number == 10) {
            return "X";
        }
        if (number == 100) {
            return "C";
        }
        if (number == 1000) {
            return "M";
        }
        if (number == 50) {
            return "L";
        }
        if (number == 5) {
            return "V";
        }
        if (number == 500) {
            return "D";
        }

        int groupNumber = 1;

        while (number / groupNumber > 10) {
            groupNumber = groupNumber * 10;
        }
        int number_between_groupNumber = number / groupNumber;

        int surPlusNumber = number % groupNumber;

        if (surPlusNumber == 0) {
            if (number_between_groupNumber <= 3) {
                for (int i = 0; i < number_between_groupNumber; i++) {
                    result += arabicToRoman(1 * groupNumber);
                }
                return result;
            }
            if (number_between_groupNumber == 4) {
                result += arabicToRoman(1 * groupNumber);
                result += arabicToRoman(5 * groupNumber);
                return result;
            }
            if (number_between_groupNumber <= 8) {
                result += arabicToRoman(5 * groupNumber);
                for (int i = 0; i < number_between_groupNumber - 5; i++) {
                    result += arabicToRoman(1 * groupNumber);
                }
                return result;
            }
            if (number_between_groupNumber == 9) {
                result += arabicToRoman(1 * groupNumber);
                result += arabicToRoman(10 * groupNumber);

                return result;
            }

        } else {
                int maxValue = number_between_groupNumber * groupNumber;
                int remainingNumber = number - maxValue;
                result += arabicToRoman(maxValue);
               if (remainingNumber > 0){
                   result += arabicToRoman(remainingNumber);
               }
        }
        System.out.println("");
        return result;

    }

Mi solucion utilizando el repetidor y un enum:

package com.javatest.romans;

import com.javatest.util.StringUtil;

public class RomanNumberConverter {

    enum RomanNumeral {

        M(1000), CM(900), D(500), CD(400),
        C(100), XC(90), L(50), XL(40),
        X(10), IX(9), V(5), IV(4),
        I(1);


        private int value;

        RomanNumeral(int value) {
            this.value = value;
        }

        public int getValue() {
            return value;
        }
    }

    public static String converter(int number){
        String value = "";

        for(RomanNumeral roman : RomanNumeral.values()){
            if(number / roman.getValue() > 0){
                int repeted = number / roman.getValue();
                value += StringUtil.repeat(roman.toString(), repeted);
                number -= (repeted * roman.getValue());
            }
        }
        return value;
    }
}

#Retoo 1

package com.platzi.javatests.numbers;

public class FizzBuzz {
    public static String fizzBuzz(int n) {
        String result = "";
        if(n % 3 == 0)
            result += "Fizz";
        if(n % 5 == 0)
            result += "Buzz";
        if(result.isEmpty())
            return String.valueOf(n);
        return result;
    }
}

#Reto 2

package com.platzi.javatests.numbers;

public class RomanNumerals {
    public static String arabicToRoman(int n){
        String result = "";
        int j = n / 1000;
        for (int i = 0; i < j; i++) {
            result += "M";
            n -= 1000;
        }
        if(n >= 900){
            result += "CM";
            n -= 900;
        }
        if(n >= 500) {
            result += "D";
            n -= 500;
        }
        if(n >= 400){
            result += "CD";
            n -= 400;
        }
        j = n / 100;
        for (int i = 0; i < j; i++) {
            result += "C";
            n -= 100;
        }
        if(n > 89) {
            result += "XC";
            n -= 90;
        }
        if(n >= 50) {
            result += "L";
            n -= 50;
        }
        if(n > 39){
            result += "XL";
            n -= 40;
        }
        j = n / 10;
        for (int i = 0; i < j; i++) {
            result += "X";
            n -= 10;
        }
        if(n > 8) {
            result += "IX";
            n -= 9;
        }
        if(n >= 5){
            result += "V";
            n -= 5;
        }
        if(n > 3){
            result += "IV";
            n -= 4;
        }
        for (int i = 0; i < n; i++) {
            result += "I";
        }
        return result;
    }
}

Hola este es el reto de Fizz Buzz 馃摎


Y este es el reto de los n煤meros romanos. 馃捇
Solo tengo un problema interno con TDD. Y es que al dejar que los test dirijan nuestro desarrollo esto no necesariamente tiene que respetar nuestra l贸gica de negocio. Supongo que tiene pros y contras. 馃馃
En mi opini贸n TDD puede hacerle la vida m脿s f谩cil al programador pero no por eso respetaran la l贸gica de negocio o facilitaran la vida al usuario final.



Este fue mi approach al segundo reto con un TreeMap en reverse order

package roman_numbers;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.TreeMap;

/**
 *
 * @author oscar
 */
public class RomanNumeral {
    
    TreeMap<Integer, String> map = new TreeMap<Integer, String>(Collections.reverseOrder());

    public RomanNumeral() {
        
        map.put( 1000,"M");
        map.put( 900, "CM");
        map.put(500, "D");
        map.put(400, "CD" );
        map.put(100,"C");
        map.put(90,"XC");
        map.put(50, "L");
        map.put(40,"XL");
        map.put(10,"X");
        map.put(9,"IX");
        map.put(5,"V");
        map.put(4,"IV");
        map.put(1,"I");
    }
    
    
    
    

    public String convert(int i, String res) {
        if (i <= 0) {
            return res;
        } else{
            for (Map.Entry<Integer,String> entry : map.entrySet()) {
                String value = entry.getValue();
                int key = entry.getKey();
                 if ((i - key) >= 0 ) {
                     res =  res + value;
                    return convert(i - key,res);
                }
           }
           
       }
        return null;
    }
    
}

Reto 2 馃槃

public class FizzBuzz {

    public static String fizzbuzz(int n){
        String result = "";

        if(n % 3 == 0) result += "Fizz";
        if(n % 5 == 0) result += "Buzz";

        return result.isEmpty() ? String.valueOf(n) : result;
    }
}

Reto extra. En desarrollo鈥 馃榿

public class FizzBuzz {
    public static String fizzBuzz(int n){
        if ((n % 3 == 0) &&(n % 5 == 0)) {
            return "FizzBuzz";
        } else if (n % 3 == 0){
            return "Fizz";
        } else if (n % 5 == 0){
            return "Buzz";
        } else {
            return String.valueOf(n);
        }
    }
}```

Mi soluci贸n para el Reto 1 Usando el operador ternario

package com.platzi.javatestingplatzi.fizzbuzz;

public class FizzBuzz {
    /**
     * Metodo para devolver un String determinado en caso de un parametro numerico recibido
     * @param n numero entero a comprobar
     * @return Fizz o Buzz 贸 FizzBuzz segun sea el caso
     */
    public static String fizzBuzz(int n) {

        return (n % 3 == 0 )? (n % 5 == 0)? "FizzBuzz" : "Fizz"  : (n % 5 == 0)?"Buzz":String.valueOf(n);
        
    }
}

package Reto2;

import java.util.ArrayList;

public class ArabicToRoman {

int number,units,tens,hundreds,thousands;



public String arabicRomans (int number){

if (number>5999|| number<=0) {
throw new IllegalArgumentException(number +" " + 鈥淣o se puede convertir a numero romano鈥);
}
ArrayList <String> arabicRomans =new ArrayList<>();
units = number%10;
number/=10;
tens = number%10;
number /= 10;
hundreds = number%10;
number /=10;
thousands = number%10;

    switch (thousands) {

        case 1:
            arabicRomans.add("M");
            break;
        case 2:
            arabicRomans.add("MM");
            break;
        case 3:
            arabicRomans.add("MMM");
            break;
        case 4:
            arabicRomans.add("MV");
            break;
        case 5:
            arabicRomans.add("V");
            break;

    }

    switch (hundreds){
        case 1:
            arabicRomans.add("C"); break;
        case 2:
            arabicRomans.add("CC"); break;
        case 3:
            arabicRomans.add("CCC"); break;
        case 4:
            arabicRomans.add("CD"); break;
        case 5:
            arabicRomans.add("D"); break;
        case 6:
            arabicRomans.add("DC"); break;
        case 7:
            arabicRomans.add("DCC"); break;
        case 8:
            arabicRomans.add("DCCC"); break;
        case 9:
            arabicRomans.add("CM"); break;

            }
        switch (tens){

            case 1: arabicRomans.add("X");break;
            case 2: arabicRomans.add("XX");break;
            case 3: arabicRomans.add("XXX");break;
            case 4: arabicRomans.add("XL");break;
            case 5: arabicRomans.add("L");break;
            case 6: arabicRomans.add("LX");break;
            case 7: arabicRomans.add("LXX");break;
            case 8: arabicRomans.add("LXXX");break;
            case 9: arabicRomans.add("XC");break;

        }

        switch (units){
            case 1: arabicRomans.add("I");break;
            case 2: arabicRomans.add("II");break;
            case 3: arabicRomans.add("III");break;
            case 4: arabicRomans.add("IV");break;
            case 5: arabicRomans.add("V");break;
            case 6: arabicRomans.add("VI");break;
            case 7: arabicRomans.add("VII");break;
            case 8: arabicRomans.add("VIII");break;
            case 9: arabicRomans.add("IX");break;

            }

return arabicRomans.toString()
.replace(",","")
.replace("[","")
.replace("]","")
.replace(" 鈥,鈥")
.trim();

}




}

Ejercicio #1:
public class FizzBuzz {

public static String fizzBuzz(int n) {

    if (n % 3 == 0 && n % 5 == 0)
        return "FizzBuzz";
    else if (n % 3 == 0)
        return "Fizz";
    else if (n % 5 == 0)
        return "Buzz";
    return String.valueOf(n);
}

}

@Test
public void returnFizzWhenBy3() {

    assertThat(fizzBuzz(3), is("Fizz"));
    assertThat(fizzBuzz(6), is("Fizz"));
}

@Test
public void returnBuzzWhenBy5() {

    assertThat(fizzBuzz(5), is("Buzz"));
    assertThat(fizzBuzz(10), is("Buzz"));
}

@Test
public void returnFizzBuzzWhenBy3and5() {

    assertThat(fizzBuzz(15), is("FizzBuzz"));
    assertThat(fizzBuzz(30), is("FizzBuzz"));
}

@Test
public void returnOther() {

    assertThat(fizzBuzz(2), is("2"));
    assertThat(fizzBuzz(16), is("16"));
}

Ejercicio #2:
public class RomanNumerals {

public static String arabicToRoman(int n) {

    String romanNumbers[] = {"CM", "CD", "XCIX", "XC", "XLIX", "XL", "XXIV", "XIX", "XIV", "IX", "IV"};
    int arab[] = {900, 400, 99, 90, 49, 40, 24, 19,14, 9, 4};
    StringBuilder result = new StringBuilder();
    int i = 0;
    while (n > 0 || arab.length == (i - 1)) {
        while ((n - arab[i]) >= 0) {
            n -= arab[i];
            result.append(romanNumbers[i]);
        }
        i++;
    }
    return result.toString();
}

}

public class FizzBuzzUtil {

    public static String validateFizzBuzz(int number) {
        String result = "";

        if (number % 3 == 0) result = "Fizz";
        if (number % 5 == 0) result += "Buzz";

        return result.isEmpty() ? String.valueOf(number) : result;
    }
}

public class FizzBuzzShould {
    @Test
    public void return_fizz_if_the_number_is_divisible_by_3() {
        Assert.assertThat(FizzBuzzUtil.validateFizzBuzz(3), CoreMatchers.is("Fizz"));
    }

    @Test
    public void return_buzz_if_the_number_is_divisible_by_5() {
        Assert.assertThat(FizzBuzzUtil.validateFizzBuzz(5), CoreMatchers.is("Buzz"));
    }

    @Test
    public void return_fizzbuzz_if_the_number_is_divisible_by_3_and_by_5() {
        Assert.assertThat(FizzBuzzUtil.validateFizzBuzz(15), CoreMatchers.is("FizzBuzz"));
    }

    @Test
    public void return_same_number_in_another_case() {
        Assert.assertThat(FizzBuzzUtil.validateFizzBuzz(1), CoreMatchers.is("1"));
    }
}
	public static String toNumberRoman(Integer number) {
		StringBuilder numRoman = new StringBuilder();
		String strNumber = number.toString();
		
		int lim = strNumber.length();
		
		for (int index = 0; index < lim; index++) {
			int rep = toInteger(strNumber.substring(index, (index + 1)));
			int cant = toInteger(strNumber.substring(index, lim));
			
			if (cant <= 3999 && cant > 999) {
				for (int auxIndex = 0; auxIndex < rep; auxIndex++) {
					numRoman.append("M");
				}
			} else if(cant <= 999 && cant > 99) {
				numRoman.append(getNumRoman("D","C","M", cant, rep));
			} else if(cant <= 99 && cant > 9) {
				numRoman.append(getNumRoman("L","X","C", cant, rep));
			} else if(cant <= 9) {
				numRoman.append(getNumRoman("V","I","X", cant, rep));
			}
		}
		
		return numRoman.toString();
	}
	
	private static String getNumRoman(String numRomanActual, String numRomanAnt, String numRomanNext, 
							   int cant, int rep) {
		String numRoman = "";
			if(rep >= 4){
				numRoman += rep == 4 ? numRomanAnt + numRomanActual : numRomanActual;
			}
			if(rep < 4 || (rep > 5 && rep < 9)) {
				rep = rep < 4 ? rep : (rep - 5);
				for (int auxIndex = 0; auxIndex < rep; auxIndex++) {
					numRoman += numRomanAnt;
				}
			}
			if(rep == 9) {
				numRoman += numRomanAnt + numRomanNext;
			}
		
		return numRoman;
	}
package com.platzi.javatests.util;

public class RomanNumerals {

    static String[] RomanSymbols = {"I", "V", "X", "L", "C", "D", "M"};

    public static String arabicToRoman(int n) {
        int count = 0;
        String result = "";
        while (true) {
            int cociente = n / 10;
            int residuo = n % 10;
            result = subRoman(residuo, count) + result;
            if (cociente == 0)
                break;
            n = cociente;
            count += 2;

        }
        return result;
    }

    private static String subRoman(int n, int c) {
        String subRoman = "";
        if (n > 0 && n <= 3) {
            for (int i = 0; i < n; i++) {
                subRoman += RomanSymbols[c];
            }
        } else if (n == 4) {
            subRoman = RomanSymbols[c] + RomanSymbols[c + 1];
        } else if (n == 5) {
            subRoman = RomanSymbols[c + 1];
        } else if (n > 5 && n <= 8) {
            subRoman = RomanSymbols[c + 1];
            for (int i = 0; i < n - 5; i++) {
                subRoman += RomanSymbols[c];
            }
        } else if (n == 9) {
            subRoman = RomanSymbols[c + 2] + RomanSymbols[c + 1];
        }
        return subRoman;
    }
}

Reto#1;
class Test

public class FizzBuzzShould {
    private FizzBuzz fizzBuzz;
    @Before //es para que junit los ejecute al inicio de cada metodo
    public  void setup(){
        fizzBuzz = new FizzBuzz(    );
    }

    @Test
    public void fizz_when_num_is_divicible_by_3() {

        
        assertThat(fizzBuzz.fizzBuzz(6),is("Fizz"));
    }

    @Test
    public void buzz_when_num_is_divicible_by_5() {

        assertThat(fizzBuzz.fizzBuzz(10),is("Buzz"));
    }
    @Test
    public void fizzBuzz_when_num_is_bivicible_by_3_and_5() {

        assertThat(fizzBuzz.fizzBuzz(15),is("FizzBuzz"));
    }
}

class

public class FizzBuzz {
    public String fizzBuzz(int num){

        String result="";

      return (num % 3) + (num % 5) == 0 ?  "FizzBuzz" : num % 3 == 0 ? "Fizz" : num % 5 ==0 ? "Buzz": num+"";
    }
}

RETO#2
class Test

public class RomanNUmeralsShould {

    @Test
    public void roman_numeral_between_1_to_3900() {
        assertEquals("CC",RomanNUmerals.arabicToRoman(200));

    }

}

class

public class RomanNUmerals {
    public static String arabicToRoman(int numer) {
   String units, tens, hundreds, units_of_mil,numRoman;
   int  unit,ten,hunmd,units_of_m;
   numRoman="";

   units_of_m=numer/1000;
   ten=(numer % 1000) / 100;
   hunmd=((numer%1000)%100)/10;
   unit=(((numer%1000)%100)%10);


//Hayamos las unidades de mil
   switch (units_of_m){
       case 1:
           numRoman+="M";
           break;
       case 2:
           numRoman+="MM";
           break;
       case 3:
           numRoman+="MM";
           break;
   }
   //Hayamos las centenas
        switch (ten){
            case 1:
                numRoman+="C";break;
            case 2:
                numRoman+="CC";break;
            case 3:
                numRoman+="CCC";break;
            case 4:
                numRoman+="CCCC";break;
            case 5:
                numRoman+="D";break;
            case 6:
                numRoman+="DC";break;
            case 7:
                numRoman+="DCC";break;
            case 8:
                numRoman+="DCCC";break;
            case 9:
                numRoman+="CM";break;
        }
        //Hayamos las decemas
        switch (hunmd){
            case 1:
                numRoman+="X";break;
            case 2:
                numRoman+="XX";break;
            case 3:
                numRoman+="XXX";break;
            case 4:
                numRoman+="XL";break;
            case 5:
                numRoman+="L";break;
            case 6:
                numRoman+="LX";break;
            case 7:
                numRoman+="LXX";break;
            case 8:
                numRoman+="LXXX";break;
            case 9:
                numRoman+="CM";break;
        }
        //Hayamos las unidades
        switch (unit){
            case 1:
                numRoman+="I";break;
            case 2:
                numRoman+="II";break;
            case 3:
                numRoman+="III";break;
            case 4:
                numRoman+="IV";break;
            case 5:
                numRoman+="V";break;
            case 6:
                numRoman+="VI";break;
            case 7:
                numRoman+="VII";break;
            case 8:
                numRoman+="VIII";break;
            case 9:
                numRoman+="IX";break;
        }
        System.out.println(numRoman);
   return numRoman;
    }
}

Class RomanNumerals:

public class RomanNumerals implements IRomanEquivalents{

    public static String arabicToRoman(int n) {
        String roman = "";
        int resto = n;

        for (RomanEquivalent eq: EQUIVALENTS) {
            if(resto / eq.arabic >= 0){
                int times = Math.round(resto/eq.arabic);
                String value = eq.roman;
                resto -= (times * eq.arabic);
                roman += StringUtil.repetirCadena(times,value);
            }
        }

        return roman;
    }
}

Interface:

public interface IRomanEquivalents {
    ArrayList<RomanEquivalent> EQUIVALENTS= new ArrayList<RomanEquivalent>(
            Arrays.asList(
                    new RomanEquivalent(1000,"M"),
                    new RomanEquivalent(900,"CM"),
                    new RomanEquivalent(500,"D"),
                    new RomanEquivalent(400,"CD"),
                    new RomanEquivalent(100,"C"),
                    new RomanEquivalent(90,"XC"),
                    new RomanEquivalent(50,"L"),
                    new RomanEquivalent(40,"XL"),
                    new RomanEquivalent(10,"X"),
                    new RomanEquivalent(9,"IX"),
                    new RomanEquivalent(5,"V"),
                    new RomanEquivalent(4,"IV"),
                    new RomanEquivalent(1,"I")
            )
    );
}

RomanEquivalent:

public class RomanEquivalent {
    int arabic;
    String roman;

    public RomanEquivalent(int arabic, String roman) {
        this.arabic = arabic;
        this.roman = roman;
    }
}

String Util:

public class StringUtil {
    
     static String repetirCadena(int times, String value){
        String cadena = "";
        while(times-- > 0){
            cadena += value;
        }
        return cadena;
    }
}
public class FizzBuzz {
    public static String fizzBuzz(int n) {
        if(n % 5 == 0 && n % 3 == 0){
            return "FizzBuzz";
        }
        if(n % 3 == 0){
            return "Fizz";
        }
        if(n % 5 == 0){
            return "Buzz";
        }
        return Integer.toString(n);
    }
}

Reto No. 1

public class FizzBuzz {
    public static String fizzBuzz(int number) {
        String result = "";
        if (number % 3 == 0)
            result = "Fizz";
        if (number % 5 == 0)
            result += "Buzz";
        return result.isEmpty() ? String.valueOf(number): result;
    }
}

Reto No. 2: Posiblemente se pueda refactorizar un poco m谩s

public class RomanNumerals {
    private static int arabicNumber;

    public static String arabicToRoman(int arabicNumberParm) {
        arabicNumber = arabicNumberParm;
        String result = "";
        int numberToConvert = 0;

        for (int i = 0; i < 4; i++) {
            numberToConvert = calculateNumberToConvert(numberToConvert, (int) Math.pow(10, i + 1));
            result = addLetters(numberToConvert, (i * 2)) + result;
        }

        return result;
    }

    private static int calculateNumberToConvert(int minus, int divisor) {
        arabicNumber -= minus;
        int result = arabicNumber - ((arabicNumber/divisor) * divisor);
        result /= (divisor / 10);
        return result;
    }

    private static String addLetters(int number, int position) {
        String[] romanNumbers = {"I","V","X","L","C", "D", "M", "", ""};
        String result = "";
        if (number <= 3)
            result = StringUtil.repeat(romanNumbers[position], number);
        if (number == 4)
            result = romanNumbers[position] + romanNumbers[position + 1];
        if (number >= 5 && number <= 8) {
            result = romanNumbers[position + 1];
            result += StringUtil.repeat(romanNumbers[position], number - 5);
        }
        if (number == 9)
            result = romanNumbers[position] + romanNumbers[position + 2];
        return result;
    }

} 
public class FizzBuzz {

    public static String fizzBuzz(int num) {
        if (num % 3 == 0 && num % 5 == 0)
            return "FizzBuzz";
        else if (num % 3 == 0)
            return "Fizz";
        else if (num % 5 == 0)
            return "Buzz";
        else
            return String.valueOf(num);
    }

}
public class FizzBuzzShould {

    @Test
    public void returnFizzWhenNumberIsDivisibleBy3() {
        assertThat(FizzBuzz.fizzBuzz(3), is("Fizz"));
        assertThat(FizzBuzz.fizzBuzz(6), is("Fizz"));
    }

    @Test
    public void returnBuzzWhenNumberIsDivisibleBy5() {
        assertThat(FizzBuzz.fizzBuzz(5), is("Buzz"));
        assertThat(FizzBuzz.fizzBuzz(10), is("Buzz"));
    }

    @Test
    public void returnFizzBuzzWhenNumberIsDivisibleBy3And5() {
        assertThat(FizzBuzz.fizzBuzz(15), is("FizzBuzz"));
        assertThat(FizzBuzz.fizzBuzz(30), is("FizzBuzz"));
    }

    @Test
    public void returnSameNumberWhenNumberIsNotDivisibleBy3OrBy5() {
        assertThat(FizzBuzz.fizzBuzz(7), is("7"));
        assertThat(FizzBuzz.fizzBuzz(2), is("2"));
        assertThat(FizzBuzz.fizzBuzz(16), is("16"));
    }
}

Mi implementaci贸n:

package com.platzi.javatests.fizzbuzz;

public class FizzBuzz {

    public static String FizzOrBuzz(int number) {
        String str = "";
        if (number % 5 != 0 && number % 3 != 0){
            str = String.valueOf(number);
        }
        if (number % 3 == 0) {
            str += "Fizz";
        }
        if (number % 5 == 0) {
            str += "Buzz";
        }
        return str;
    }
}

package com.platzi.javatests.fizzbuzz;

import org.junit.Test;

import static org.junit.Assert.*;

public class FizzBuzzShould {

    @Test
    public void return_fizz_if_number_is_divisible_by_3() {
        assertEquals("Fizz", FizzBuzz.FizzOrBuzz(21));
    }

    @Test
    public void return_buzz_if_number_is_divisible_by_5() {
        assertEquals("Buzz", FizzBuzz.FizzOrBuzz(35));
    }

    @Test
    public void return_fizzbuzz_if_number_is_divisible_by_3_and_5() {
        assertEquals("FizzBuzz", FizzBuzz.FizzOrBuzz(45));
    }

    @Test
    public void return_same_number_if_number_is_not_divisible_by_3_or_5() {
        assertEquals("1", FizzBuzz.FizzOrBuzz(1));
    }
}