Updated test coverage
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
//CipherStreamJava/src/main/java/com/mattrixwv/CipherStreamJava/monoSubstitution/BaseX.java
|
||||
//Mattrixwv
|
||||
// Created: 01-08-22
|
||||
//Modified: 07-09-22
|
||||
//Modified: 04-16-23
|
||||
package com.mattrixwv.cipherstream.monosubstitution;
|
||||
|
||||
|
||||
@@ -16,16 +16,16 @@ import com.mattrixwv.cipherstream.exceptions.InvalidBaseException;
|
||||
|
||||
|
||||
public class BaseX{
|
||||
private static final Logger logger = LoggerFactory.getLogger(BaseX.class);
|
||||
protected static Logger logger = LoggerFactory.getLogger(BaseX.class);
|
||||
|
||||
private String inputString; //The string that needs encoded/decoded
|
||||
private String outputString; //The encoded/decoded string
|
||||
private int base; //The base that the number will be encoded at
|
||||
protected String inputString; //The string that needs encoded/decoded
|
||||
protected String outputString; //The encoded/decoded string
|
||||
protected int base; //The base that the number will be encoded at
|
||||
|
||||
//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);
|
||||
@@ -36,9 +36,9 @@ public class BaseX{
|
||||
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");
|
||||
}
|
||||
|
||||
logger.debug("Setting input string for decoding '{}'", inputString);
|
||||
@@ -67,9 +67,12 @@ public class BaseX{
|
||||
}
|
||||
}
|
||||
//Sets the numeric base
|
||||
private void setBase(int base) throws InvalidBaseException{
|
||||
if(base <= 0){
|
||||
throw new InvalidBaseException("Base cannot be a negative number");
|
||||
protected void setBase(int base) throws InvalidBaseException{
|
||||
if(base < Character.MIN_RADIX){
|
||||
throw new InvalidBaseException("Base cannot be less than " + Character.MIN_RADIX);
|
||||
}
|
||||
else if(base > Character.MAX_RADIX){
|
||||
throw new InvalidBaseException("Base cannot be larger than " + Character.MAX_RADIX);
|
||||
}
|
||||
|
||||
logger.debug("Setting base {}", base);
|
||||
@@ -77,7 +80,7 @@ public class BaseX{
|
||||
this.base = base;
|
||||
}
|
||||
//Encode inputString, store it in outputString, and return it
|
||||
private String encode(){
|
||||
protected String encode(){
|
||||
logger.debug("Encoding");
|
||||
|
||||
//Encode every character in inputString
|
||||
@@ -101,7 +104,7 @@ public class BaseX{
|
||||
return outputString;
|
||||
}
|
||||
//Decode inputString, store it in outputString, and return it
|
||||
private String decode() throws InvalidCharacterException{
|
||||
protected String decode() throws InvalidCharacterException{
|
||||
logger.debug("Decoding");
|
||||
|
||||
//Decode every binary number in the string
|
||||
@@ -114,8 +117,8 @@ public class BaseX{
|
||||
logger.debug("Decoded number {}", num);
|
||||
|
||||
//Make sure it is in a valid range
|
||||
if((num < 0) && (num > 255)){
|
||||
throw new InvalidCharacterException("The base" + base + " string '" + baseXString + "' is not a valid character");
|
||||
if((num < 0) || (num > 255)){
|
||||
throw new InvalidCharacterException("The base" + base + " string '" + baseXString + "' is not a valid ASCII character");
|
||||
}
|
||||
|
||||
//Convert the int to a char and save it
|
||||
@@ -123,8 +126,8 @@ public class BaseX{
|
||||
}
|
||||
|
||||
//Save the output
|
||||
logger.debug("Saving output string '{}'", output);
|
||||
outputString = output.toString();
|
||||
logger.debug("Saving output string '{}'", outputString);
|
||||
|
||||
//Return the output
|
||||
return outputString;
|
||||
|
||||
Reference in New Issue
Block a user