-
Notifications
You must be signed in to change notification settings - Fork 0
/
Test.cpp
123 lines (102 loc) · 3.13 KB
/
Test.cpp
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
//
// Created by Michal on 06.12.2018.
//
#include "Test.h"
#include "Rotor.h"
void Test::runTests() {
plugboardSetTest();
rotorsSetTest();
rotorMoveTest();
rotorLoadTest();
plugboardSwitchTest();
EncytpTest();
if(!error)
cout<<", so everything is ok";
}
void Test::rotorLoadTest() {
char Rotor4[] = "ESOVPZJAYQUIRHXLNFTGKDCMWB";
Rotor *r = new Rotor(4);
Node<char> *temp = r->getCypher().getHead();
for (int i = 0; temp->next != r->getCypher().getHead(); i++) {
if (temp->data == Rotor4[i])
temp = temp->next;
else {
error = true;
cout << "something goes wrong in rotor's loading" << endl;
break;
}
}
cout << "rotor's loading is ok" << endl;
}
void Test::rotorMoveTest() {
char Rotor5[] = "ESOVPZJAYQUIRHXLNFTGKDCMWB";
Rotor *r = new Rotor(5);
for (int i = 0; r->getCypher().getHead()->next->data != 'E'; i++) {
if (r->getCypher().getHead()->data == Rotor5[i])
r->moveRotor();
else {
error = true;
cout << "something goes wrong in rotor's Moving" << endl;
break;
}
}
cout << "rotor's Moving is ok" << endl;
}
void Test::plugboardSetTest() {
int rotorsType[] = {1, 2, 3};
string plug = "SZEWTGHP";
string rotorsSettings = "ELA";
E = new Enigma(rotorsType, plug, rotorsSettings);
Node<Pair> *temp = E->getPlugboard()->getPlugBoardChnages().getHead();
for (int i = 0; plug[i] != '\0'; i += 2) {
if (temp->data.first == plug[i] && temp->data.second == plug[i + 1])
temp = temp->next;
else {
error = true;
cout << "something goes wrong in setting plugboard" << endl;
}
}
cout << "plugboard setting is ok" << endl;
}
void Test::rotorsSetTest() {
string rotorsSettings = "ELA";
Rotor *tempRotors[3];
for (int i = 0; i < 3; i++)
tempRotors[i] = E->getRotor(i);
for (int i = 0; i < 3; i++) {
if (tempRotors[i]->getCypher().getHead()->data == rotorsSettings[i])
continue;
else {
error = true;
cout << "something goes wrong in setting rotors" << endl;
}
}
cout << "rotors' setting is ok" << endl;
}
void Test::plugboardSwitchTest() {
string example = "SWITCHINGXXTEST";
for (int i = 0; example[i] != '\0'; i++) {
E->getPlugboard()->switchLetter(example[i]);
}
if (example == "ZEIGCPINTXXGWZG")
cout << "plugboard switching is ok" << endl;
else {
error = true;
cout << "something goes wrong in switching letters with plugboard" << endl;
}
}
void Test::EncytpTest() {
int rotorsType[] = {1, 2, 3};
string plug = "SZEWTGHP";
string rotorsSettings = "ELA";
string example = "ENCRYTINGXTEST";
Enigma *check = new Enigma(rotorsType, plug, rotorsSettings);
E->go(example);
check->go(example);
if (example == "ENCRYTINGXTEST")
cout << "encytping and decrypting is ok" << endl;
else {
error = true;
cout << "something goes wrong in encrypting or decrypting " << endl;
}
}