Skip to content

Commit 04bc3e1

Browse files
authored
Create insertion_sort test
1 parent cd540cf commit 04bc3e1

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

insertion_sort test

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#include <algorithm>
2+
#include <cassert>
3+
#include <iostream>
4+
#include <vector>
5+
#include "binary_insertion_sort.h"
6+
static void test() {
7+
/* 1st test:
8+
[3] returns [3] */
9+
std::vector<int64_t> arr1({3});
10+
sorting::insertionSort_binsrch(arr1);
11+
assert(std::is_sorted(std::begin(arr1), std::end(arr1)));
12+
std::cout << "True" << std::endl;
13+
14+
/* 2nd test:
15+
[1,2] returns [1,2] */
16+
std::vector<int64_t> arr2({1,2});
17+
sorting::insertionSort_binsrch(arr2);
18+
assert(std::is_sorted(std::begin(arr2), std::end(arr2)));
19+
std::cout << "True" << std::endl;
20+
21+
/* 3rd test:
22+
[1,3,2,4] returns [1,2,3,4] */
23+
std::vector<float> arr3({1,3,2,4});
24+
sorting::insertionSort_binsrch(arr3);
25+
assert(std::is_sorted(std::begin(arr3), std::end(arr3)));
26+
std::cout << "True" << std::endl;
27+
28+
/* 4th test:
29+
[4,3,2,1] returns [1,2,3,4] */
30+
std::vector<float> arr4({4,3,2,1});
31+
sorting::insertionSort_binsrch(arr4);
32+
assert(std::is_sorted(std::begin(arr4), std::end(arr4)));
33+
std::cout << "True" << std::endl;
34+
35+
/* 5th test:
36+
[-1,-2,1,2] returns [-2,-1,1,2] */
37+
std::vector<float> arr5({12.8, -3.7, -20.7, -7.1, 2.2});
38+
sorting::insertionSort_binsrch(arr5);
39+
assert(std::is_sorted(std::begin(arr5), std::end(arr5)));
40+
std::cout << "True" << std::endl;
41+
42+
/* 6th test:
43+
[0.2,0.1,0.3] returns [0.1,0.2,0.3] */
44+
std::vector<float> arr6({0.2,0.1,0.3});
45+
sorting::insertionSort_binsrch(arr6);
46+
assert(std::is_sorted(std::begin(arr6), std::end(arr6)));
47+
std::cout << "True" << std::endl;
48+
49+
/* 7th test:
50+
[a,b,c] returns 0 */
51+
std::vector<float> arr7({a,b,c});
52+
sorting::insertionSort_binsrch(arr7);
53+
assert(std::is_sorted(std::begin(arr7), std::end(arr7)));
54+
std::cout << "True" << std::endl;
55+
}

0 commit comments

Comments
 (0)