-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathtest_insertion_sort.cpp
More file actions
57 lines (45 loc) · 1.34 KB
/
test_insertion_sort.cpp
File metadata and controls
57 lines (45 loc) · 1.34 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
#include <functional>
#include <iostream>
#include <cassert>
#include "insertion_sort.h"
#include "list_pool.h"
#include "algorithm.h"
int main() {
// test binary insertion sort
{
int nums[] = {5, 3, 10, 1, 2};
binary_insertion_sort_n(nums, 5, std::less<int>());
print_range(nums, nums + 5);
assert(is_sorted(nums, nums + 5));
}
// test linear insertion sort
{
int nums[] = {5, 3, 10, 1, 2};
linear_insertion_sort_n(nums, 5, std::less<int>());
print_range(nums, nums + 5);
assert(is_sorted(nums, nums + 5));
}
// test for forward iterators
{
// std::list provides bidirectional iterators and
// std::forward_list is in C++11, so we will use
// our list pool to test this.
list_pool<int, int> pool;
// Create a list "1 2 3",
typename list_pool<int, int>::list_type l = pool.end();
l = pool.allocate(3, l);
l = pool.allocate(2, l);
l = pool.allocate(1, l);
typedef typename list_pool<int, int>::iterator I;
I first(pool, l);
I last(pool);
// do a few rotates and print the results
rotate_right_by_one(first, last);
print_range(first, last);
rotate_right_by_one(first, last);
print_range(first, last);
rotate_right_by_one(first, last);
print_range(first, last);
}
return 0;
}