|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+import org.junit.Test;
|
|
|
2
|
+import static org.junit.Assert.*;
|
|
|
3
|
+import static org.junit.Assert.assertTrue;
|
|
|
4
|
+
|
|
|
5
|
+public class CaesarTest {
|
|
|
6
|
+
|
|
|
7
|
+ @Test
|
|
|
8
|
+ public void rotateStringTest0() {
|
|
|
9
|
+ // Given
|
|
|
10
|
+ String s1 = "ABCDEF";
|
|
|
11
|
+ String s2 = "BCDEFA";
|
|
|
12
|
+
|
|
|
13
|
+ // When
|
|
|
14
|
+ Caesar cipher = new Caesar();
|
|
|
15
|
+ String actual = cipher.rotate(s1, 'B');
|
|
|
16
|
+ System.out.println(actual);
|
|
|
17
|
+ // Then
|
|
|
18
|
+ assertTrue(actual.equals(s2));
|
|
|
19
|
+ }
|
|
|
20
|
+
|
|
|
21
|
+ @Test
|
|
|
22
|
+ public void rotateStringTest1() {
|
|
|
23
|
+ // Given
|
|
|
24
|
+ String s1 = "ABCDEF";
|
|
|
25
|
+ String s2 = "DEFABC";
|
|
|
26
|
+
|
|
|
27
|
+ // When
|
|
|
28
|
+ Caesar cipher = new Caesar();
|
|
|
29
|
+ String actual = cipher.rotate(s1, 'D');
|
|
|
30
|
+
|
|
|
31
|
+ // Then
|
|
|
32
|
+ assertTrue(actual.equals(s2));
|
|
|
33
|
+ }
|
|
|
34
|
+
|
|
|
35
|
+ @Test
|
|
|
36
|
+ public void rotateStringTest2() {
|
|
|
37
|
+ // Given
|
|
|
38
|
+ String s1 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
|
|
39
|
+ String s2 = "NOPQRSTUVWXYZABCDEFGHIJKLM";
|
|
|
40
|
+
|
|
|
41
|
+ // When
|
|
|
42
|
+ Caesar cipher = new Caesar();
|
|
|
43
|
+ String actual = cipher.rotate(s1, 'N');
|
|
|
44
|
+ System.out.println(s1);
|
|
|
45
|
+ System.out.println(actual);
|
|
|
46
|
+ // Then
|
|
|
47
|
+ assertTrue(actual.equals(s2));
|
|
|
48
|
+ }
|
|
|
49
|
+
|
|
|
50
|
+ @Test
|
|
|
51
|
+ public void cryptTest1() {
|
|
|
52
|
+ // Given
|
|
|
53
|
+ Caesar cipher = new Caesar('a', 'b');
|
|
|
54
|
+
|
|
|
55
|
+ String Q1 = "Caesar Salad!"; //"Why did the chicken cross the road?";
|
|
|
56
|
+ String A1 = "Bzdrzq Rzkzc!"; //"Jul qvq gur puvpxra pebff gur ebnq?";
|
|
|
57
|
+
|
|
|
58
|
+ String Q2 = "With Chicken"; //"Gb trg gb gur bgure fvqr!";
|
|
|
59
|
+ String A2 = "Xjui Dijdlfo"; //"To get to the other side!";
|
|
|
60
|
+
|
|
|
61
|
+ // When
|
|
|
62
|
+ String actual = cipher.encrypt(Q1);
|
|
|
63
|
+ System.out.println(Q1);
|
|
|
64
|
+ System.out.println(A1);
|
|
|
65
|
+ // Then
|
|
|
66
|
+ assertTrue(actual.equals(A1));
|
|
|
67
|
+
|
|
|
68
|
+ // When
|
|
|
69
|
+ String actual2 = cipher.decrypt(Q2);
|
|
|
70
|
+ System.out.println(Q2);
|
|
|
71
|
+ System.out.println(A2);
|
|
|
72
|
+ // Then
|
|
|
73
|
+ assertTrue(actual2.equals(A2));
|
|
|
74
|
+ }
|
|
|
75
|
+ @Test
|
|
|
76
|
+ public void cryptTest2() {
|
|
|
77
|
+ // Given
|
|
|
78
|
+ Caesar cipher = new Caesar('b', 'o');
|
|
|
79
|
+
|
|
|
80
|
+ String Q1 = "Eat more Chicken?";
|
|
|
81
|
+ System.out.println(Q1);
|
|
|
82
|
+
|
|
|
83
|
+ // When
|
|
|
84
|
+ String actual = cipher.crypt(cipher.crypt(Q1));
|
|
|
85
|
+ System.out.println(actual);
|
|
|
86
|
+ // Then
|
|
|
87
|
+ assertTrue(actual.equals(Q1));
|
|
|
88
|
+ }
|
|
|
89
|
+
|
|
|
90
|
+}
|
|
|
91
|
+
|