Added options to leave whitespace and capitals

This commit is contained in:
2021-12-25 14:12:59 -05:00
parent a6a30f38a9
commit 6c40edbdfe
2 changed files with 269 additions and 15 deletions

View File

@@ -1,7 +1,7 @@
//CipherStreamJava/src/main/java/mattrixwv/CipherStreamJava/TestCaesar.java
//CipherStreamJava/src/test/java/mattrixwv/CipherStreamJava/TestCaesar.java
//Matthew Ellison
// Created: 07-25-21
//Modified: 07-25-21
//Modified: 12-25-21
//These are the tests for the Caesar class
package mattrixwv.CipherStreamJava;
@@ -14,7 +14,7 @@ import org.junit.Test;
public class TestCaesar{
@Test
public void testDecode(){
Caesar cipher = new Caesar();
Caesar cipher = new Caesar(true, true);
//Test 1
String input = "def";
@@ -28,24 +28,139 @@ public class TestCaesar{
correctOutput = "abc";
output = cipher.decode(shift, input);
assertEquals("Caesar Decoding failed the second test", correctOutput, output);
//Test 3
input = "DEF";
shift = 3;
correctOutput = "ABC";
output = cipher.decode(shift, input);
assertEquals("Caesar Decoding failed the third test", correctOutput, output);
//Test 4
input = "Qeb nrfzh yoltk clu grjmp lsbo - qeb ixwv ald";
shift = -3;
correctOutput = "The quick brown fox jumps over - the lazy dog";
output = cipher.decode(shift, input);
assertEquals("Caesar Decoding failed the third test", correctOutput, output);
//Test 4
assertEquals("Caesar Decoding failed the fourth test", correctOutput, output);
//Test 5
input = "Qeb nrfzh yoltk clu grjmp lsbo - qeb ixwv ald";
shift = 23;
correctOutput = "The quick brown fox jumps over - the lazy dog";
output = cipher.decode(shift, input);
assertEquals("Caesar Decoding failed the fourth test", correctOutput, output);
assertEquals("Caesar Decoding failed the fifth test", correctOutput, output);
}
@Test
public void testNoWhitespaceDecode(){
Caesar cipher = new Caesar(true, false);
//Test 1
String input = "def";
int shift = 3;
String correctOutput = "abc";
String output = cipher.decode(shift, input);
assertEquals("Caesar Decoding failed the first test", correctOutput, output);
//Test 2
input = "def";
shift = 29;
correctOutput = "abc";
output = cipher.decode(shift, input);
assertEquals("Caesar Decoding failed the second test", correctOutput, output);
//Test 3
input = "DEF";
shift = 3;
correctOutput = "ABC";
output = cipher.decode(shift, input);
assertEquals("Caesar Decoding failed the third test", correctOutput, output);
//Test 4
input = "Qeb nrfzh yoltk clu grjmp lsbo - qeb ixwv ald";
shift = -3;
correctOutput = "Thequickbrownfoxjumpsover-thelazydog";
output = cipher.decode(shift, input);
assertEquals("Caesar Decoding failed the fourth test", correctOutput, output);
//Test 5
input = "Qeb nrfzh yoltk clu grjmp lsbo - qeb ixwv ald";
shift = 23;
correctOutput = "Thequickbrownfoxjumpsover-thelazydog";
output = cipher.decode(shift, input);
assertEquals("Caesar Decoding failed the fifth test", correctOutput, output);
}
@Test
public void testNoCapitalDecode(){
Caesar cipher = new Caesar(false, true);
//Test 1
String input = "def";
int shift = 3;
String correctOutput = "abc";
String output = cipher.decode(shift, input);
assertEquals("Caesar Decoding failed the first test", correctOutput, output);
//Test 2
input = "def";
shift = 29;
correctOutput = "abc";
output = cipher.decode(shift, input);
assertEquals("Caesar Decoding failed the second test", correctOutput, output);
//Test 3
input = "DEF";
shift = 3;
correctOutput = "abc";
output = cipher.decode(shift, input);
assertEquals("Caesar Decoding failed the third test", correctOutput, output);
//Test 4
input = "Qeb nrfzh yoltk clu grjmp lsbo - qeb ixwv ald";
shift = -3;
correctOutput = "the quick brown fox jumps over - the lazy dog";
output = cipher.decode(shift, input);
assertEquals("Caesar Decoding failed the fourth test", correctOutput, output);
//Test 5
input = "Qeb nrfzh yoltk clu grjmp lsbo - qeb ixwv ald";
shift = 23;
correctOutput = "the quick brown fox jumps over - the lazy dog";
output = cipher.decode(shift, input);
assertEquals("Caesar Decoding failed the fifth test", correctOutput, output);
}
@Test
public void testNoCapitalWhitespaceDecode(){
Caesar cipher = new Caesar(false, false);
//Test 1
String input = "def";
int shift = 3;
String correctOutput = "abc";
String output = cipher.decode(shift, input);
assertEquals("Caesar Decoding failed the first test", correctOutput, output);
//Test 2
input = "def";
shift = 29;
correctOutput = "abc";
output = cipher.decode(shift, input);
assertEquals("Caesar Decoding failed the second test", correctOutput, output);
//Test 3
input = "DEF";
shift = 3;
correctOutput = "abc";
output = cipher.decode(shift, input);
assertEquals("Caesar Decoding failed the third test", correctOutput, output);
//Test 4
input = "Qeb nrfzh yoltk clu grjmp lsbo - qeb ixwv ald";
shift = -3;
correctOutput = "thequickbrownfoxjumpsover-thelazydog";
output = cipher.decode(shift, input);
assertEquals("Caesar Decoding failed the fourth test", correctOutput, output);
//Test 5
input = "Qeb nrfzh yoltk clu grjmp lsbo - qeb ixwv ald";
shift = 23;
correctOutput = "thequickbrownfoxjumpsover-thelazydog";
output = cipher.decode(shift, input);
assertEquals("Caesar Decoding failed the fifth test", correctOutput, output);
}
@Test
public void testEncode(){
//Test 1
Caesar cipher = new Caesar();
Caesar cipher = new Caesar(true, true);
String input = "abc";
int shift = 3;
String correctOutput = "def";
@@ -56,19 +171,130 @@ public class TestCaesar{
shift = 29;
correctOutput = "def";
output = cipher.encode(shift, input);
assertEquals("Caesar Encoding failed the second test - Expected: " + correctOutput + "; actual" + output, correctOutput, output);
assertEquals("Caesar Encoding failed the second test", correctOutput, output);
//Test 3
input = "ABC";
shift = 3;
correctOutput = "DEF";
output = cipher.encode(shift, input);
assertEquals("Ceasar Encoding failed the third test", correctOutput, output);
//Test 4
input = "The quick brown fox jumps over - the lazy dog";
shift = -3;
correctOutput = "Qeb nrfzh yoltk clu grjmp lsbo - qeb ixwv ald";
output = cipher.encode(shift, input);
assertEquals("Caesar Encoding failed the third test", correctOutput, output);
//Test 4
assertEquals("Caesar Encoding failed the fourth test", correctOutput, output);
//Test 5
input = "The quick brown fox jumps over - the lazy dog";
shift = 23;
correctOutput = "Qeb nrfzh yoltk clu grjmp lsbo - qeb ixwv ald";
output = cipher.encode(shift, input);
assertEquals("Caesar Encoding failed the third test", correctOutput, output);
assertEquals("Caesar Encoding failed the fifth test", correctOutput, output);
}
@Test
public void testNoWhitespaceEncode(){
//Test 1
Caesar cipher = new Caesar(true, false);
String input = "abc";
int shift = 3;
String correctOutput = "def";
String output = cipher.encode(shift, input);
assertEquals("Caesar Encoding failed the first test", correctOutput, output);
//Test 2
input = "abc";
shift = 29;
correctOutput = "def";
output = cipher.encode(shift, input);
assertEquals("Caesar Encoding failed the second test", correctOutput, output);
//Test 3
input = "ABC";
shift = 3;
correctOutput = "DEF";
output = cipher.encode(shift, input);
assertEquals("Ceasar Encoding failed the third test", correctOutput, output);
//Test 4
input = "The quick brown fox jumps over - the lazy dog";
shift = -3;
correctOutput = "Qebnrfzhyoltkclugrjmplsbo-qebixwvald";
output = cipher.encode(shift, input);
assertEquals("Caesar Encoding failed the fourth test", correctOutput, output);
//Test 5
input = "The quick brown fox jumps over - the lazy dog";
shift = 23;
correctOutput = "Qebnrfzhyoltkclugrjmplsbo-qebixwvald";
output = cipher.encode(shift, input);
assertEquals("Caesar Encoding failed the fifth test", correctOutput, output);
}
@Test
public void testNoCapitalEncode(){
//Test 1
Caesar cipher = new Caesar(false, true);
String input = "abc";
int shift = 3;
String correctOutput = "def";
String output = cipher.encode(shift, input);
assertEquals("Caesar Encoding failed the first test", correctOutput, output);
//Test 2
input = "abc";
shift = 29;
correctOutput = "def";
output = cipher.encode(shift, input);
assertEquals("Caesar Encoding failed the second test", correctOutput, output);
//Test 3
input = "ABC";
shift = 3;
correctOutput = "def";
output = cipher.encode(shift, input);
assertEquals("Ceasar Encoding failed the third test", correctOutput, output);
//Test 4
input = "The quick brown fox jumps over - the lazy dog";
shift = -3;
correctOutput = "qeb nrfzh yoltk clu grjmp lsbo - qeb ixwv ald";
output = cipher.encode(shift, input);
assertEquals("Caesar Encoding failed the fourth test", correctOutput, output);
//Test 5
input = "The quick brown fox jumps over - the lazy dog";
shift = 23;
correctOutput = "qeb nrfzh yoltk clu grjmp lsbo - qeb ixwv ald";
output = cipher.encode(shift, input);
assertEquals("Caesar Encoding failed the fifth test", correctOutput, output);
}
@Test
public void testNoCapitalWhitespaceEncode(){
//Test 1
Caesar cipher = new Caesar(false, false);
String input = "abc";
int shift = 3;
String correctOutput = "def";
String output = cipher.encode(shift, input);
assertEquals("Caesar Encoding failed the first test", correctOutput, output);
//Test 2
input = "abc";
shift = 29;
correctOutput = "def";
output = cipher.encode(shift, input);
assertEquals("Caesar Encoding failed the second test", correctOutput, output);
//Test 3
input = "ABC";
shift = 3;
correctOutput = "def";
output = cipher.encode(shift, input);
assertEquals("Ceasar Encoding failed the third test", correctOutput, output);
//Test 4
input = "The quick brown fox jumps over - the lazy dog";
shift = -3;
correctOutput = "qebnrfzhyoltkclugrjmplsbo-qebixwvald";
output = cipher.encode(shift, input);
assertEquals("Caesar Encoding failed the fourth test", correctOutput, output);
//Test 5
input = "The quick brown fox jumps over - the lazy dog";
shift = 23;
correctOutput = "qebnrfzhyoltkclugrjmplsbo-qebixwvald";
output = cipher.encode(shift, input);
assertEquals("Caesar Encoding failed the fifth test", correctOutput, output);
}
}