-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest.cpp
More file actions
149 lines (129 loc) · 5.25 KB
/
test.cpp
File metadata and controls
149 lines (129 loc) · 5.25 KB
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#include <filesystem>
#include <iostream>
#include <ctime>
#include "Algorithm/sort.hpp"
#include "Algorithm/fileinfo.hpp"
#include "Algorithm/search.hpp"
using namespace std;
int key = 0;
string pattern = "test"; //문자열 검증을 위한 값
std::string generateRandomString() {
std::string chars = "abcdefghijklmnopqrstuvwxyz";
std::string result;
// 문자열 길이 50으로 설정
while (result.length() < 50) {
char randomChar = chars[std::rand() % chars.length()];
result += randomChar;
}
key = std::rand() % 2;// "test"를 포함하는지 랜덤으로 결정
if (key == 1) { //key 가 1이면 패턴을 포함하는
// "test"를 포함하는 경우, 랜덤한 위치에 삽입
int position = std::rand() % (result.length() - 3);
result.replace(position, 0, "test");
}
return result;
}// 문자열 검증을 위한 랜덤 문자열 함수
int main(){
cout << "테스트 시작" << endl;
//Sort 테스트
// 임의의 구조체 배열 생성
FileInfo fileArray[5]; // 구조체 배열을 선언합니다.
std::time_t currentTime = std::time(nullptr);
std::srand(static_cast<unsigned int>(currentTime));
for (int i = 0; i < 5; ++i) {
fileArray[i].name = "File" + std::to_string(rand());
fileArray[i].size = std::rand() % 100000;
fileArray[i].is_directory = (std::rand() % 2 == 0);
fileArray[i].modified_time = currentTime + (std::rand() % 3600);
} //랜덤 구조체 생성
std::srand(static_cast<unsigned int>(std::time(nullptr))); // 랜덤 시드 초기화
// 3가지 정렬함수로 정렬 후 검사
// quick_sort check
quick_sort(fileArray, 0, 4, &FileInfo::modified_time, comp<int>);
for (int i = 0; i < 4; i++) {
if(fileArray[i].modified_time > fileArray[i+1].modified_time)
printf("error on quick_sort(time)\n");
}
quick_sort(fileArray, 0, 4, &FileInfo::size, comp<int>);
for (int i = 0; i < 4; i++) {
if(fileArray[i].size > fileArray[i+1].size)
printf("error on quick_sort(size)\n");
}
quick_sort(fileArray, 0, 4, &FileInfo::name, comp<string>);
for (int i = 0; i < 4; i++) {
if(fileArray[i].name > fileArray[i+1].name)
printf("error on quick_sort(name)\n");
}
// merge_sort check
merge_sort(fileArray, 0, 4, &FileInfo::modified_time, comp<int>);
for (int i = 0; i < 4; i++) {
if(fileArray[i].modified_time > fileArray[i+1].modified_time)
printf("error on merge_sort(time)\n");
}
merge_sort(fileArray, 0, 4, &FileInfo::size, comp<int>);
for (int i = 0; i < 4; i++) {
if(fileArray[i].size > fileArray[i+1].size)
printf("error on merge_sort(size)\n");
}
merge_sort(fileArray, 0, 4, &FileInfo::name, comp<string>);
for (int i = 0; i < 4; i++) {
if(fileArray[i].name > fileArray[i+1].name)
printf("error on merge_sort(name)\n");
}
// head_sort check
heap_sort(fileArray, 5, &FileInfo::modified_time, comp<int>);
for (int i = 0; i < 4; i++) {
if(fileArray[i].modified_time > fileArray[i+1].modified_time){
printf("error on heap_sort(time)\n");
printInfo(&fileArray[i],1);
printInfo(&fileArray[i+1],1);
}
}
heap_sort(fileArray, 5, &FileInfo::size, comp<int>);
for (int i = 0; i < 4; i++) {
if(fileArray[i].size > fileArray[i+1].size){
printf("error on heap_sort(size)\n");
printInfo(&fileArray[i],1);
printInfo(&fileArray[i+1],1);
}
}
heap_sort(fileArray, 5, &FileInfo::name, comp<string>);
for (int i = 0; i < 4; i++) {
if(fileArray[i].name > fileArray[i+1].name)
{
printf("error on heap_sort(name)\n");
printInfo(&fileArray[i],1);
printInfo(&fileArray[i+1],1);
}
}
for(int i = 0; i < 50; i++){
string RandomString = generateRandomString();
if(kmp(RandomString, pattern) + key == 1) // key가 0이면 pattern이 없는 스트링
{
cout<<"kmp has error on string " + RandomString <<endl;
cout<<kmp(RandomString, pattern)<<endl;
cout<<key<<endl;
}
if((strstr(RandomString, pattern) == -1 && key == 1) || (strstr(RandomString,pattern)!=-1) && key == 0){
cout<<"strstr has error on string " + RandomString <<endl;
cout<<strstr(RandomString, pattern)<<endl;
cout<<key<<endl;
}
}
// STRSTR, KMP 테스트
// 찾을 임의의 패턴 정하기
// 특정 패턴이 포함된 문자열 케이스 생성
// 패턴이 포함되지 않은 문자열 생성
// 각 함수가 위 문자열에 적절한 값이 리턴되는 지 검사
//DFS, BFS 검사
// 최소 3단계 깊이의 폴더 구조 생성
fs::path p = fs::current_path().string() + "\\..\\Algorithm\\test";
cout << "DFS test" << endl;
cout << p.string() << " path search" << endl;
dfs(p, "hi",KMP); //working
cout << "BFS test" << endl;
cout << p.string() << " path search" << endl;
bfs(p, "hi", STRSTR);
// 깊이에 따라서 파일명 다르게 생성
// DFS, BFS가 어떤 순서로 파일명을 출력하는지 검사
}