-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathTestcase_generator(tree).cpp
65 lines (49 loc) · 1.35 KB
/
Testcase_generator(tree).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
/*
author : nuttela
*/
#include<bits/stdc++.h>
using namespace std;
int main() {
// freopen("i3.txt", "w", stdout);
srand(time(NULL));
std::random_device rd;
std::mt19937 eng(rd());
std::uniform_int_distribution < > distr(1, 100);
//static const char generator[] = "abcdefghijklmnopqrstuvwxyz";
//static const char leet[] = "12";
//TEST CASES SET BY USER
int tc = 1;
cout << tc << '\n';
while (tc--) {
// MAXIMUM NODES OF TREE
const int maxN = 10;
const int N = rand() % maxN + 1;
//PRINT NODES OF TREE
cout << N << endl;
//MIN AND MAX VALUE OF NODE OF TREE
int x = 1, y = 10;
//VALUES OF NODES (IF TO BE PROVIDED)
for (int i = 0; i < N; ++i) {
cout << x + rand() % ((y + 1) - (x)) << ' ';
}
cout << endl;
//BASE TREE TEST DATA STARTS
vector < int > nodeIds;
for (int i = 1; i <= N; i++) {
nodeIds.push_back(i);
}
random_shuffle(nodeIds.begin(), nodeIds.end());
vector < int > usedNodeIds = {
nodeIds.back()
};
nodeIds.pop_back();
for (int i = 0; i < N - 1; i++) {
const int newNodeId = nodeIds.back();
const int oldNodeId = usedNodeIds[rand() % usedNodeIds.size()];
cout << newNodeId << " " << oldNodeId << endl;
usedNodeIds.push_back(newNodeId);
nodeIds.pop_back();
}
//BASE TREE TEST DATA ENDS
}
}