Skip to content

Commit

Permalink
Added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ShannonRoberts committed Sep 3, 2019
1 parent ff54c0e commit 5f39c95
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 11 deletions.
29 changes: 18 additions & 11 deletions src/main/java/nz/ac/eit/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ public class App {
"vingt", "vingt et un", "vingt-deux", "vingt-trois", "vingt-quatre", "vingt-cinq", "vingt-six",
"vingt-sept", "vingt-huit", "vingt-neuf", "trente"};

static String[] germanNumbers = {"eins", "zwei", "drei", "vier", "funf", "sechs", "sieben", "acht", "neun",
static String[] germanNumbers = {"einz", "zwei", "drei", "vier", "funf", "sechs", "sieben", "acht", "neun",
"zehn", "elf", "zwolf", "dreizehn", "vierzehn", "funfzehn", "sechzehn", "siebzehn", "achtzehn",
"neunzehn", "zwanzig", "einundzwanzig", "zweiundzwanzig", "dreiundzwanzig", "vierundzwanzig",
"fünfundzwanzig", "sechsundzwanzig", "siebenundzwanzig", "achtundzwanzig", "neunundzwanzig", "dreiβig"};

public static void main(String[] args) {
Converter conv = new Converter();
String userNumber = "";
int translatedNumber = -1;
String chosenLanguage = "";
Expand All @@ -44,18 +45,24 @@ public static void main(String[] args) {
} catch (Exception e) {
System.out.println("Error in picking language: " + e);
}

try{
if (chosenLanguage.equalsIgnoreCase("French")) {
System.out.println(translatedNumber + " translated to french: " + frenchNumbers[translatedNumber -1]);
}
if (chosenLanguage.equalsIgnoreCase("German")) {
System.out.println(translatedNumber + " translated to german: " + germanNumbers[translatedNumber -1]);
}
}catch (Exception e){
System.out.println("Error in translation: " + e);
if(conv.convert(translatedNumber,chosenLanguage) != null){
System.out.println("translated to: " + conv.convert(translatedNumber,chosenLanguage));
}
else{
System.out.println("Invalid input");
}

// try{
// if (chosenLanguage.equalsIgnoreCase("French")) {
// System.out.println(translatedNumber + " translated to french: " + frenchNumbers[translatedNumber -1]);
// }
// if (chosenLanguage.equalsIgnoreCase("German")) {
// System.out.println(translatedNumber + " translated to german: " + germanNumbers[translatedNumber -1]);
// }
// }catch (Exception e){
// System.out.println("Error in translation: " + e);
// }

}


Expand Down
29 changes: 29 additions & 0 deletions src/main/java/nz/ac/eit/Converter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package nz.ac.eit;

public class Converter {
String[] frenchNumbers = {"un", "deux", "trois", "quatre", "cinq", "six", "sept", "huit", "neuf",
"dix", "onze", "douze", "treize", "quatorze", "quinze", "seize", "dix-sept", "dix-huit", "dix-neuf",
"vingt", "vingt et un", "vingt-deux", "vingt-trois", "vingt-quatre", "vingt-cinq", "vingt-six",
"vingt-sept", "vingt-huit", "vingt-neuf", "trente"};

String[] germanNumbers = {"einz", "zwei", "drei", "vier", "funf", "sechs", "sieben", "acht", "neun",
"zehn", "elf", "zwolf", "dreizehn", "vierzehn", "funfzehn", "sechzehn", "siebzehn", "achtzehn",
"neunzehn", "zwanzig", "einundzwanzig", "zweiundzwanzig", "dreiundzwanzig", "vierundzwanzig",
"fünfundzwanzig", "sechsundzwanzig", "siebenundzwanzig", "achtundzwanzig", "neunundzwanzig", "dreiβig"};

public String convert(int number, String chosenLanguage){
try {
if (chosenLanguage.equalsIgnoreCase("French")) {
return frenchNumbers[number - 1];
}
if (chosenLanguage.equalsIgnoreCase("German")) {
return germanNumbers[number - 1];
}
return null;
}catch(Exception e){
return null;
}
}


}
45 changes: 45 additions & 0 deletions src/test/java/nz/ac/eit/Converter_Test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package nz.ac.eit;

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

import static org.junit.Assert.*;

public class Converter_Test {
private Converter conv;
@Before
public void setup(){
conv = new Converter();
}

@Test
public void test_1toGerman_Einz() {

String translated = conv.convert(1,"german");
assertEquals("1 is not giving einz","einz",translated);
}

@Test
public void test_1toFrench_Un() {

String translated = conv.convert(1,"french");
assertEquals("1 is not giving un","un",translated);
}

@Test
public void test_Neg5toFrench_Null() {

String translated = conv.convert(-5,"french");
assertEquals("1 is not giving null",null,translated);
}

@Test
public void test_Neg10toGerman_Null() {

String translated = conv.convert(-10,"german");
assertEquals("1 is not giving null",null,translated);
}



}

0 comments on commit 5f39c95

Please sign in to comment.