-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTestGenerator.cpp
74 lines (66 loc) · 1.73 KB
/
TestGenerator.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
#include "TestGenerator.h"
// attGen function returns an integer number which is the value of one attribute.
int DataGenerator::attGen()
{
return rng() % Data::ATT_MAX + Data::ATT_MIN;
}
// labelGen function return the label of an attribute vector.
char DataGenerator::labelGen(vector<int> att)
{
int left = 0, right = 0;
for (int index = 0; index < att.size(); index++)
{
if (index < att.size() / 2)
left += att[index];
else
right += att[index];
}
if (left < right)
return 'R';
if (left > right)
return 'L';
return 'B';
}
// dataGen function return a random Data.
Data DataGenerator::dataGen()
{
vector<int> att;
att.resize(Data::ATT_SIZE, 0);
for (int index = 0; index < att.size(); index++)
att[index] = attGen();
char label = labelGen(att);
return Data(label, att, -1);
}
// testGen function returns a vector of Data.
// numberOfData is the number of random data.
vector<Data> DataGenerator::testGen(int numberOfData)
{
vector<Data> test;
test.resize(numberOfData);
for (int index = 0; index < numberOfData; index++)
{
test[index] = dataGen();
}
return test;
}
void TestGenerator::print(vector<Data> test)
{
ofstream file(outputFile);
for (Data data : test)
{
//cout << data.toString() << '\n';
file << data.toString() << '\n';
}
}
TestGenerator::TestGenerator(string _outputFile) : outputFile(_outputFile) {}
void TestGenerator::setFileName(string _outputFile)
{
outputFile = _outputFile;
}
void TestGenerator::generate(int numberOfData)
{
cout << "Generating the test . . .";
// Generate the test
print(DataGenerator::testGen(numberOfData));
cout << "Done!";
}