Added binary encoding
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
//CipherStreamJava/src/test/java/com/mattrixwv/CipherStreamJava/monoSubstitution/TestBinary.java
|
||||
//Mattrixwv
|
||||
// Created: 01-08-22
|
||||
//Modified: 01-08-22
|
||||
package com.mattrixwv.CipherStreamJava.monoSubstitution;
|
||||
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import com.mattrixwv.CipherStreamJava.exceptions.InvalidCharacterException;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
public class TestBinary{
|
||||
@Test
|
||||
public void testDecode() throws InvalidCharacterException{
|
||||
Binary cipher = new Binary();
|
||||
|
||||
//Test lowercase decoding
|
||||
String inputString = "1100001";
|
||||
String correctOutput = "a";
|
||||
String output = cipher.decode(inputString);
|
||||
assertEquals("Binary failed lowercase decoding.", correctOutput, output);
|
||||
//Test uppercase decoding
|
||||
inputString = "1000001";
|
||||
correctOutput = "A";
|
||||
output = cipher.decode(inputString);
|
||||
assertEquals("Binary failed uppercase decoding.", correctOutput, output);
|
||||
|
||||
//Test whitespace decoding
|
||||
inputString = "1000001 100000 1000010 1001 1000011 1010";
|
||||
correctOutput = "A B\tC\n";
|
||||
output = cipher.decode(inputString);
|
||||
assertEquals("Binary failed whitespace decoding.", correctOutput, output);
|
||||
|
||||
//Test symbol decoding
|
||||
inputString = "1000001 1000000 1000010 101101 1000011 101011";
|
||||
correctOutput = "A@B-C+";
|
||||
output = cipher.decode(inputString);
|
||||
assertEquals("Binary failed symbol decoding.", correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, and symbol decoding
|
||||
inputString = "1000001 101011 1000010 1000000 1000011 100000 1100100 1001 1100101 1010 1100110";
|
||||
correctOutput = "A+B@C d\te\nf";
|
||||
output = cipher.decode(inputString);
|
||||
assertEquals("Binary failed mixed case, whitespace, and symbol decoding.", correctOutput, output);
|
||||
}
|
||||
@Test
|
||||
public void testEncode(){
|
||||
Binary cipher = new Binary();
|
||||
|
||||
//Test lowercase encoding
|
||||
String inputString = "a";
|
||||
String correctOutput = "1100001";
|
||||
String output = cipher.encode(inputString);
|
||||
assertEquals("Binary failed lowercase encoding.", correctOutput, output);
|
||||
//Test uppercase encoding
|
||||
inputString = "A";
|
||||
correctOutput = "1000001";
|
||||
output = cipher.encode(inputString);
|
||||
assertEquals("Binary failed uppercase encoding.", correctOutput, output);
|
||||
|
||||
//Test whitespace encoding
|
||||
inputString = "A B\tC\n";
|
||||
correctOutput = "1000001 100000 1000010 1001 1000011 1010";
|
||||
output = cipher.encode(inputString);
|
||||
assertEquals("Binary failed whitespace encoding.", correctOutput, output);
|
||||
|
||||
//Test symbol encoding
|
||||
inputString = "A@B-C+";
|
||||
correctOutput = "1000001 1000000 1000010 101101 1000011 101011";
|
||||
output = cipher.encode(inputString);
|
||||
assertEquals("Binary failed symbol encoding.", correctOutput, output);
|
||||
|
||||
//Test mixed case, whitespace, and symbol encoding
|
||||
inputString = "A+B@C d\te\nf";
|
||||
correctOutput = "1000001 101011 1000010 1000000 1000011 100000 1100100 1001 1100101 1010 1100110";
|
||||
output = cipher.encode(inputString);
|
||||
assertEquals("Binary failed mixed case, whitespace, and symbol encoding.", correctOutput, output);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user