Updated test coverage
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
//CipherStreamJava/src/main/java/com/mattrixwv/CipherStreamJava/monoSubstitution/Caesar.java
|
||||
//Matthew Ellison
|
||||
// Created: 07-25-21
|
||||
//Modified: 07-09-22
|
||||
//Modified: 04-16-23
|
||||
package com.mattrixwv.cipherstream.monosubstitution;
|
||||
|
||||
|
||||
@@ -12,18 +12,18 @@ import com.mattrixwv.cipherstream.exceptions.InvalidInputException;
|
||||
|
||||
|
||||
public class Caesar{
|
||||
private static final Logger logger = LoggerFactory.getLogger(Caesar.class);
|
||||
protected static Logger logger = LoggerFactory.getLogger(Caesar.class);
|
||||
|
||||
//Fields
|
||||
private String inputString; //The string that needs encoded/decoded
|
||||
private String outputString; //The encoded/decoded string
|
||||
private int shift; //The amount that you need to shift each letter
|
||||
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 int shift; //The amount that you need to shift each letter
|
||||
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
|
||||
|
||||
//Sets shift and makes sure it is within the propper bounds
|
||||
private void setShift(int shiftAmount){
|
||||
protected void setShift(int shiftAmount){
|
||||
logger.debug("Setting shift {}", shiftAmount);
|
||||
|
||||
//If you shift more than 26 you will just be wrapping back around again
|
||||
@@ -32,9 +32,9 @@ public class Caesar{
|
||||
logger.debug("Cleaned shift {}", shift);
|
||||
}
|
||||
//Sets the input string
|
||||
private void setInputString(String inputString) throws InvalidInputException{
|
||||
protected void setInputString(String inputString) throws InvalidInputException{
|
||||
if(inputString == null){
|
||||
throw new NullPointerException("Input cannot be null");
|
||||
throw new InvalidInputException("Input cannot be null");
|
||||
}
|
||||
|
||||
logger.debug("Original input string '{}'", inputString);
|
||||
@@ -63,7 +63,7 @@ public class Caesar{
|
||||
}
|
||||
}
|
||||
//Encodes the inputString and stores the result in outputString
|
||||
private String encode(){
|
||||
protected String encode(){
|
||||
logger.debug("Encoding");
|
||||
|
||||
StringBuilder output = new StringBuilder();
|
||||
@@ -107,12 +107,12 @@ public class Caesar{
|
||||
output.append(currentChar);
|
||||
}
|
||||
|
||||
logger.debug("Saving encoded string '{}'", output);
|
||||
outputString = output.toString();
|
||||
logger.debug("Saving encoded string '{}'", outputString);
|
||||
return outputString;
|
||||
}
|
||||
//Decodes the inputString and stores the result in outputString
|
||||
private String decode(){
|
||||
protected String decode(){
|
||||
logger.debug("Decoding");
|
||||
|
||||
StringBuilder output = new StringBuilder();
|
||||
@@ -156,11 +156,12 @@ public class Caesar{
|
||||
}
|
||||
//If it is whitespace, number, or punctuation just let it pass through
|
||||
//Add it to the output string
|
||||
logger.debug("Decoded character {}", currentChar);
|
||||
output.append(currentChar);
|
||||
}
|
||||
|
||||
logger.debug("Saving decoded string '{}'", output);
|
||||
outputString = output.toString();
|
||||
logger.debug("Saving decoded string '{}'", outputString);
|
||||
return outputString;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user