-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtesting.h
51 lines (46 loc) · 1.58 KB
/
testing.h
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
#include "lcs.h"
#include <algorithm>
#include <random>
std::default_random_engine generator;
int generateInt(int left, int right)
{
std::uniform_int_distribution<int> distribution(left, right);
return distribution(generator);
}
std::string generateString(size_t size)
{
std::string result = "";
for (size_t i = 1; i < size; i++)
{
int new_char_number = generateInt(0, 25);
char new_char = (char)new_char_number + 'a';
result += new_char;
}
return result;
}
bool testingWithCurrentLength(size_t firstLength, size_t secondLength, unsigned int numberOfTests)
{
bool correctWork = true;
for (unsigned int i = 0; i < numberOfTests; i++)
{
std::string first = generateString(firstLength), second = generateString(secondLength);
std::vector < std::vector <int> > resultOfFastAlgorithm, resultOfSlowAlgorithm;
fastLCS(first, second, resultOfFastAlgorithm);
slowLCS(first, second, resultOfSlowAlgorithm);
if (!compareVectors(resultOfFastAlgorithm, resultOfSlowAlgorithm))
correctWork = false;
}
return correctWork;
}
bool testing(unsigned int numberOfTests)
{
bool correctWork = true;
for (unsigned int i = 0; i <= numberOfTests; i++)
{
size_t firstLength = (size_t)generateInt(0, i), secondLength = (size_t)generateInt(0, i);
unsigned int numberOfTestsWithCurrentLength = (unsigned int)generateInt(10, 30);
if (!testingWithCurrentLength(firstLength, secondLength, numberOfTestsWithCurrentLength))
correctWork = false;
}
return correctWork;
}