-
Notifications
You must be signed in to change notification settings - Fork 0
/
string_sort_tests.cpp
71 lines (56 loc) · 1.6 KB
/
string_sort_tests.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
#include "string_sort_tests.h"
#include <algorithm>
#include <chrono>
#include <iostream>
#include "string_sort.h"
#include "test_utils.h"
#include "test_data_generator.h"
namespace fs { namespace test
{
namespace impl
{
void check_sort(const std::vector<std::string>& data, bool timing)
{
auto light_data = light_from_normal(data);
const auto my_start_time = std::chrono::system_clock::now();
utils::string_sort(light_data);
const auto my_end_time = std::chrono::system_clock::now();
if (timing)
{
std::cout << "My sort time " << std::chrono::duration_cast<std::chrono::milliseconds>(my_end_time - my_start_time).count()
<< " milliseconds" << std::endl;
}
auto sorted_data = data;
const auto std_start_time = std::chrono::system_clock::now();
std::sort(sorted_data.begin(), sorted_data.end());
const auto std_end_time = std::chrono::system_clock::now();
TEST_CHECK(light_data.size() == data.size());
for (size_t i = 0; i < data.size(); ++i)
{
TEST_CHECK(light_data[i].to_string() == sorted_data[i]);
}
if (timing)
{
std::cout << "Std sort time " << std::chrono::duration_cast<std::chrono::milliseconds>(std_end_time - std_start_time).count()
<< " milliseconds" << std::endl;
}
}
}
void string_sort_tests::test()
{
random_small_test();
random_big_test();
}
void string_sort_tests::random_small_test()
{
test_data_generator generator;
const auto data = generator.generate_strings(100);
impl::check_sort(data, false);
}
void string_sort_tests::random_big_test()
{
test_data_generator generator;
const auto data = generator.generate_strings(10000000);
impl::check_sort(data, true);
}
}}