-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.cpp
123 lines (96 loc) · 3.22 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
123
#include <iostream>
#include <fstream>
#include <vector>
#include "base.h"
#include "sort_implementations.h"
#include <cassert>
#include <string>
#include <random>
using namespace std;
std::vector<int> rand_vec(int n, int min, int max) {
std::vector<int> result;
std::random_device rd;
std::mt19937 gen(rd());
std::uniform_int_distribution<int> dis(min, max);
for (int i = 0; i < n; ++i) {
result.push_back(dis(gen));
}
return result;
}
std::string generateRandomString(int length) {
const std::string charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 ";
std::random_device rd;
std::mt19937 generator(rd());
std::uniform_int_distribution<int> distribution(0, charset.length() - 1);
std::string randomString;
for (int i = 0; i < length; ++i) {
randomString += charset[distribution(generator)];
}
return randomString;
}
std::vector<std::string> generateRandomStrings(int n, int length) {
std::vector<std::string> randomStrings;
for (int i = 0; i < n; ++i) {
randomStrings.push_back(generateRandomString(length));
}
return randomStrings;
}
int main(){
std::ofstream outputFile("sorting_results.csv");
outputFile << "Sorting Name, N, Comparisons, Seconds" << std::endl;
std::vector<int> arr[25];
for(int i = 2000, j = 0; i <= 50000; i += 2000, j++){
std::vector<int> randomVector = rand_vec(i, 0, 50000);
arr[j] = randomVector;
}
for(int i = 0; i < 25; i++){
std::vector<int> test_copy = arr[i];
SortStats test = bubble_sort(test_copy);
assert(is_sorted(test_copy));
string print = test.to_csv();
outputFile << print << std::endl;
}
for(int i = 0; i < 25; i++){
std::vector<int> test_copy = arr[i];
SortStats test = insertion_sort(test_copy);
assert(is_sorted(test_copy));
string print = test.to_csv();
outputFile << print << std::endl;
}
for(int i = 0; i < 25; i++){
std::vector<int> test_copy = arr[i];
SortStats test = selection_sort(test_copy);
assert(is_sorted(test_copy));
string print = test.to_csv();
outputFile << print << std::endl;
}
for(int i = 0; i < 25; i++){
std::vector<int> test_copy = arr[i];
SortStats test = merge_sort(test_copy);
assert(is_sorted(test_copy));
string print = test.to_csv();
outputFile << print << std::endl;
}
for(int i = 0; i < 25; i++){
std::vector<int> test_copy = arr[i];
SortStats test = quick_sort(test_copy);
assert(is_sorted(test_copy));
string print = test.to_csv();
outputFile << print << std::endl;
}
for(int i = 0; i < 25; i++){
std::vector<int> test_copy = arr[i];
SortStats test = shell_sort(test_copy);
assert(is_sorted(test_copy));
string print = test.to_csv();
outputFile << print << std::endl;
}
for(int i = 0; i < 25; i++){
std::vector<int> test_copy = arr[i];
SortStats test = iquick_sort(test_copy);
assert(is_sorted(test_copy));
string print = test.to_csv();
outputFile << print << std::endl;
}
return 0;
}