Skip to content

Commit

Permalink
close #9 Stampati i numeri romani in asciart
Browse files Browse the repository at this point in the history
  • Loading branch information
saraferraro18 committed May 17, 2024
1 parent f917481 commit 017e946
Show file tree
Hide file tree
Showing 2 changed files with 203 additions and 10 deletions.
109 changes: 105 additions & 4 deletions src/main/java/it/unipd/mtss/RomanPrinter.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,118 @@
// GIULIA MARCON 2075541
// SARA FERRARO 2076442
////////////////////////////////////////////////////////////////////

package it.unipd.mtss;

public class RomanPrinter {


// Metodo pubblico per convertire un numero intero in numero romano e stamparlo in ASCII
public static String print(int num){


// Chiama il metodo di conversione per ottenere il numero romano
return printAsciiArt(IntegerToRoman.convert(num));
}


// Metodo privato per convertire una stringa di numeri romani in ASCII Art
private static String printAsciiArt(String romanNumber){
//TODO
return null;


// Converte la stringa di numeri romani in un array di caratteri
char[] letters = romanNumber.toCharArray();


// Stringa che conterrà l'output finale in ASCII Art
String str = "";


// Ciclo per ogni riga dell'output ASCII (ci sono 6 righe per ogni carattere)
for (int i = 0; i < 6; i++){


// Ciclo per ogni carattere della stringa di numeri romani
for (int j = 0; j < letters.length; j++){


// Controlla quale carattere romano è e aggiunge la corrispondente riga ASCII
if (letters[j] == 'I'){
switch(i){
case 0: str = str + " _____ "; break;
case 1: str = str + "|_ _| "; break;
case 2: str = str + " | | "; break;
case 3: str = str + " | | "; break;
case 4: str = str + " _| |_ "; break;
case 5: str = str + "|_____| "; break;
}
}
if (letters[j] == 'V'){
switch(i){
case 0: str = str + "__ __ "; break;
case 1: str = str + "\\ \\ / / "; break;
case 2: str = str + " \\ \\ / / "; break;
case 3: str = str + " \\ \\/ / "; break;
case 4: str = str + " \\ / "; break;
case 5: str = str + " \\/ "; break;
}
}
if (letters[j] == 'X'){
switch(i){
case 0: str = str + "__ __ "; break;
case 1: str = str + "\\ \\ / / "; break;
case 2: str = str + " \\ V / "; break;
case 3: str = str + " > < "; break;
case 4: str = str + " / . \\ "; break;
case 5: str = str + "/_/ \\_\\ "; break;
}
}
if (letters[j] == 'L'){
switch(i){
case 0: str = str + " _ "; break;
case 1: str = str + "| | "; break;
case 2: str = str + "| | "; break;
case 3: str = str + "| | "; break;
case 4: str = str + "| |____ "; break;
case 5: str = str + "|______| "; break;
}
}
if (letters[j] == 'C'){
switch(i){
case 0: str = str + " _____ "; break;
case 1: str = str + " / ____| "; break;
case 2: str = str + "| | "; break;
case 3: str = str + "| | "; break;
case 4: str = str + "| |____ "; break;
case 5: str = str + " \\_____| "; break;
}
}
if (letters[j] == 'D'){
switch(i){
case 0: str = str + " _____ "; break;
case 1: str = str + "| __ \\ "; break;
case 2: str = str + "| | | | "; break;
case 3: str = str + "| | | | "; break;
case 4: str = str + "| |__| | "; break;
case 5: str = str + "|_____/ "; break;
}
}
if (letters[j] == 'M'){
switch(i){
case 0: str = str + " __ __ "; break;
case 1: str = str + "| \\/ | "; break;
case 2: str = str + "| \\ / | "; break;
case 3: str = str + "| |\\/| | "; break;
case 4: str = str + "| | | | "; break;
case 5: str = str + "|_| |_| "; break;
}
}
}
// Va a capo dopo ogni riga di caratteri
str += "\n";
}


// Ritorna la stringa finale contenente l'output in ASCII Art
return str;
}
}
}
104 changes: 98 additions & 6 deletions src/test/java/it/unipd/mtss/RomanPrinterTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,110 @@

package it.unipd.mtss;

import static org.junit.Assert.assertTrue;

import static org.junit.Assert.*;


import java.util.Arrays;
import java.util.Collection;


import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;


//Unit test per RomanPrinter
// Utilizza il runner parametrizzato di JUnit per eseguire test con diverse combinazioni di parametri
@RunWith(Parameterized.class)
public class RomanPrinterTests {

//TODO

// Variabili di istanza per l'input e l'output atteso
private String input;
private String expectedOutput;


// Costruttore che inizializza le variabili di istanza con i valori dei parametri
public RomanPrinterTests(String input, String expectedOutput) {
this.input = input;
this.expectedOutput = expectedOutput;
}


// Metodo che fornisce i dati di test come una collezione di array di stringhe
@Parameters
public static Collection<String[]> testConditions() {


// Array bidimensionale con i valori di input e gli output attesi
String[][] expectedOutputs = {
{ "1", " _____ \n" +
"|_ _| \n" +
" | | \n" +
" | | \n" +
" _| |_ \n" +
"|_____| \n" },
{ "3", " _____ _____ _____ \n" +
"|_ _| |_ _| |_ _| \n" +
" | | | | | | \n" +
" | | | | | | \n" +
" _| |_ _| |_ _| |_ \n" +
"|_____| |_____| |_____| \n" },
{ "4", " _____ __ __ \n" +
"|_ _| \\ \\ / / \n" +
" | | \\ \\ / / \n" +
" | | \\ \\/ / \n" +
" _| |_ \\ / \n" +
"|_____| \\/ \n" },
{ "8", "__ __ _____ _____ _____ \n" +
"\\ \\ / / |_ _| |_ _| |_ _| \n" +
" \\ \\ / / | | | | | | \n" +
" \\ \\/ / | | | | | | \n" +
" \\ / _| |_ _| |_ _| |_ \n" +
" \\/ |_____| |_____| |_____| \n" },
{ "19", "__ __ _____ __ __ \n" +
"\\ \\ / / |_ _| \\ \\ / / \n" +
" \\ V / | | \\ V / \n" +
" > < | | > < \n" +
" / . \\ _| |_ / . \\ \n" +
"/_/ \\_\\ |_____| /_/ \\_\\ \n" },
{ "333", " _____ _____ _____ __ __ __ __ __ __ _____ _____ _____ \n" +
" / ____| / ____| / ____| \\ \\ / / \\ \\ / / \\ \\ / / |_ _| |_ _| |_ _| \n" +
"| | | | | | \\ V / \\ V / \\ V / | | | | | | \n" +
"| | | | | | > < > < > < | | | | | | \n" +
"| |____ | |____ | |____ / . \\ / . \\ / . \\ _| |_ _| |_ _| |_ \n" +
" \\_____| \\_____| \\_____| /_/ \\_\\ /_/ \\_\\ /_/ \\_\\ |_____| |_____| |_____| \n" },
{ "500", " _____ \n" +
"| __ \\ \n" +
"| | | | \n" +
"| | | | \n" +
"| |__| | \n" +
"|_____/ \n" },
{ "979", " _____ __ __ _ __ __ __ __ _____ __ __ \n" +
" / ____| | \\/ | | | \\ \\ / / \\ \\ / / |_ _| \\ \\ / / \n" +
"| | | \\ / | | | \\ V / \\ V / | | \\ V / \n" +
"| | | |\\/| | | | > < > < | | > < \n" +
"| |____ | | | | | |____ / . \\ / . \\ _| |_ / . \\ \n" +
" \\_____| |_| |_| |______| /_/ \\_\\ /_/ \\_\\ |_____| /_/ \\_\\ \n" },
{ "1000", " __ __ \n" +
"| \\/ | \n" +
"| \\ / | \n" +
"| |\\/| | \n" +
"| | | | \n" +
"|_| |_| \n" }};


// Ritorna i dati di test come una lista
return Arrays.asList(expectedOutputs);
}


// Test parametrizzato che verifica la conversione da numero intero a numero romano in ASCII Art
@Test
public void shouldAnswerWithTrue()
{
assertTrue( true );
public void testConvertNumbers() {
assertEquals(expectedOutput,
RomanPrinter.print(Integer.parseInt(input)));
}
}

0 comments on commit 017e946

Please sign in to comment.