Commit 28524a7b authored by Bran's avatar Bran

Completed, removed edited unit test and replaced with original, updated

code to work with new test
parent 1a9758f2
......@@ -32,31 +32,13 @@ public class AssessmentPartFour
return morseCode.size(); //returns the size of the array string morseCode
}
//////////////////////////////////////////////
public String translateMorse(String filename)
public String translateMorse()
// public String translateMorse(String filename)
{
File file = new File(filename); //creates an instance of a file
morseCode.clear(); // clears the contents of morseCode
//creates an array string containing the alphabet in morse code
String[] morse = {".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--..","/"};
String[] morse = {".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--..","/"};
// creates an array string containing each letter of the alphabet in morse code
String[] alphabet = {"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"," "};
//creates an array string containing the alphabet in lower case
Scanner sc = null; //Assigns a value of null to the scanner "sc"
try //creates a try block and attempts to run the code inside it
{
sc = new Scanner(file); // creates a new scanner and assigns the value of "file" to it
}
catch (FileNotFoundException e) // if the scanner cannot assign the value of "file" , run the following
{
// TODO Auto-generated catch block
e.printStackTrace(); // if an exception is met, prints the stack trace of the instance ready for debugging
}
String lineFromFile; //creates a string called lineFromFile
while (sc.hasNextLine()) //creates a while loop as long as as sc has another line waiting
{
lineFromFile = sc.nextLine(); //stores the next line in the scanner sc
morseCode.add(lineFromFile); // assigns the value of lineFromfile to morsecode
}
//creates an array string containing each letter of the alphabet in lower case
String message=""; //creates a string called message and assigns it nothing
for (int i = 0; i < morseCode.size();i++) //creates a for loop where i = 0 and runs for the size of the array morseCode
{
......@@ -69,6 +51,7 @@ public class AssessmentPartFour
}
}
}
return message; //returns the value of message
}
}
\ No newline at end of file
......@@ -27,7 +27,6 @@ class AssessmentPartFourTest {
})
void testEnryptedCharacter(String filename, int count) {
assertEquals(count,test.loadMorseFromFile(filename));
test.morseCode.clear();
}
@ParameterizedTest
......@@ -39,17 +38,14 @@ class AssessmentPartFourTest {
"test4.txt,13,yippee did it"
})
void testEncryptedString(String filename, int count, String message) {
test.morseCode.clear();
int cc = test.loadMorseFromFile(filename);
if (cc==count)
{
assertEquals(message, test.translateMorse(filename));
assertEquals(message, test.translateMorse());
}
else
{
fail("File failed to load");
}
test.morseCode.clear();
}
}
\ No newline at end of file
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment