Update unit test coverage
This commit is contained in:
@@ -18,27 +18,27 @@ import com.mattrixwv.cipherstream.exceptions.InvalidKeywordException;
|
||||
|
||||
|
||||
public class Columnar{
|
||||
private static final Logger logger = LoggerFactory.getLogger(Columnar.class);
|
||||
protected static final Logger logger = LoggerFactory.getLogger(Columnar.class);
|
||||
|
||||
//Fields
|
||||
private String inputString; //The message that needs to be encoded/decoded
|
||||
private String outputString; //The encoded/decoded message
|
||||
private String keyword; //The keyword used to create the grid
|
||||
private char characterToAdd; //The character that is added to the end of a string to bring it to the correct length
|
||||
private int charsAdded; //The number of characters that were added to the end of the message
|
||||
private ArrayList<ArrayList<Character>> grid; //The grid used to encode/decode the message
|
||||
private boolean preserveCapitals; //Persist capitals in the output string
|
||||
private boolean preserveWhitespace; //Persist whitespace in the output string
|
||||
private boolean preserveSymbols; //Persist symbols in the output string
|
||||
private boolean removePadding; //Remove the padding letters added to the cipher
|
||||
protected String inputString; //The message that needs to be encoded/decoded
|
||||
protected String outputString; //The encoded/decoded message
|
||||
protected String keyword; //The keyword used to create the grid
|
||||
protected char characterToAdd; //The character that is added to the end of a string to bring it to the correct length
|
||||
protected int charsAdded; //The number of characters that were added to the end of the message
|
||||
protected ArrayList<ArrayList<Character>> grid; //The grid used to encode/decode the message
|
||||
protected boolean preserveCapitals; //Persist capitals in the output string
|
||||
protected boolean preserveWhitespace; //Persist whitespace in the output string
|
||||
protected boolean preserveSymbols; //Persist symbols in the output string
|
||||
protected boolean removePadding; //Remove the padding letters added to the cipher
|
||||
|
||||
//Strip the inputString of all non-letter characters and change them to capitals
|
||||
private String getCleanInputString(){
|
||||
protected String getCleanInputString(){
|
||||
logger.debug("Cleaning input string");
|
||||
return inputString.toUpperCase().replaceAll("[^A-Z]", "");
|
||||
}
|
||||
//Create the grid from the keyword
|
||||
private void createGridEncode(){
|
||||
protected void createGridEncode(){
|
||||
logger.debug("Creating grid for encoding");
|
||||
|
||||
//Add the keyword to the first row in the array
|
||||
@@ -57,7 +57,7 @@ public class Columnar{
|
||||
)));
|
||||
}
|
||||
}
|
||||
private void createGridDecode(){
|
||||
protected void createGridDecode(){
|
||||
logger.debug("Creating grid for decoding");
|
||||
|
||||
//Add the keyword to the first row in the array
|
||||
@@ -86,7 +86,7 @@ public class Columnar{
|
||||
}
|
||||
}
|
||||
//Strips invalid characters from the string that needs encoded/decoded
|
||||
private void setInputStringEncode(String inputString) throws InvalidInputException{
|
||||
protected void setInputStringEncode(String inputString) throws InvalidInputException{
|
||||
logger.debug("Setting input string for encoding");
|
||||
|
||||
//Ensure the input isn't null
|
||||
@@ -139,7 +139,7 @@ public class Columnar{
|
||||
throw new InvalidInputException("Input cannot be blank");
|
||||
}
|
||||
}
|
||||
private void setInputStringDecode(String inputString) throws InvalidInputException{
|
||||
protected void setInputStringDecode(String inputString) throws InvalidInputException{
|
||||
logger.debug("Setting input string for decoding");
|
||||
|
||||
//Ensure the input isn't null
|
||||
@@ -225,7 +225,7 @@ public class Columnar{
|
||||
}
|
||||
}
|
||||
//Creates the output string from the grid
|
||||
private void createOutputStringFromColumns(){
|
||||
protected void createOutputStringFromColumns(){
|
||||
logger.debug("Creating output string for encoding");
|
||||
|
||||
//Get the current rows of any characters that you added
|
||||
@@ -274,7 +274,7 @@ public class Columnar{
|
||||
logger.debug("Output string '{}'", output);
|
||||
outputString = output.toString();
|
||||
}
|
||||
private void createOutputStringFromRows(){
|
||||
protected void createOutputStringFromRows(){
|
||||
logger.debug("Creating output string for decoding");
|
||||
|
||||
//Turn the grid into a string
|
||||
@@ -338,7 +338,7 @@ public class Columnar{
|
||||
outputString = output.toString();
|
||||
}
|
||||
//Strips invalid characters from the keyword and creates the grid
|
||||
private void setKeyword(String keyword) throws InvalidKeywordException{
|
||||
protected void setKeyword(String keyword) throws InvalidKeywordException{
|
||||
//Ensure the keyword isn't null
|
||||
if(keyword == null){
|
||||
throw new NullPointerException("Keyword cannot be null");
|
||||
@@ -357,7 +357,7 @@ public class Columnar{
|
||||
}
|
||||
}
|
||||
//Set the character that is added to the end of the string
|
||||
private void setCharacterToAdd(char characterToAdd) throws InvalidCharacterException{
|
||||
protected void setCharacterToAdd(char characterToAdd) throws InvalidCharacterException{
|
||||
if(!Character.isAlphabetic(characterToAdd)){
|
||||
throw new InvalidCharacterException("Character to add must be a letter");
|
||||
}
|
||||
@@ -374,7 +374,7 @@ public class Columnar{
|
||||
logger.debug("Character to add for padding {}", characterToAdd);
|
||||
}
|
||||
//Returns a list of integers that represents the location of the characters of the keyword in alphabetic order
|
||||
private ArrayList<Integer> getKeywordAlphaLocations(){
|
||||
protected ArrayList<Integer> getKeywordAlphaLocations(){
|
||||
logger.debug("Creating an array of keyword letter locations");
|
||||
|
||||
ArrayList<Integer> orderedLocations = new ArrayList<>();
|
||||
@@ -392,7 +392,7 @@ public class Columnar{
|
||||
logger.debug("Array of keyword letters {}", orderedLocations);
|
||||
return orderedLocations;
|
||||
}
|
||||
private ArrayList<Integer> getKeywordOriginalLocations(){
|
||||
protected ArrayList<Integer> getKeywordOriginalLocations(){
|
||||
logger.debug("Creating array of original keyword locations");
|
||||
|
||||
//Figure out the order the columns are in
|
||||
@@ -413,7 +413,7 @@ public class Columnar{
|
||||
return originalOrder;
|
||||
}
|
||||
//Rearanges the grid based on the list of numbers given
|
||||
private void rearangeGrid(ArrayList<Integer> listOrder){
|
||||
protected void rearangeGrid(ArrayList<Integer> listOrder){
|
||||
logger.debug("Rearanging grid");
|
||||
|
||||
//Create a new grid and make sure it is the same size as the original grid
|
||||
@@ -435,7 +435,7 @@ public class Columnar{
|
||||
grid = newGrid;
|
||||
}
|
||||
//Encodes inputString using the Columnar cipher and stores the result in outputString
|
||||
private void encode(){
|
||||
protected void encode(){
|
||||
logger.debug("Encoding");
|
||||
|
||||
//Create the grid
|
||||
@@ -448,7 +448,7 @@ public class Columnar{
|
||||
createOutputStringFromColumns();
|
||||
}
|
||||
//Decodes inputString using the Columnar cipher and stores the result in outputString
|
||||
private void decode(){
|
||||
protected void decode(){
|
||||
logger.debug("Decoding");
|
||||
|
||||
//Create the grid
|
||||
|
||||
Reference in New Issue
Block a user