Updated test coverage
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
//CipherStreamJava/src/test/java/com/mattrixwv/CipherStreamJava/Baconian.java
|
||||
//Mattrixwv
|
||||
// Created: 01-12-22
|
||||
//Modified: 07-09-22
|
||||
//Modified: 04-15-23
|
||||
package com.mattrixwv.cipherstream.monosubstitution;
|
||||
|
||||
|
||||
@@ -17,21 +17,21 @@ import com.mattrixwv.cipherstream.exceptions.InvalidInputException;
|
||||
|
||||
|
||||
public class Baconian{
|
||||
private static final Logger logger = LoggerFactory.getLogger(Baconian.class);
|
||||
protected static Logger logger = LoggerFactory.getLogger(Baconian.class);
|
||||
|
||||
//Conversions
|
||||
private static final ArrayList<String> code = new ArrayList<>(Arrays.asList(
|
||||
protected static final ArrayList<String> code = new ArrayList<>(Arrays.asList(
|
||||
"aaaaa", "aaaab", "aaaba", "aaabb", "aabaa", "aabab", "aabba","aabbb", "abaaa", "abaaa", "abaab", "ababa", "ababb", //A-M
|
||||
"abbaa", "abbab", "abbba", "abbbb", "baaaa", "baaab", "baaba", "baabb", "baabb", "babaa", "babab", "babba", "babbb" //N-Z
|
||||
));
|
||||
private String inputString; //The string that needs encoded/decoded
|
||||
private String outputString; //The encoded/decoded string
|
||||
private boolean preserveCapitals; //Whether to respect capitals in the output string
|
||||
protected String inputString; //The string that needs encoded/decoded
|
||||
protected String outputString; //The encoded/decoded string
|
||||
protected boolean preserveCapitals; //Whether to respect capitals in the output string
|
||||
|
||||
//Sets the input string
|
||||
private void setInputStringEncode(String inputString) throws InvalidInputException{
|
||||
protected void setInputStringEncode(String inputString) throws InvalidInputException{
|
||||
if(inputString == null){
|
||||
throw new NullPointerException("Input cannot be null");
|
||||
throw new InvalidInputException("Input cannot be null");
|
||||
}
|
||||
|
||||
logger.debug("Setting input string for encoding '{}'", inputString);
|
||||
@@ -52,9 +52,12 @@ public class Baconian{
|
||||
throw new InvalidInputException("Input must contain at least 1 letter");
|
||||
}
|
||||
}
|
||||
private void setInputStringDecode(String inputString) throws InvalidCharacterException, InvalidInputException{
|
||||
protected void setInputStringDecode(String inputString) throws InvalidCharacterException, InvalidInputException{
|
||||
if(inputString == null){
|
||||
throw new NullPointerException("Input cannot be null");
|
||||
throw new InvalidInputException("Input cannot be null");
|
||||
}
|
||||
else if(inputString.isBlank()){
|
||||
throw new InvalidInputException("Input cannot be empty");
|
||||
}
|
||||
|
||||
logger.debug("Setting input string for decoding '{}'", inputString);
|
||||
@@ -86,13 +89,9 @@ public class Baconian{
|
||||
this.inputString = inputString;
|
||||
|
||||
logger.debug("Cleaned input string '{}'", inputString);
|
||||
|
||||
if(this.inputString.isBlank()){
|
||||
throw new InvalidInputException("Input cannot be empty");
|
||||
}
|
||||
}
|
||||
//Encodes the inputString and stores the result in outputString
|
||||
private String encode(){
|
||||
protected void encode(){
|
||||
logger.debug("Encoding");
|
||||
StringJoiner output = new StringJoiner(" ");
|
||||
//Go through every character in the inputString and encode it
|
||||
@@ -113,17 +112,16 @@ public class Baconian{
|
||||
}
|
||||
|
||||
//Add the encoded character to the output
|
||||
logger.debug("Output 'letter' {}", binary);
|
||||
logger.debug("Output letter {}", binary);
|
||||
output.add(binary);
|
||||
}
|
||||
|
||||
//Save and return the output
|
||||
logger.debug("Saving output string '{}'", output);
|
||||
outputString = output.toString();
|
||||
return outputString;
|
||||
logger.debug("Saving output string '{}'", outputString);
|
||||
}
|
||||
//Decodes the inputString and stores the result in outputString
|
||||
private String decode(){
|
||||
protected String decode(){
|
||||
logger.debug("Decoding");
|
||||
|
||||
StringBuilder output = new StringBuilder();
|
||||
@@ -154,8 +152,8 @@ public class Baconian{
|
||||
}
|
||||
|
||||
//Save and return the output
|
||||
logger.debug("Saving output string '{}'", output);
|
||||
outputString = output.toString();
|
||||
logger.debug("Saving output string '{}'", outputString);
|
||||
return outputString;
|
||||
}
|
||||
|
||||
@@ -180,7 +178,8 @@ public class Baconian{
|
||||
public String encode(String inputString) throws InvalidInputException{
|
||||
reset();
|
||||
setInputStringEncode(inputString);
|
||||
return encode();
|
||||
encode();
|
||||
return outputString;
|
||||
}
|
||||
//Sets the inputString and decodes the message
|
||||
public String decode(String inputString) throws InvalidCharacterException, InvalidInputException{
|
||||
|
||||
Reference in New Issue
Block a user