-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.cc
75 lines (62 loc) · 1.29 KB
/
test.cc
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
//
// Created by JING-MING CHEN on 2023/1/20.
//
#include "merge_sort.h"
#include <iostream>
#include <vector>
#include <cstdlib>
#include "bubble_sort.h"
#include "selection_sort.h"
#include "insert_sort.h"
#include "quick_sort.h"
#include "heap_sort.h"
#include <gtest/gtest.h>
using std::vector;
using std::cout;
using std::endl;
vector<int> original;
vector<int> ans;
vector<int> RandomVector(int size, int range_begin = 0) {
vector<int> result(size);
for (auto& x : result) {
x = rand() % size + range_begin;
}
return result;
}
TEST(BubbleSort, test1) {
auto temp = original;
BubbleSort(temp);
EXPECT_EQ(temp, ans);
}
TEST(SelectionSort, test1) {
auto temp = original;
SelectionSort(temp);
EXPECT_EQ(temp, ans);
}
TEST(InsertSort, test1) {
auto temp = original;
InsertSort(temp);
EXPECT_EQ(temp, ans);
}
TEST(MergeSort, test1) {
auto temp = original;
MergeSort(temp);
EXPECT_EQ(temp, ans);
}
TEST(QuickSort, test1) {
auto temp = original;
QuickSort(temp);
EXPECT_EQ(temp, ans);
}
TEST(HeapSort, test1) {
auto temp = original;
HeapSort(temp);
EXPECT_EQ(temp, ans);
}
int main(int argc, char **argv) {
testing::InitGoogleTest(&argc, argv);
original = RandomVector(10000);
ans = original;
std::sort(ans.begin(), ans.end());
return RUN_ALL_TESTS();
}