Skip to content

Commit 92d2bf0

Browse files
committed
Added tests for comb_sort.cpp
1 parent f030a69 commit 92d2bf0

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

sorting/comb_sort.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
#include <algorithm>
1919
#include <iostream>
20+
#include <cassert>
2021

2122
/**
2223
*
@@ -69,8 +70,26 @@ void CombSort(int *arr, int l, int r) {
6970
}
7071
}
7172

73+
void tests() {
74+
/// Test 1
75+
int arr1[10] = {34, 56, 6, 23, 76, 34, 76, 343, 4, 76};
76+
CombSort(arr1, 0, 10);
77+
assert(std::is_sorted(arr1, arr1 + 10));
78+
std::cout << "Test 1 passed\n";
79+
80+
/// Test 2
81+
int arr2[8] = {-6, 56, -45, 56, 0, -1, 8, 8};
82+
CombSort(arr2, 0, 8);
83+
assert(std::is_sorted(arr2, arr2 + 8));
84+
std::cout << "Test 2 Passed\n";
85+
}
86+
7287
/** Main function */
7388
int main() {
89+
/// Running predefined tests
90+
tests();
91+
92+
/// For user interaction
7493
int n;
7594
std::cin >> n;
7695
int *arr = new int[n];

0 commit comments

Comments
 (0)