-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMachineTest.java
More file actions
42 lines (37 loc) · 1.4 KB
/
Copy pathMachineTest.java
File metadata and controls
42 lines (37 loc) · 1.4 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
package enigma;
import java.util.ArrayList;
import org.junit.Test;
import org.junit.Rule;
import org.junit.rules.Timeout;
import static org.junit.Assert.*;
import java.util.Arrays;
public class MachineTest {
/** Testing time limit. */
@Rule
public Timeout globalTimeout = Timeout.seconds(5);
@Test
public void testDoubleStep() {
Alphabet ac = new CharacterRange('A', 'D');
Rotor one = new Reflector("R1", new Permutation("(AC) (BD)", ac));
Rotor two = new MovingRotor("R2", new Permutation("(ABCD)", ac), "C");
Rotor three = new MovingRotor("R3", new Permutation("(ABCD)", ac), "C");
Rotor four = new MovingRotor("R4", new Permutation("(ABCD)", ac), "C");
String setting = "AAA";
Rotor[] machineRotors = {one, two, three, four};
String[] rotors = {"R1", "R2", "R3", "R4"};
Machine mach = new Machine(ac, 4, 3,
new ArrayList<>(Arrays.asList(machineRotors)));
mach.insertRotors(rotors);
mach.setRotors(setting);
assertEquals("AAAA", getSetting(ac, machineRotors));
mach.convert('a');
assertEquals("AAAB", getSetting(ac, machineRotors));
}
private String getSetting(Alphabet alph, Rotor[] machineRotors) {
String currSetting = "";
for (Rotor r : machineRotors) {
currSetting += alph.toChar(r.setting());
}
return currSetting;
}
}