-
Notifications
You must be signed in to change notification settings - Fork 52
Expand file tree
/
Copy pathROT13Test.java
More file actions
93 lines (72 loc) · 2.07 KB
/
ROT13Test.java
File metadata and controls
93 lines (72 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import org.junit.Test;
import static org.junit.Assert.*;
public class ROT13Test {
@Test
public void rotateStringTest0() {
// Given
String s1 = "ABCDEF";
String s2 = "ABCDEF";
// When
ROT13 cipher = new ROT13();
String actual = cipher.rotate(s1, 'A');
// Then
assertTrue(actual.equals(s2));
}
@Test
public void rotateStringTest1() {
// Given
String s1 = "ABCDEF";
String s2 = "DEFABC";
// When
ROT13 cipher = new ROT13();
String actual = cipher.rotate(s1, 'D');
// Then
assertTrue(actual.equals(s2));
}
@Test
public void rotateStringTest2() {
// Given
String s1 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
String s2 = "NOPQRSTUVWXYZABCDEFGHIJKLM";
// When
ROT13 cipher = new ROT13();
String actual = cipher.rotate(s1, 'N');
System.out.println(s1);
System.out.println(actual);
// Then
assertTrue(actual.equals(s2));
}
@Test
public void cryptTest1() {
// Given
ROT13 cipher = new ROT13('a', 'n');
String Q1 = "Why did the chicken cross the road?";
String A1 = "Jul qvq gur puvpxra pebff gur ebnq?";
String Q2 = "Gb trg gb gur bgure fvqr!";
String A2 = "To get to the other side!";
// When
String actual = cipher.encrypt(Q1);
System.out.println(Q1);
System.out.println(A1);
// Then
assertTrue(actual.equals(A1));
// When
String actual2 = cipher.decrypt(Q2);
System.out.println(Q2);
System.out.println(A2);
// Then
assertTrue(actual2.equals(A2));
}
@Test
public void cryptTest2() {
// Given
ROT13 cipher = new ROT13('a', 'n');
String Q1 = "Why did the chicken cross the road?";
System.out.println(Q1);
// When
String actual = cipher.crypt(cipher.crypt(Q1));
System.out.println(actual);
// Then
assertTrue(actual.equals(Q1));
}
}