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