From 04bc3e1fbffb4c0b83c1a604913ff162265e0ff3 Mon Sep 17 00:00:00 2001 From: congchien <48888448+Chiencho@users.noreply.github.com> Date: Mon, 23 May 2022 15:43:02 +0700 Subject: [PATCH] Create insertion_sort test --- insertion_sort test | 55 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 insertion_sort test diff --git a/insertion_sort test b/insertion_sort test new file mode 100644 index 0000000..3f16091 --- /dev/null +++ b/insertion_sort test @@ -0,0 +1,55 @@ +#include +#include +#include +#include +#include "binary_insertion_sort.h" +static void test() { + /* 1st test: + [3] returns [3] */ + std::vector arr1({3}); + sorting::insertionSort_binsrch(arr1); + assert(std::is_sorted(std::begin(arr1), std::end(arr1))); + std::cout << "True" << std::endl; + + /* 2nd test: + [1,2] returns [1,2] */ + std::vector arr2({1,2}); + sorting::insertionSort_binsrch(arr2); + assert(std::is_sorted(std::begin(arr2), std::end(arr2))); + std::cout << "True" << std::endl; + + /* 3rd test: + [1,3,2,4] returns [1,2,3,4] */ + std::vector arr3({1,3,2,4}); + sorting::insertionSort_binsrch(arr3); + assert(std::is_sorted(std::begin(arr3), std::end(arr3))); + std::cout << "True" << std::endl; + + /* 4th test: + [4,3,2,1] returns [1,2,3,4] */ + std::vector arr4({4,3,2,1}); + sorting::insertionSort_binsrch(arr4); + assert(std::is_sorted(std::begin(arr4), std::end(arr4))); + std::cout << "True" << std::endl; + + /* 5th test: + [-1,-2,1,2] returns [-2,-1,1,2] */ + std::vector arr5({12.8, -3.7, -20.7, -7.1, 2.2}); + sorting::insertionSort_binsrch(arr5); + assert(std::is_sorted(std::begin(arr5), std::end(arr5))); + std::cout << "True" << std::endl; + + /* 6th test: + [0.2,0.1,0.3] returns [0.1,0.2,0.3] */ + std::vector arr6({0.2,0.1,0.3}); + sorting::insertionSort_binsrch(arr6); + assert(std::is_sorted(std::begin(arr6), std::end(arr6))); + std::cout << "True" << std::endl; + + /* 7th test: + [a,b,c] returns 0 */ + std::vector arr7({a,b,c}); + sorting::insertionSort_binsrch(arr7); + assert(std::is_sorted(std::begin(arr7), std::end(arr7))); + std::cout << "True" << std::endl; +}