Caesar cipher is implemented

This commit is contained in:
2021-07-25 15:57:53 -04:00
parent aaa2031274
commit 4f8b440c59
4 changed files with 293 additions and 47 deletions

View File

@@ -0,0 +1,73 @@
//CipherStreamJava/src/main/java/mattrixwv/CipherStreamJava/TestCaesar.java
//Matthew Ellison
// Created: 07-25-21
//Modified: 07-25-21
//These are the tests for the Caesar class
package mattrixwv.CipherStreamJava;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
public class TestCaesar{
@Test
public void testDecode(){
//Test 1
Caesar cipher = new Caesar();
String input = "def";
int shift = 3;
String correctOutput = "abc";
String output = cipher.decode(shift, input);
assertEquals("Caesar Decoding failed the first test - Expected: " + correctOutput + "; actual: " + output, correctOutput, output);
//Test 2
input = "def";
shift = 29;
correctOutput = "abc";
output = cipher.decode(shift, input);
assertEquals("Caesar Decoding failed the second test - Expected: " + correctOutput + "; actual: " + output, correctOutput, output);
//Test 3
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 - Expected: " + correctOutput + "; actual: " + output, correctOutput, output);
//Test 4
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 - Expected: " + correctOutput + "; actual: " + output, correctOutput, output);
}
@Test
public void testEncode(){
//Test 1
Caesar cipher = new Caesar();
String input = "abc";
int shift = 3;
String correctOutput = "def";
String output = cipher.encode(shift, input);
assertEquals("Caesar Encoding failed the first test - Expected: " + correctOutput + "; actual: " + output, correctOutput, output);
//Test 2
input = "abc";
shift = 29;
correctOutput = "def";
output = cipher.encode(shift, input);
assertEquals("Caesar Encoding failed the second test - Expected: " + correctOutput + "; actual" + output, correctOutput, output);
//Test 3
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 - Expected: " + correctOutput + "; actual: " + output, correctOutput, output);
//Test 4
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 - Expected: " + correctOutput + "; actual: " + output, correctOutput, output);
}
}