Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add tests

  • Loading branch information...
commit ad7b011c0fb89a7228b95edb3baf09eeb802067b 1 parent fa900d5
@gfx authored
Showing with 144 additions and 2 deletions.
  1. +2 −1  .gitignore
  2. +142 −1 test/test.cpp
View
3  .gitignore
@@ -1,4 +1,5 @@
-ench
*~
*.swp
.bin
+*.gc*
+coverage.txt
View
143 test/test.cpp
@@ -11,6 +11,48 @@
using namespace gfx;
+BOOST_AUTO_TEST_CASE( simple0 ) {
+ std::vector<int> a;
+
+ timsort(a.begin(), a.end(), std::less<int>());
+
+ BOOST_CHECK_EQUAL( a.size(), 0 );
+}
+
+BOOST_AUTO_TEST_CASE( simple1 ) {
+ std::vector<int> a;
+
+ a.push_back(42);
+
+ timsort(a.begin(), a.end(), std::less<int>());
+
+ BOOST_CHECK_EQUAL( a.size(), 1 );
+ BOOST_CHECK_EQUAL( a[0], 42 );
+}
+
+BOOST_AUTO_TEST_CASE( simple2 ) {
+ std::vector<int> a;
+
+ a.push_back(10);
+ a.push_back(20);
+
+ timsort(a.begin(), a.end(), std::less<int>());
+
+ BOOST_CHECK_EQUAL( a.size(), 2 );
+ BOOST_CHECK_EQUAL( a[0], 10);
+ BOOST_CHECK_EQUAL( a[1], 20 );
+
+ a.clear();
+ a.push_back(20);
+ a.push_back(10);
+
+ timsort(a.begin(), a.end(), std::less<int>());
+
+ BOOST_CHECK_EQUAL( a.size(), 2 );
+ BOOST_CHECK_EQUAL( a[0], 10);
+ BOOST_CHECK_EQUAL( a[1], 20 );
+}
+
BOOST_AUTO_TEST_CASE( simple10 ) {
std::vector<int> a;
a.push_back(60);
@@ -65,6 +107,7 @@ BOOST_AUTO_TEST_CASE( shuffle30 ) {
timsort(a.begin(), a.end(), std::less<int>());
+ BOOST_CHECK_EQUAL(a.size(), size);
for(int i = 0; i < size; ++i) {
BOOST_CHECK_EQUAL( a[i], (i+1) * 10 );
}
@@ -82,6 +125,7 @@ BOOST_AUTO_TEST_CASE( shuffle31 ) {
timsort(a.begin(), a.end(), std::less<int>());
+ BOOST_CHECK_EQUAL(a.size(), size);
for(int i = 0; i < size; ++i) {
BOOST_CHECK_EQUAL( a[i], (i+1) * 10 );
}
@@ -98,6 +142,7 @@ BOOST_AUTO_TEST_CASE( shuffle32 ) {
timsort(a.begin(), a.end(), std::less<int>());
+ BOOST_CHECK_EQUAL(a.size(), size);
for(int i = 0; i < size; ++i) {
BOOST_CHECK_EQUAL( a[i], (i+1) * 10 );
}
@@ -114,13 +159,33 @@ BOOST_AUTO_TEST_CASE( shuffle128 ) {
timsort(a.begin(), a.end(), std::less<int>());
+ BOOST_CHECK_EQUAL(a.size(), size);
for(int i = 0; i < size; ++i) {
BOOST_CHECK_EQUAL( a[i], (i+1) * 10 );
}
}
+BOOST_AUTO_TEST_CASE( shuffle1023 ) {
+ const int size = 1023; // odd number of elements
+
+ std::vector<int> a;
+ for(int i = 0; i < size; ++i) {
+ a.push_back((i+1) * 10);
+ }
+
+ for(int n = 0; n < 100; ++n) {
+ std::random_shuffle(a.begin(), a.end());
+
+ timsort(a.begin(), a.end(), std::less<int>());
+
+ for(int i = 0; i < size; ++i) {
+ BOOST_CHECK_EQUAL( a[i], (i+1) * 10 );
+ }
+ }
+}
+
BOOST_AUTO_TEST_CASE( shuffle1024 ) {
- const int size = 1024;
+ const int size = 1024; // even number of elements
std::vector<int> a;
for(int i = 0; i < size; ++i) {
@@ -138,6 +203,44 @@ BOOST_AUTO_TEST_CASE( shuffle1024 ) {
}
}
+BOOST_AUTO_TEST_CASE( partial_shuffle1023 ) {
+ const int size = 1023;
+
+ std::vector<int> a;
+ for(int i = 0; i < size; ++i) {
+ a.push_back((i+1) * 10);
+ }
+
+ for(int n = 0; n < 100; ++n) {
+ std::random_shuffle(a.begin(), a.begin() + (size / 2));
+
+ timsort(a.begin(), a.end(), std::less<int>());
+
+ for(int i = 0; i < size; ++i) {
+ BOOST_CHECK_EQUAL( a[i], (i+1) * 10 );
+ }
+ }
+}
+
+BOOST_AUTO_TEST_CASE( partial_shuffle1024 ) {
+ const int size = 1024;
+
+ std::vector<int> a;
+ for(int i = 0; i < size; ++i) {
+ a.push_back((i+1) * 10);
+ }
+
+ for(int n = 0; n < 100; ++n) {
+ std::random_shuffle(a.begin(), a.begin() + (size / 2));
+
+ timsort(a.begin(), a.end(), std::less<int>());
+
+ for(int i = 0; i < size; ++i) {
+ BOOST_CHECK_EQUAL( a[i], (i+1) * 10 );
+ }
+ }
+}
+
BOOST_AUTO_TEST_CASE( shuffle1024r ) {
const int size = 1024;
@@ -158,6 +261,44 @@ BOOST_AUTO_TEST_CASE( shuffle1024r ) {
}
}
+BOOST_AUTO_TEST_CASE( partial_reversed1023 ) {
+ const int size = 1023;
+
+ std::vector<int> a;
+ for(int i = 0; i < size; ++i) {
+ a.push_back((i+1) * 10);
+ }
+
+ for(int n = 0; n < 100; ++n) {
+ std::reverse(a.begin(), a.begin() + (size / 2)); // partial reversed
+
+ timsort(a.begin(), a.end(), std::less<int>());
+
+ for(int i = 0; i < size; ++i) {
+ BOOST_CHECK_EQUAL( a[i], (i+1) * 10 );
+ }
+ }
+}
+
+BOOST_AUTO_TEST_CASE( partial_reversed1024 ) {
+ const int size = 1024;
+
+ std::vector<int> a;
+ for(int i = 0; i < size; ++i) {
+ a.push_back((i+1) * 10);
+ }
+
+ for(int n = 0; n < 100; ++n) {
+ std::reverse(a.begin(), a.begin() + (size / 2)); // partial reversed
+
+ timsort(a.begin(), a.end(), std::less<int>());
+
+ for(int i = 0; i < size; ++i) {
+ BOOST_CHECK_EQUAL( a[i], (i+1) * 10 );
+ }
+ }
+}
+
BOOST_AUTO_TEST_CASE( c_array ) {
int a[] = { 7, 1, 5, 3, 9 };
Please sign in to comment.
Something went wrong with that request. Please try again.