Update unit test coverage
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
//CipherStreamJava/src/main/java/com/mattrixwv/CipherStreamJava/monoSubstitution/Porta.java
|
||||
//Mattrixwv
|
||||
// Created: 02-28-22
|
||||
//Modified: 07-09-22
|
||||
//Modified: 04-17-23
|
||||
package com.mattrixwv.cipherstream.monosubstitution;
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ import com.mattrixwv.cipherstream.exceptions.InvalidKeywordException;
|
||||
|
||||
|
||||
public class Porta{
|
||||
private static final Logger logger = LoggerFactory.getLogger(Porta.class);
|
||||
protected static Logger logger = LoggerFactory.getLogger(Porta.class);
|
||||
|
||||
private static final String[] tableau = {
|
||||
"NOPQRSTUVWXYZABCDEFGHIJKLM", //A-B
|
||||
@@ -32,15 +32,15 @@ public class Porta{
|
||||
};
|
||||
|
||||
//Fields
|
||||
private String inputString; //The string that needs encoded/decoded
|
||||
private String outputString; //The encoded/decoded string
|
||||
private String keyword; //The keyword used to encode the input string
|
||||
private boolean preserveCapitals; //Whether to respect capitals in the output string
|
||||
private boolean preserveWhitespace; //Whether to respect whitespace in the output string
|
||||
private boolean preserveSymbols; //Whether to respect symbols in the output string
|
||||
protected String inputString; //The string that needs encoded/decoded
|
||||
protected String outputString; //The encoded/decoded string
|
||||
protected String keyword; //The keyword used to encode the input string
|
||||
protected boolean preserveCapitals; //Whether to respect capitals in the output string
|
||||
protected boolean preserveWhitespace; //Whether to respect whitespace in the output string
|
||||
protected boolean preserveSymbols; //Whether to respect symbols in the output string
|
||||
|
||||
//Ensure all keyword constraints are followed
|
||||
private void setKeyword(String keyword) throws InvalidKeywordException{
|
||||
protected void setKeyword(String keyword) throws InvalidKeywordException{
|
||||
//Make sure the keyword isn't null
|
||||
if(keyword == null){
|
||||
throw new InvalidKeywordException("Keyword cannot be null");
|
||||
@@ -66,7 +66,7 @@ public class Porta{
|
||||
}
|
||||
}
|
||||
//Ensure all input constraints are followed
|
||||
private void setInputString(String inputString) throws InvalidInputException{
|
||||
protected void setInputString(String inputString) throws InvalidInputException{
|
||||
//Ensure the input isn't null
|
||||
if(inputString == null){
|
||||
throw new InvalidInputException("Input cannot be null");
|
||||
@@ -86,7 +86,7 @@ public class Porta{
|
||||
inputString = inputString.replaceAll("\\s", "");
|
||||
}
|
||||
if(!preserveSymbols){
|
||||
logger.debug("Removig symbols");
|
||||
logger.debug("Removing symbols");
|
||||
|
||||
inputString = inputString.replaceAll("[^a-zA-Z\\s]", "");
|
||||
}
|
||||
@@ -101,7 +101,7 @@ public class Porta{
|
||||
}
|
||||
}
|
||||
//Returns the letter that replaces the passed in letter
|
||||
private char getReplacer(int keywordCnt, char letter){
|
||||
protected char getReplacer(int keywordCnt, char letter){
|
||||
logger.debug("Getting letter that replaces {} at {}", letter, keywordCnt);
|
||||
|
||||
char keyLetter = keyword.charAt(keywordCnt % keyword.length());
|
||||
@@ -129,9 +129,21 @@ public class Porta{
|
||||
return replacer;
|
||||
}
|
||||
//Encodes the inputString and stores the result in outputString
|
||||
private void encode(){
|
||||
protected void encode(){
|
||||
logger.debug("Encoding");
|
||||
|
||||
//Encoding is the same as decoding
|
||||
code();
|
||||
}
|
||||
//Decodes the inputString and stores the result in outputString
|
||||
protected void decode(){
|
||||
logger.debug("Decoding");
|
||||
|
||||
//Decoding is the same as encoding
|
||||
code();
|
||||
}
|
||||
//Codes the inputString and stores the result in outputString
|
||||
protected void code(){
|
||||
StringBuilder output = new StringBuilder();
|
||||
|
||||
//Step through every character in the inputString and advance it the correct amount according to the keyword and tableau
|
||||
@@ -156,15 +168,8 @@ public class Porta{
|
||||
}
|
||||
|
||||
//Save the output
|
||||
logger.debug("Saving output string '{}'", output);
|
||||
outputString = output.toString();
|
||||
}
|
||||
//Decodes the inputString and stores the result in outputString
|
||||
private void decode(){
|
||||
logger.debug("Decoding");
|
||||
|
||||
//Decoding is the same as encoding
|
||||
encode();
|
||||
logger.debug("Saving output string '{}'", outputString);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user