Aprende todo un fin de semana sin pagar una suscripci贸n 馃敟

Aprende todo un fin de semana sin pagar una suscripci贸n 馃敟

Reg铆strate

Comienza en:

1D
16H
31M
19S
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 167

Preguntas 0

Ordenar por:

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

o inicia sesi贸n.

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 #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;    
}
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;
    }
}```

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"));

}

Practica 馃捇
Reto 1

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 #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

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));
    }
}

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 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));
    }

}
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));
    }
}

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));
    }
}

Un reto que me dejo horas pensando, pero al final agregue un contador que muestra el rango de n煤meros hasta n numero en decimal y romano.

 public static String fizzbuzz(int number) {
        String result = "";
        int cont = 0;
        if (number % 3 == 0) {
            result += "Fizz";
            cont++;
        }
        if (number % 5 == 0) {
            result += "Buzz";
            cont++;
        }
        if (cont == 0) result += number;

        return result;
    }

//Clase

package org.example.Prueba1.Util;

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);
        }
    }
}

}

//Clase test

package org.example.Prueba1.Util;

import org.junit.Test;

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

public class FizzBuzzTest {

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

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

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

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

}

Reto #1

public class FizzBuzz {

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

Reto #2

public class RomanNumerals {

  final static String symbols = "IVXLCDM";

  public static String arabicToRoman(int n) {
    return getNumber(new StringBuffer(), n, 0).toString();
  }

  private static StringBuffer getNumber(final StringBuffer builder, int n, final int seed1) {
    if (n >= 10) {
      getNumber(builder, n / 10, seed1 + 1);
      n = n%10;
    }
    if (n == 9) {
      return builder.append(eq(1, seed1)).append(eq(1, seed1 + 1));
    }
    if (n >= 5) {
      builder.append(eq(5, seed1));
      n %=5;
    }
    if (n == 4) {
      return builder.append(eq(1, seed1)).append(eq(5, seed1));
    }
    for (;n > 0;n--) {
      builder.append(eq(1, seed1));
    }
    return builder;
  }

  static char eq(final int c, final int seed) {
    return symbols.charAt((c==1?0:1) + seed*2);
  }

}

//Retoo # 1
public class FizzBuzz {
public static String fizzBuzz(int i) {
String num = 鈥溾;
if (i % 3 == 0) {
num += 鈥淔izz鈥;
}
if (i % 5 == 0) {
num += 鈥淏uzz鈥;
}
return num.isEmpty() ? i + 鈥溾 : num;
}
}

//Retoo #2
public class RomanNumber {
static Map<Integer, String> roman = new TreeMap<>();

public static String arabicToRoman(int number) {
    roman.put(1, "I");
    roman.put(2, "II");
    roman.put(3, "III");
    roman.put(4, "IV");
    roman.put(5, "V");
    roman.put(6, "VI");
    roman.put(7, "VII");
    roman.put(8, "VIII");
    roman.put(9, "IX");
    roman.put(10, "X");
    roman.put(40, "XL");
    roman.put(50, "L");
    roman.put(90, "XC");
    roman.put(100, "C");
    roman.put(400, "CD");
    roman.put(500, "D");
    roman.put(900, "CM");
    roman.put(1000, "M");
    if (roman.containsKey(number)) {
        return roman.get(number);
    }
    int numR = 11;
    while (numR <= number) {
        String rom = "";
        int digits = (int) (Math.pow(10, String.valueOf(numR).length() - 1));
        int unit = (numR % digits);
        int tens = numR - unit;
        if (roman.containsKey(tens)) {
            rom += roman.get(tens) + ((roman.get(unit) == null) ? "" : roman.get(unit));
        } else {
            String g = roman.get(tens - digits);
            rom += g + roman.get(digits);
        }
        roman.put(numR, rom);
        numR++;
    }
    return roman.get(number);
}

}

Reto 1

Para este reto utilic茅 un StringBuilder ya que es m谩s eficiente para concatenar:

public class FizzBuzz {

	public static String fizzBuzz(int n) {
		var strB = new StringBuilder();
		
		if (n%3 == 0) strB.append("Fizz");
		if (n%5 == 0) strB.append("Buzz");
		
		return (strB.length() > 0) ? strB.toString() : String.valueOf(n);
	}
	
}

Reto 2

En el siguiente, refactoric茅 el c贸digo para utilizar el concepto del numeral como un enum que propuso un compa帽ero, ya que me pareci贸 muy compacto y no cambi贸 la l贸gica del programa:

public enum RomanNumerals {

	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;

    private RomanNumerals(int value) {
        this.value = value;
    }

    public int getValue() {
        return value;
    }

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

	/**
	 * Transforma un n煤mero ar谩bigo en su an谩logo romano. Solo funciona para numeros entre -4000 y 4000 exclusive.
	 * @param n n煤mero a transformar a numerales romanos.
	 * @return cadena con el n煤mero romano.
	 * @throws IllegalArgumentException si el n煤mero a transformar se sale del rango soportado.
	 */
	public static String arabicToRoman(int n) throws IllegalArgumentException{
		if (n < 0) return "-" + arabicToRoman(-n);
		if (n >= 4000 || n == 0) throw new IllegalArgumentException("Solo permitidos n煤meros en el rango |x| > 0");
		
		var strB = new StringBuilder();
		for (RomanNumerals rm: RomanNumerals.getRomanNumerals()) {
			int romanNumeralValue = rm.getValue();
			while (n >= romanNumeralValue) {
				strB.append(rm);
				n -= romanNumeralValue;
			}
		}
		
		return strB.toString();
	}
	
}

Reto N煤meros Romanos

public class ArabicToRoman {


    public static String toRoman(int n) {

        if(n > 3999){
            throw new ArithmeticException("We are limited to 3999, sorry :(");
        }

        String result = "";

        if(n >= 1000){
            int thousands = n / 1000;
            n -= (thousands * 1000);
            for (int i = 0; i < thousands; i++) {
                result += "M";
            }
        }



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

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

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

        if(n >= 100){
            int hundreds = n / 100;
            n -= (hundreds * 100);
            for (int i = 0; i < hundreds; i++) {
                result += "C";
            }
        }

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

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

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

        if(n >= 10){
            int tens = n / 10;
            n -= (tens * 10);
            for (int i = 0; i < tens; i++) {
                result += "X";
            }
        }

        String units = "";

        for (int i = 0; i < n; i++) {
            units += "I";
            units = units.replaceAll("IIII", "IV");
            units = units.replaceAll("IVI", "V");

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

        return result+units;
    }
}

Retos:

// FizzBuzzpublic 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);
    }
}

// Test Case FizzBuzz
class FizzBuzzShould {

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

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

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

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

}

 // Test Case FizzBuzz
    class FizzBuzzShould {

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

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

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

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

//Roman numerals

public class RomanNumber {

public static String arabicToRoman(int n) {
    if (n <= 0 || n >= 4000) {
        throw new IllegalArgumentException("S贸lo se permiten n煤meros positivos entre 1 y 4000");
    }

    int actualArabicNumberSize = String.valueOf(n).length();
    String arabicNumber = String.valueOf(n);
    StringBuilder romanNumber = new StringBuilder();

    for (int i = 0; i < String.valueOf(n).length(); i++) {
        int actualArabicNumber = Integer.parseInt(arabicNumber.substring(i, i + 1));
        String actualRoman = getRoman(actualArabicNumber, actualArabicNumberSize);

        if (actualRoman.equals("") && actualArabicNumber <= 3) {
            actualRoman = getRepeateadLetters(actualArabicNumberSize, actualArabicNumber, actualRoman);
        }

        if (actualRoman.equals("") && actualArabicNumber == 4) {
            actualRoman += getRoman(1, actualArabicNumberSize) + getRoman(5, actualArabicNumberSize);
        }

        if (actualRoman.equals("") && actualArabicNumber >= 6 && actualArabicNumber <= 8) {
            actualRoman += getRoman(5, actualArabicNumberSize) + getRepeateadLetters(actualArabicNumberSize, actualArabicNumber % 5, actualRoman);
        }

        if (actualRoman.equals("") && actualArabicNumber == 9) {
            actualRoman += getRepeateadLetters(actualArabicNumberSize, 1, actualRoman) + getRoman(1, actualArabicNumberSize + 1);
        }

        romanNumber.append(actualRoman);
        actualArabicNumberSize--;
    }

    return romanNumber.toString();
}

private static String getRepeateadLetters(int arabicNumberSize, int times, String actualRoman) {
    return actualRoman + String.valueOf(getRoman(1, arabicNumberSize)).repeat(Math.max(0, times));
}

private static String getRoman(int n, int arabicSize) {
    String roman;
    n *= Math.pow(10, arabicSize - 1);

    switch (n) {
        test case 1: {
            roman = "I";
            break;
        }
        test case 5: {
            roman = "V";
            break;
        }
        test case 10: {
            roman = "X";
            break;
        }
        test case 50: {
            roman = "L";
            break;
        }
        test case 100: {
            roman = "C";
            break;
        }
        test case 500: {
            roman = "D";
            break;
        }
        test case 1000: {
            roman = "M";
            break;
        }
        default:
            roman = "";
    }

    return roman;
}

}


     //Test Roman numerals 

       class RomanNumberShould {

    @Test
    void return_proper_romans_conversion_table() {
        assertEquals("I", RomanNumber.arabicToRoman(1));
        assertEquals("V", RomanNumber.arabicToRoman(5));
        assertEquals("X", RomanNumber.arabicToRoman(10));
        assertEquals("L", RomanNumber.arabicToRoman(50));
        assertEquals("C", RomanNumber.arabicToRoman(100));
        assertEquals("D", RomanNumber.arabicToRoman(500));
        assertEquals("M", RomanNumber.arabicToRoman(1000));
    }

    @Test
    void return_II_when_number_is_two() {
        assertEquals("II", RomanNumber.arabicToRoman(2));
    }

    @Test
    void return_III_when_number_is_three() {
        assertEquals("III", RomanNumber.arabicToRoman(3));
    }

    @Test
    void return_IV_when_number_is_four() {
        assertEquals("IV", RomanNumber.arabicToRoman(4));
    }

    @Test
    void return_VI_when_number_is_six() {
        assertEquals("VI", RomanNumber.arabicToRoman(6));
    }

    @Test
    void return_VI_when_number_is_seven() {
        assertEquals("VII", RomanNumber.arabicToRoman(7));
    }

    @Test
    void return_VI_when_number_is_eight() {
        assertEquals("VIII", RomanNumber.arabicToRoman(8));
    }

    @Test
    void return_VI_when_number_is_nine() {
        assertEquals("IX", RomanNumber.arabicToRoman(9));
    }

    @Test
    void return_XI_when_number_is_eleven() {
        assertEquals("XI", RomanNumber.arabicToRoman(11));
    }

    @Test
    void return_XIV_when_number_is_fourteen() {
        assertEquals("XIV", RomanNumber.arabicToRoman(14));
    }

    @Test
    void return_XV_when_number_is_fifteen() {
        assertEquals("XV", RomanNumber.arabicToRoman(15));
    }

    @Test
    void return_XVI_when_number_is_sixteen() {
        assertEquals("XVI", RomanNumber.arabicToRoman(16));
    }

    @Test
    void return_XXIV_when_number_is_twentyfour() {
        assertEquals("XXIV", RomanNumber.arabicToRoman(24));
    }

    @Test
    void return_XLIX_when_number_is_fourtynine() {
        assertEquals("XLIX", RomanNumber.arabicToRoman(49));
    }

    @Test
    void return_LI_when_number_is_fiftyone() {
        assertEquals("LI", RomanNumber.arabicToRoman(51));
    }

    @Test
    void return_LVI_when_number_is_fiftysix() {
        assertEquals("LVI", RomanNumber.arabicToRoman(56));
    }

    @Test
    void return_LX_when_number_is_sixty() {
        assertEquals("LX", RomanNumber.arabicToRoman(60));
    }

    @Test
    void return_LXX_when_number_is_seventy() {
        assertEquals("LXX", RomanNumber.arabicToRoman(70));
    }

    @Test
    void return_LXXX_when_number_is_eighty() {
        assertEquals("LXXX", RomanNumber.arabicToRoman(80));
    }

    @Test
    void return_LXXXI_when_number_is_eightyone() {
        assertEquals("LXXXI", RomanNumber.arabicToRoman(81));
    }

    @Test
    void return_LXXXI_when_number_is_eightyfive() {
        assertEquals("LXXXV", RomanNumber.arabicToRoman(85));
    }

    @Test
    void return_LXXXVI_when_number_is_eightysix() {
        assertEquals("LXXXVI", RomanNumber.arabicToRoman(86));
    }

    @Test
    void return_XC_when_number_is_ninety() {
        assertEquals("XC", RomanNumber.arabicToRoman(90));
    }

    @Test
    void return_XCV_when_number_is_ninetyfive() {
        assertEquals("XCV", RomanNumber.arabicToRoman(95));
    }

    @Test
    void return_XCIX_when_number_is_ninetynine() {
        assertEquals("XCIX", RomanNumber.arabicToRoman(99));
    }

    @Test
    void return_CXXVI_when_number_is_onehundredandtwentysix() {
        assertEquals("CXXVI", RomanNumber.arabicToRoman(126));
    }

    @Test
    void return_CD_when_number_is_fourhundred() {
        assertEquals("CD", RomanNumber.arabicToRoman(400));
    }

    @Test
    void return_CDXCV_when_number_is_fourhundredandninetynine() {
        assertEquals("CDXCV", RomanNumber.arabicToRoman(495));
    }

    @Test
    void return_CM_when_number_is_ninehundred() {
        assertEquals("CM", RomanNumber.arabicToRoman(900));
    }

    @Test
    void return_MMDVII_when_number_is_twothousandandfivehundredandseven() {
        assertEquals("MMDVII", RomanNumber.arabicToRoman(2507));
    }

    @Test
    void thorw_runtimeexception_when_number_is_lower_or_equal_than_0_or_greater_or_equal_than_4000() {
        assertThrows(IllegalArgumentException.class, () -> RomanNumber.arabicToRoman(0));
        assertThrows(IllegalArgumentException.class, () -> RomanNumber.arabicToRoman(4000));
    }
}

Reto #1

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

RETO #2

public class RomanNumerals {
    public static String arabicToRoman(int n){
        String result = "";
        int thousands = n / 1000;
        int hundreds = n / 100 % 10;
        int tens= n  / 10 % 10;
        int units = n % 10;
            for(int i = 1; i <= thousands; i++){
                result += "M";
            }
            if(hundreds == 9){
                result +="CM";
            }else if(hundreds >= 5){
                result += "D";
                for(int i=6; i<=hundreds; i++){
                    result += "C";
                }
            }else if(hundreds == 4){
                result += "CD";
            }else{
                for(int i = 1; i<= hundreds; i++){
                    result +="C";
                }
            }
            if(tens == 9){
                result += "XC";
            }else if(tens >= 5){
                result += "L";
                for(int i = 6; i<=tens;i++){
                    result += "X";
                }
            }else if(tens == 4){
                result += "XL";
            }else{
                for(int i = 1; i<=tens;i++){
                    result += "X";
                }
            }
            if(units == 9){
                result += "IX";
            }else if(units>=5){
                result += "V";
                for(int i = 6; i<=units; i++){
                    result += "I";
                }
            }else if(units == 4){
                result += "IV";
            }else{
                for(int i = 1; i<=units; i++){
                    result += "I";
                }
            }
        return result;
    }
}

Reto 1

package com.platzi.javatest.fizzbuzz;

public class FizzBuzz {

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

Reto 2

package com.platzi.javatest.romannumerals;

public class RomanNumerals {

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

RETO 1

package com.platzi.javatests.fizzbuzz;

public class FizzBuzz {

    public static String fizzBuzz(int n) {
        StringBuilder result = new StringBuilder();
        if (n % 3 == 0)
            result.append("Fizz");
        if (n % 5 == 0)
            result.append("Buzz");
        if (result.length() == 0)
            result.append(n);
        return result.toString();
    }
}
 

RETO 2

package com.platzi.javatests.romannumeral;

import java.util.HashMap;
import java.util.Map;

public class RomanNumerals {

    private Map<Integer, String> valueConverter;

    public RomanNumerals() {
        valueConverter = new HashMap<>();
        valueConverter.put(1, "I");
        valueConverter.put(2, "II");
        valueConverter.put(3, "III");
        valueConverter.put(4, "IV");
        valueConverter.put(5, "V");
        valueConverter.put(6, "VI");
        valueConverter.put(7, "VII");
        valueConverter.put(8, "VIII");
        valueConverter.put(9, "IX");
        valueConverter.put(10, "X");
        valueConverter.put(20, "XX");
        valueConverter.put(30, "XXX");
        valueConverter.put(40, "XL");
        valueConverter.put(50, "L");
        valueConverter.put(60, "LX");
        valueConverter.put(70, "LXX");
        valueConverter.put(80, "LXXX");
        valueConverter.put(90, "XC");
        valueConverter.put(100, "C");
        valueConverter.put(200, "CC");
        valueConverter.put(300, "CCC");
        valueConverter.put(400, "CD");
        valueConverter.put(500, "D");
        valueConverter.put(600, "DC");
        valueConverter.put(700, "DCC");
        valueConverter.put(800, "DCCC");
        valueConverter.put(900, "CM");
        valueConverter.put(1000, "M");
        valueConverter.put(2000, "MM");
        valueConverter.put(3000, "MMM");
    }

    public String arabicToRoman(final int n) {
        int value = n;
        StringBuilder result = new StringBuilder();
        if (value > 999) {
            result.append(toThousands(value));
            value = removeFirstNumber(value);
        }
        if (value > 99) {
            result.append(toHundreds(value));
            value = removeFirstNumber(value);
        }
        if (value > 9) {
            result.append(toTens(value));
            value = removeFirstNumber(value);
        }
        if (value > 0) {
            result.append(valueConverter.get(value));
        }
        return result.toString();
    }

    private String toThousands(int n) {
        return valueConverter.get(toFirstNumber(n) * 1000);
    }

    private String toHundreds(int n) {
        return valueConverter.get(toFirstNumber(n) * 100);
    }

    private String toTens(int n) {
        return valueConverter.get(toFirstNumber(n) * 10);
    }

    private int toFirstNumber(int n) {
        return Integer.valueOf(String.valueOf(n).substring(0, 1));
    }

    private int removeFirstNumber(int n) {
        String val = String.valueOf(n).substring(1);
        return Integer.valueOf(val).intValue();
    }

}

public class FizzBuzz {

public static String fizzBuzz(int n) {
    int numEntero = n;
    String numCadena= String.valueOf(numEntero);

    if (n % 3 == 0 && n % 5 != 0) {
        return "Fizz";
    } else if (n % 5 == 0 && n % 3 != 0) {
        return "Buzz";
    } else if (n % 5 == 0 && n % 3 == 0) {
        return "FizzBuzz";
    } else {
        return numCadena;
    }
}

}

public class FizzBuzzTest {
@Test
public void numero_divisible_por_3() {
assertThat(FizzBuzz.fizzBuzz(3), is(鈥淔izz鈥));
}

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

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

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

}
}

Funcion:

public static String numberType(int number) {
        String str = "";
        if (number % 3 == 0)
            str += "Fizz";
        if (number % 5 == 0)
            str += "Buzz";
        return str;
    }

Tests:

@Test
    public void number_is_disvisible_by_3_returns_fizz() {
        assertThat(FizzBuzz.numberType(9), is("Fizz"));
    }

    @Test
    public void number_is_divisible_by_5_returns_buzz() {
        assertThat(FizzBuzz.numberType(80), is("Buzz"));
    }

    @Test
    public void number_is_divisible_by_3_and_5_returns_fizzbuzz() {
        assertThat(FizzBuzz.numberType(60), is("FizzBuzz"));
    }
public class FizzBuzz {
    public static String fizzBuzz(int i) {
        if (i%5==0 && i%3==0) {
            return "FizzBuzz";
        }
        if (i%3==0) {
            return "Fizz";
        }
        if (i%5==0) {
            return "Buzz";
        }
        return String.valueOf(i);
    }
}
import org.junit.Test;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;

public class FizzBuzzShould {

    @Test
    public void return_fizz_if_divisible_by_3() {

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

    @Test
    public void return_buzz_if_divisible_by_5() {

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

    @Test
    public void return_fizzbuzz_if_divisible_by_3_and_5() {

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

    @Test
    public void return_value_if_not_divisible_by_3_or_5() {

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

}

Esta fue mi soluci贸n. Permite la transformaci贸n de los numeros del 0 al 4000. Se pueden transformar del 4000 al infinito, pero seria necesario agregar los siguientes valores romanos en la lista:

package com.platzi.javatest.util;

import java.util.ArrayList;
import java.util.List;

public class NumberUtil {
	
	private List<String> values = new ArrayList<String>();

	public NumberUtil() {
		values.add("I");
		values.add("V");
		values.add("X");
		values.add("L");
		values.add("C");
		values.add("D");
		values.add("M");
		values.add("V");
		values.add("X");
	}
	
	public String arabicToRoman(int value) {
		String returnable = "";
			
		for(int i = 0; i < values.size() / 2; i++) {
			int evaluatedValue = (int) (value % (Math.pow(10, i + 1)) / (Math.pow(10, i)));
			returnable = evaluate0to9(evaluatedValue, 
					"",
					values.get(i * 2), 
					values.get((i * 2) + 1),
					values.get((i * 2) + 2)) + returnable;				
		}

		return returnable;
	}
	
	public String evaluate0to9(int value, String prefix, String valueForUnit, String valueForNextFiveMultiple, String valueForTenUnits) {
		String returnable = "";
		
		if(value >= 0 && value <= 5) {
			if(value > 0 && value <= 3) {
				returnable += prefix;
				
				for(int i = 0; i < value; i++) {
					returnable += valueForUnit;
				}
			}
			if(5 - value == 1) {
				returnable = valueForUnit + valueForNextFiveMultiple;
			}
			if(value - 5 == 0) {
				returnable = valueForNextFiveMultiple;
			}
		} else if (value > 5 && value < 10){
			returnable += evaluate0to9(value - 5, valueForNextFiveMultiple, valueForUnit, valueForTenUnits, "");
		}
		
		return returnable;	
	}
}

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);
    }
}

Tests (FizzBuzz )

class FizzBuzzShould {

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

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

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

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

Romans

public class RomanNumber {

    public static String arabicToRoman(int n) {
        if (n <= 0 || n >= 4000) {
            throw new IllegalArgumentException("S贸lo se permiten n煤meros positivos entre 1 y 4000");
        }

        int actualArabicNumberSize = String.valueOf(n).length();
        String arabicNumber = String.valueOf(n);
        StringBuilder romanNumber = new StringBuilder();

        for (int i = 0; i < String.valueOf(n).length(); i++) {
            int actualArabicNumber = Integer.parseInt(arabicNumber.substring(i, i + 1));
            String actualRoman = getRoman(actualArabicNumber, actualArabicNumberSize);

            if (actualRoman.equals("") && actualArabicNumber <= 3) {
                actualRoman = getRepeateadLetters(actualArabicNumberSize, actualArabicNumber, actualRoman);
            }

            if (actualRoman.equals("") && actualArabicNumber == 4) {
                actualRoman += getRoman(1, actualArabicNumberSize) + getRoman(5, actualArabicNumberSize);
            }

            if (actualRoman.equals("") && actualArabicNumber >= 6 && actualArabicNumber <= 8) {
                actualRoman += getRoman(5, actualArabicNumberSize) + getRepeateadLetters(actualArabicNumberSize, actualArabicNumber % 5, actualRoman);
            }

            if (actualRoman.equals("") && actualArabicNumber == 9) {
                actualRoman += getRepeateadLetters(actualArabicNumberSize, 1, actualRoman) + getRoman(1, actualArabicNumberSize + 1);
            }

            romanNumber.append(actualRoman);
            actualArabicNumberSize--;
        }

        return romanNumber.toString();
    }

    private static String getRepeateadLetters(int arabicNumberSize, int times, String actualRoman) {
        return actualRoman + String.valueOf(getRoman(1, arabicNumberSize)).repeat(Math.max(0, times));
    }

    private static String getRoman(int n, int arabicSize) {
        String roman;
        n *= Math.pow(10, arabicSize - 1);

        switch (n) {
            case 1: {
                roman = "I";
                break;
            }
            case 5: {
                roman = "V";
                break;
            }
            case 10: {
                roman = "X";
                break;
            }
            case 50: {
                roman = "L";
                break;
            }
            case 100: {
                roman = "C";
                break;
            }
            case 500: {
                roman = "D";
                break;
            }
            case 1000: {
                roman = "M";
                break;
            }
            default:
                roman = "";
        }

        return roman;
    }
}

Tests (Romans)

class RomanNumberShould {

    @Test
    void return_proper_romans_conversion_table() {
        assertEquals("I", RomanNumber.arabicToRoman(1));
        assertEquals("V", RomanNumber.arabicToRoman(5));
        assertEquals("X", RomanNumber.arabicToRoman(10));
        assertEquals("L", RomanNumber.arabicToRoman(50));
        assertEquals("C", RomanNumber.arabicToRoman(100));
        assertEquals("D", RomanNumber.arabicToRoman(500));
        assertEquals("M", RomanNumber.arabicToRoman(1000));
    }

    @Test
    void return_II_when_number_is_two() {
        assertEquals("II", RomanNumber.arabicToRoman(2));
    }

    @Test
    void return_III_when_number_is_three() {
        assertEquals("III", RomanNumber.arabicToRoman(3));
    }

    @Test
    void return_IV_when_number_is_four() {
        assertEquals("IV", RomanNumber.arabicToRoman(4));
    }

    @Test
    void return_VI_when_number_is_six() {
        assertEquals("VI", RomanNumber.arabicToRoman(6));
    }

    @Test
    void return_VI_when_number_is_seven() {
        assertEquals("VII", RomanNumber.arabicToRoman(7));
    }

    @Test
    void return_VI_when_number_is_eight() {
        assertEquals("VIII", RomanNumber.arabicToRoman(8));
    }

    @Test
    void return_VI_when_number_is_nine() {
        assertEquals("IX", RomanNumber.arabicToRoman(9));
    }

    @Test
    void return_XI_when_number_is_eleven() {
        assertEquals("XI", RomanNumber.arabicToRoman(11));
    }

    @Test
    void return_XIV_when_number_is_fourteen() {
        assertEquals("XIV", RomanNumber.arabicToRoman(14));
    }

    @Test
    void return_XV_when_number_is_fifteen() {
        assertEquals("XV", RomanNumber.arabicToRoman(15));
    }

    @Test
    void return_XVI_when_number_is_sixteen() {
        assertEquals("XVI", RomanNumber.arabicToRoman(16));
    }

    @Test
    void return_XXIV_when_number_is_twentyfour() {
        assertEquals("XXIV", RomanNumber.arabicToRoman(24));
    }

    @Test
    void return_XLIX_when_number_is_fourtynine() {
        assertEquals("XLIX", RomanNumber.arabicToRoman(49));
    }

    @Test
    void return_LI_when_number_is_fiftyone() {
        assertEquals("LI", RomanNumber.arabicToRoman(51));
    }

    @Test
    void return_LVI_when_number_is_fiftysix() {
        assertEquals("LVI", RomanNumber.arabicToRoman(56));
    }

    @Test
    void return_LX_when_number_is_sixty() {
        assertEquals("LX", RomanNumber.arabicToRoman(60));
    }

    @Test
    void return_LXX_when_number_is_seventy() {
        assertEquals("LXX", RomanNumber.arabicToRoman(70));
    }

    @Test
    void return_LXXX_when_number_is_eighty() {
        assertEquals("LXXX", RomanNumber.arabicToRoman(80));
    }

    @Test
    void return_LXXXI_when_number_is_eightyone() {
        assertEquals("LXXXI", RomanNumber.arabicToRoman(81));
    }

    @Test
    void return_LXXXI_when_number_is_eightyfive() {
        assertEquals("LXXXV", RomanNumber.arabicToRoman(85));
    }

    @Test
    void return_LXXXVI_when_number_is_eightysix() {
        assertEquals("LXXXVI", RomanNumber.arabicToRoman(86));
    }

    @Test
    void return_XC_when_number_is_ninety() {
        assertEquals("XC", RomanNumber.arabicToRoman(90));
    }

    @Test
    void return_XCV_when_number_is_ninetyfive() {
        assertEquals("XCV", RomanNumber.arabicToRoman(95));
    }

    @Test
    void return_XCIX_when_number_is_ninetynine() {
        assertEquals("XCIX", RomanNumber.arabicToRoman(99));
    }

    @Test
    void return_CXXVI_when_number_is_onehundredandtwentysix() {
        assertEquals("CXXVI", RomanNumber.arabicToRoman(126));
    }

    @Test
    void return_CD_when_number_is_fourhundred() {
        assertEquals("CD", RomanNumber.arabicToRoman(400));
    }

    @Test
    void return_CDXCV_when_number_is_fourhundredandninetynine() {
        assertEquals("CDXCV", RomanNumber.arabicToRoman(495));
    }

    @Test
    void return_CM_when_number_is_ninehundred() {
        assertEquals("CM", RomanNumber.arabicToRoman(900));
    }

    @Test
    void return_MMDVII_when_number_is_twothousandandfivehundredandseven() {
        assertEquals("MMDVII", RomanNumber.arabicToRoman(2507));
    }

    @Test
    void thorw_runtimeexception_when_number_is_lower_or_equal_than_0_or_greater_or_equal_than_4000() {
        assertThrows(IllegalArgumentException.class, () -> RomanNumber.arabicToRoman(0));
        assertThrows(IllegalArgumentException.class, () -> RomanNumber.arabicToRoman(4000));
    }
}

Reto 1

FizzBuzz.java

public class FizzBuzz {

    public String fizzBuzz(int number) {

        String result = "";

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

        if(number % 5 == 0){
            result+="Buzz";
        }
        return result != "" ? result : String.valueOf(number);
    }
}

FizzBuzzShould.java

public class FizzBuzzShould {

    private FizzBuzz fizzBuzz;

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

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

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

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

    @Test
    public void return_same_number_when_the_number_is_not_divisible_by_3_or_5(){
        assertEquals(String.valueOf(16), fizzBuzz.fizzBuzz(16));
    }

}

Clase FizzBuzz

package es.jesustfk.javatest.fizzbuzz;

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.equals(""))
            result += n;
        return result;
    }
}

Test FizzBuzz

package es.jesustfk.javatest.fizzbuzz;

import org.junit.Before;
import org.junit.Test;

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

public class FizzBuzzShould {

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

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

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

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

Clase RomanNumeral

package es.jesustfk.javatest.util;

public class RomanNumeral {

    public static String arabicToRoman(int n) {
        InfoNumeral infoNumeral = new InfoNumeral(n,"");

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

        return infoNumeral.getInfo();
//        return result;
    }

    private static InfoNumeral replaceValue(InfoNumeral infoNumeral, int number, String value){
        if(infoNumeral.getNumber() >= number)
            return new InfoNumeral(infoNumeral.getNumber() - number, infoNumeral.getInfo() + value);
        else
            return infoNumeral;
    }

    private static InfoNumeral multiple10(InfoNumeral infoNumeral, int multiple, String value) {
        String result = infoNumeral.getInfo();
        int aux = infoNumeral.getNumber();
        if (aux < multiple)
            return infoNumeral;

        while( aux >= multiple) {
            result += value;
            aux -= multiple;
        }
        return new InfoNumeral(aux, result);
    }

    private static class InfoNumeral {
        private int number;
        private String info;

        public InfoNumeral(int number, String info) {
            this.number = number;
            this.info = info;
        }

        public int getNumber() {
            return number;
        }

        public String getInfo() {
            return info;
        }
    }
}

Test RomanNumeral

package es.jesustfk.javatest.util;

import org.junit.Test;

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

public class RomanNumeralShould {

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    @Test
    public void number_is_2507_then_MMDVII() {
        assertThat(RomanNumeral.arabicToRoman(2507), is("MMDVII"));
    }

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

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

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

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

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

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

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

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

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

    @Test
    public void number_is_900_then_CM() {
        assertThat(RomanNumeral.arabicToRoman(900), is("CM"));
    }
}
public static String arabicToRoman(int n){
        String romano = "";
        int residual = 0;
        if(n > 0 && n < 3999){
            int miles = n / 1000;
            residual = n % 1000;
            romano += "M".repeat(miles);

            if(residual >= 500 && residual < 900){
                romano += "D";
                residual -= 500;
            }

            if(residual >= 900){
                romano += "CM";
                residual -= 900;
            }

            residual = residual % 500;

            if(residual >= 400){
                romano += "CD";
                residual -= 400;
            }

            if(residual >= 100){
                romano += "C".repeat(residual / 100);
            }

            residual = residual % 100;

            if(residual >= 50 && residual < 90){
                romano += "L";
                residual -= 50;
            }

            if(residual >= 90){
                romano += "XC";
                residual -= 90;
            }

            residual = residual % 50;

            if(residual >= 40) {
                romano += "XL";
                residual -= 40;
            }

            if(residual >= 10){
                romano += "X".repeat(residual / 10);
            }

            residual = residual % 10;

            if(residual >= 9){
                romano += "IX";
                residual -= 9;
            }

            if(residual >= 5){
                romano += "V";
                residual -= 5;
            }

            residual = residual % 5;

            if(residual >= 4){
                romano += "IV";
                residual -= 4;
            }

            if(residual >= 1){
                romano += "I".repeat(residual);
            }

        } else if(n == 0){
            romano = "Could not be zero!";
        }
        else  {
            romano = "Too High!";
        }
        return romano;
    }```



public class RomanNumeralsShould {

@Test
public void return_i_when_arabic_is_lower_than_ten() {
    assertThat(RomanNumerals.arabicToRoman(1), is("I"));
    assertThat(RomanNumerals.arabicToRoman(2), is("II"));
    assertThat(RomanNumerals.arabicToRoman(3), is("III"));
    assertThat(RomanNumerals.arabicToRoman(4), is("IV"));
    assertThat(RomanNumerals.arabicToRoman(5), is("V"));
    assertThat(RomanNumerals.arabicToRoman(6), is("VI"));
    assertThat(RomanNumerals.arabicToRoman(7), is("VII"));
    assertThat(RomanNumerals.arabicToRoman(8), is("VIII"));
    assertThat(RomanNumerals.arabicToRoman(9), is("IX"));
}

@Test
public void return_MM_when_arabic_is_greater_than_two_thousands(){
    assertThat(RomanNumerals.arabicToRoman(2507), is("MMDVII"));
    assertThat(RomanNumerals.arabicToRoman(2397), is("MMCCCXCVII"));
}

@Test
public void return_too_high_when_arabic_is_greater_than_3999() {
    assertThat(RomanNumerals.arabicToRoman(4000), is("Too High!"));
}

@Test
public void return_coulb_be_not_zero_when_arabic_is_zero() {
    assertThat(RomanNumerals.arabicToRoman(0), is("Could not be zero!"));
}

}```

Hola

FizzBuzz

public class FizzBuzz {

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

            return String.valueOf(number);
        }
    }
}

.

FizzBuzzShould.class
.

public class FizzBuzzShould {
    public FizzBuzzShould() {
    }

    @Test
    public void return_fizz_if_number_is_divisible_by_3() {
        Assert.assertThat(FizzBuzz.fizzBuzz(9), CoreMatchers.is("Fizz"));
        Assert.assertThat(FizzBuzz.fizzBuzz(12), CoreMatchers.is("Fizz"));
        Assert.assertThat(FizzBuzz.fizzBuzz(33), CoreMatchers.is("Fizz"));
    }

    @Test
    public void return_buzz_if_number_is_divisible_by_5() {
        Assert.assertThat(FizzBuzz.fizzBuzz(10), CoreMatchers.is("Buzz"));
        Assert.assertThat(FizzBuzz.fizzBuzz(50), CoreMatchers.is("Buzz"));
        Assert.assertThat(FizzBuzz.fizzBuzz(70), CoreMatchers.is("Buzz"));
    }

    @Test
    public void return_fizzbuzz_if_number_is_divisible_by_3_and_5() {
        Assert.assertThat(FizzBuzz.fizzBuzz(3255), CoreMatchers.is("FizzBuzz"));
        Assert.assertThat(FizzBuzz.fizzBuzz(90), CoreMatchers.is("FizzBuzz"));
        Assert.assertThat(FizzBuzz.fizzBuzz(150), CoreMatchers.is("FizzBuzz"));
    }

    @Test
    public void return_number_if_number_is_not_divisible_by_3_or_5() {
        Assert.assertThat(FizzBuzz.fizzBuzz(4), CoreMatchers.is(String.valueOf(4)));
        Assert.assertThat(FizzBuzz.fizzBuzz(26), CoreMatchers.is(String.valueOf(26)));
        Assert.assertThat(FizzBuzz.fizzBuzz(52), CoreMatchers.is(String.valueOf(52)));
    }
}