|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r53972 - in sandbox/monotonic: boost/monotonic libs/monotonic/test
From: christian.schladetsch_at_[hidden]
Date: 2009-06-16 03:04:13
Author: cschladetsch
Date: 2009-06-16 03:04:11 EDT (Tue, 16 Jun 2009)
New Revision: 53972
URL: http://svn.boost.org/trac/boost/changeset/53972
Log:
moving over to use Boost.Test
Added:
sandbox/monotonic/libs/monotonic/test/basic_tests.cpp (contents, props changed)
Text files modified:
sandbox/monotonic/boost/monotonic/allocator.h | 8 ++
sandbox/monotonic/boost/monotonic/fixed_storage.h | 1
sandbox/monotonic/boost/monotonic/storage.h | 1
sandbox/monotonic/libs/monotonic/test/main.cpp | 136 +++------------------------------------
sandbox/monotonic/libs/monotonic/test/monotonic.vcproj | 12 +++
sandbox/monotonic/libs/monotonic/test/rope.cpp | 6
sandbox/monotonic/libs/monotonic/test/test_bubble_sort.cpp | 3
sandbox/monotonic/libs/monotonic/test/test_chained_storage.cpp | 2
sandbox/monotonic/libs/monotonic/test/test_map_list.cpp | 13 ---
9 files changed, 37 insertions(+), 145 deletions(-)
Modified: sandbox/monotonic/boost/monotonic/allocator.h
==============================================================================
--- sandbox/monotonic/boost/monotonic/allocator.h (original)
+++ sandbox/monotonic/boost/monotonic/allocator.h 2009-06-16 03:04:11 EDT (Tue, 16 Jun 2009)
@@ -55,6 +55,7 @@
typedef allocator<U> other;
};
+ private:
/// the storage used by the allocator
storage_base *storage;
@@ -79,7 +80,7 @@
{
typedef BOOST_DEDUCED_TYPENAME allocator<T>::template rebind<U> Other;
typedef BOOST_DEDUCED_TYPENAME Other::other OtherStorage;
- storage = OtherStorage(*Q.storage).storage;
+ storage = OtherStorage(*Q.get_storage()).get_storage();
}
~allocator() throw()
@@ -148,6 +149,11 @@
std::swap(storage, other.storage);
}
+ storage_base *get_storage() const
+ {
+ return storage;
+ }
+
friend bool operator==(allocator<T> const &A, allocator<T> const &B) { return A.storage == B.storage; }
friend bool operator!=(allocator<T> const &A, allocator<T> const &B) { return A.storage != B.storage; }
};
Modified: sandbox/monotonic/boost/monotonic/fixed_storage.h
==============================================================================
--- sandbox/monotonic/boost/monotonic/fixed_storage.h (original)
+++ sandbox/monotonic/boost/monotonic/fixed_storage.h 2009-06-16 03:04:11 EDT (Tue, 16 Jun 2009)
@@ -26,7 +26,6 @@
template <size_t N>
struct fixed_storage : storage_base
{
- BOOST_STATIC_ASSERT(N > 0);
typedef boost::array<char, N> Buffer;
private:
Modified: sandbox/monotonic/boost/monotonic/storage.h
==============================================================================
--- sandbox/monotonic/boost/monotonic/storage.h (original)
+++ sandbox/monotonic/boost/monotonic/storage.h 2009-06-16 03:04:11 EDT (Tue, 16 Jun 2009)
@@ -7,6 +7,7 @@
#include <utility>
#include <limits>
+#include <vector>
#include <boost/monotonic/fixed_storage.h>
#include <boost/foreach.hpp>
Added: sandbox/monotonic/libs/monotonic/test/basic_tests.cpp
==============================================================================
--- (empty file)
+++ sandbox/monotonic/libs/monotonic/test/basic_tests.cpp 2009-06-16 03:04:11 EDT (Tue, 16 Jun 2009)
@@ -0,0 +1,145 @@
+#define BOOST_TEST_DYN_LINK
+#define BOOST_TEST_MAIN
+
+#include <boost/monotonic/allocator.h>
+#include <string>
+#include <vector>
+#include <set>
+#include <map>
+
+#define BOOST_TEST_MODULE basic_test test
+#include <boost/test/unit_test.hpp>
+
+using namespace std;
+using namespace boost;
+
+BOOST_AUTO_TEST_CASE(test_splice)
+{
+ monotonic::storage<> store1;
+ std::list<int, monotonic::allocator<int> > list1(store1);
+ {
+ monotonic::storage<> store2;
+ std::list<int, monotonic::allocator<int> > list2(store2);
+ list2.push_back(1);
+ list1.splice(list1.begin(), list2);
+ }
+ BOOST_CHECK_EQUAL(*list1.begin(), 1);
+}
+
+BOOST_AUTO_TEST_CASE(test_ctors)
+{
+ monotonic::storage<> storage;
+ string foo = "foo";
+ vector<char, monotonic::allocator<char> > v1(foo.begin(), foo.end(), storage);
+ BOOST_CHECK(v1.size() == 3);
+ BOOST_CHECK(equal(v1.begin(), v1.end(), "foo"));
+
+ vector<char, monotonic::allocator<char> > v2(6, 'x', storage);
+ BOOST_CHECK(v2.size() == 6);
+ BOOST_CHECK(equal(v2.begin(), v2.end(), "xxxxxx"));
+
+ set<char, less<char>, monotonic::allocator<char> > s2(foo.begin(), foo.end(), less<char>(), storage);
+ BOOST_CHECK(s2.size() == 2);
+ BOOST_CHECK(s2.find('f') != s2.end());
+ BOOST_CHECK(s2.find('o') != s2.end());
+
+ vector<pair<int, string>, monotonic::allocator<pair<int, string> > > v(storage);
+ v.push_back(make_pair(42,"foo"));
+ v.push_back(make_pair(123,"bar"));
+
+ map<int, string, less<int>, monotonic::allocator<int> > m1(v.begin(), v.end(), less<int>(), storage);
+ BOOST_CHECK(m1.find(42) != m1.end());
+ BOOST_CHECK(m1.find(123) != m1.end());
+
+ list<int, monotonic::allocator<int> > l1(foo.begin(), foo.end(), storage);
+ BOOST_CHECK(equal(l1.begin(), l1.end(), "foo"));
+}
+
+BOOST_AUTO_TEST_CASE( test_copy )
+{
+ monotonic::storage<> storage;
+ std::vector<int, monotonic::allocator<int> > v1(storage);
+
+ for (int n = 0; n < 100; ++n)
+ v1.push_back(n);
+
+ size_t rem1 = storage.fixed_remaining();
+ std::vector<int, monotonic::allocator<int> > v2(v1);
+ size_t rem2 = storage.fixed_remaining();
+
+ BOOST_CHECK(v2 == v1);
+ BOOST_CHECK_EQUAL(rem1 - rem2, 12 + 100*sizeof(int));
+}
+
+BOOST_AUTO_TEST_CASE(test_shared_allocators)
+{
+ monotonic::storage<> sa, sb;
+ typedef monotonic::allocator<int> Al;
+ {
+ std::vector<int, Al> v0(sa), v1(sa);
+ std::vector<int, Al> v2(sb), v3(sb);
+ std::list<int, Al> l0(sa), l1(sb);
+
+ BOOST_CHECK(v0.get_allocator() == v1.get_allocator());
+ BOOST_CHECK(v2.get_allocator() == v3.get_allocator());
+ BOOST_CHECK(v0.get_allocator() != v2.get_allocator());
+ BOOST_CHECK(v3.get_allocator() != v1.get_allocator());
+
+ for (int n = 0; n < 10; ++n)
+ v0.push_back(n);
+
+ v1 = v0;
+ v1.swap(v2); // swap from different allocators means they are copied
+ BOOST_CHECK(v1.empty() && v3.empty() && v1 == v3);
+
+ BOOST_CHECK(v2 == v0); // both are now [0..9]
+
+ v1.swap(v0); // swap from same allocators means no copying
+ BOOST_CHECK(v2 == v1);
+ BOOST_CHECK(v0 == v3);
+
+ l0.assign(v0.begin(), v0.end());
+ l1 = l0;
+ BOOST_CHECK(l0 == l1);
+ }
+}
+
+BOOST_AUTO_TEST_CASE(test_basic)
+{
+ monotonic::storage<> storage1;
+ vector<int, monotonic::allocator<int> > v1(storage1);
+
+ for(int i = 0; i < 100; ++i)
+ v1.push_back(i);
+
+ size_t len = storage1.fixed_remaining();
+ vector<int, monotonic::allocator<int> > copy(v1);
+ size_t len2 = storage1.fixed_remaining();
+
+ BOOST_CHECK(copy == v1);
+ BOOST_CHECK(len - len2 == 12 + 100*sizeof(int)); // 12 has no right being there, it is for the extra gunk in vector and is STL-impl-dependant
+
+
+ // create the storage that will be used for the various monotonic containers.
+ // while it is on the stack here, it could be on the heap as well.
+ monotonic::storage<> storage;
+
+ // create a list that uses inline, monotonically-increasing storage
+ list<int, monotonic::allocator<int> > list(storage);
+ list.push_back(100);
+ list.push_back(400);
+ list.erase(list.begin());
+
+ // a map from the same storage
+ map<int, float, less<int>, monotonic::allocator<int> > map(less<int>(), storage);
+ map[42] = 3.14f;
+ BOOST_CHECK(map[42] == 3.14f);
+
+ // a set...
+ set<float, less<float>, monotonic::allocator<float> > set(less<float>(), storage);
+ set.insert(3.14f);
+ set.insert(-123.f);
+ BOOST_CHECK(set.size() == 2);
+}
+
+//EOF
Modified: sandbox/monotonic/libs/monotonic/test/main.cpp
==============================================================================
--- sandbox/monotonic/libs/monotonic/test/main.cpp (original)
+++ sandbox/monotonic/libs/monotonic/test/main.cpp 2009-06-16 03:04:11 EDT (Tue, 16 Jun 2009)
@@ -79,87 +79,6 @@
}
}
-void test_basic()
-{
- monotonic::storage<1000*sizeof(int)> storage1;
- monotonic::vector<int> v1(storage1);
-
- for(int i = 0; i < 100; ++i)
- v1.push_back(i);
-
- size_t len = storage1.remaining();
- monotonic::vector<int> copy(v1);
- size_t len2 = storage1.remaining();
-
- assert(copy == v1);
- assert(len - len2 == 100*sizeof(int));
-
-
- // create the storage that will be used for the various monotonic containers.
- // while it is on the stack here, it could be on the heap as well.
- monotonic::storage<1000> storage;
-
- // create a list that uses inline, monotonically-increasing storage
- monotonic::list<int> list(storage);
- list.push_back(100);
- list.push_back(400);
- list.erase(list.begin());
-
- // a map from the same storage
- monotonic::map<int, float> map(storage);
- map[42] = 3.14f;
- assert(map[42] == 3.14f);
-
- // a set...
- monotonic::set<float> set(storage);
- set.insert(3.14f);
- set.insert(-123.f);
-}
-
-void test_copy()
-{
- monotonic::storage<1000*sizeof(int)> storage;
- monotonic::vector<int> v1(storage);
-
- for (int n = 0; n < 100; ++n)
- v1.push_back(n);
-
- size_t rem1 = storage.remaining();
- monotonic::vector<int> v2(v1);
- size_t rem2 = storage.remaining();
-
- assert(v2 == v1);
- assert(rem1 - rem2 == 100*sizeof(int));
-}
-
-void test_ctors()
-{
- monotonic::storage<1000*sizeof(int)> storage;
- string foo = "foo";
- monotonic::vector<char> v1(foo.begin(), foo.end(), storage);
- assert(v1.size() == 3);
- assert(equal(v1.begin(), v1.end(), "foo"));
-
- monotonic::vector<char> v2(6, 'x', storage);
- assert(v2.size() == 6);
- assert(equal(v2.begin(), v2.end(), "xxxxxx"));
-
- monotonic::set<char> s2(foo.begin(), foo.end(), storage);
- assert(s2.size() == 2);
- assert(s2.find('f') != s2.end());
- assert(s2.find('o') != s2.end());
-
- vector<pair<int, string> > v;
- v.push_back(make_pair(42,"foo"));
- v.push_back(make_pair(123,"bar"));
- monotonic::map<int, string> m1(v.begin(), v.end(), storage);
- assert(m1.find(42) != m1.end());
- assert(m1.find(123) != m1.end());
-
- monotonic::list<int> l1(foo.begin(), foo.end(), storage);
- assert(equal(l1.begin(), l1.end(), "foo"));
-}
-
void test_speed()
{
typedef monotonic::map<int, monotonic::list<int> > map_with_list;
@@ -346,7 +265,6 @@
}
-#include "test_map_list.cpp"
template <class T>
pair<boost::counting_iterator<T>, boost::counting_iterator<T> > range(T start, T end)
@@ -356,66 +274,34 @@
}
-void test_shared_allocators()
-{
- monotonic::storage<500> sa, sb;
- typedef monotonic::allocator<int> Al;
- {
- std::vector<int, Al> v0(sa), v1(sa);
- std::vector<int, Al> v2(sb), v3(sb);
- std::list<int, Al> l0(sa), l1(sb);
-
- assert(v0.get_allocator() == v1.get_allocator());
- assert(v2.get_allocator() == v3.get_allocator());
- assert(v0.get_allocator() != v2.get_allocator());
- assert(v3.get_allocator() != v1.get_allocator());
-
- for (int n = 0; n < 10; ++n)
- v0.push_back(n);
-
- v1 = v0;
- v1.swap(v2); // swap from different allocators means they are copied
- assert(v1.empty() && v3.empty() && v1 == v3);
-
- assert(v2 == v0); // both are now [0..9]
-
- v1.swap(v0); // swap from same allocators means no copying
- assert(v2 == v1);
- assert(v0 == v3);
-
- l0.assign(v0.begin(), v0.end());
- l1 = l0;
- assert(l0 == l1);
- }
-}
-
void test_chain();
void test_chain();
+#include "test_map_list.cpp"
#include "test_bubble_sort.cpp"
#include "test_dupe.cpp"
#include "test_chained_storage.cpp"
#include "test_shared_storage.cpp"
-int main()
+void run_all_tests()
{
test_shared_storage();
test_chained_storage();
test_map_list_heap_stack();
test_dupe();
- //graph_bubble_sort();
- //test_bubble_sort();
- return 0;
- //test_chain();
+ graph_bubble_sort();
+ test_bubble_sort();
+ test_chain();
test_deque();
- //test_chain();
- test_shared_allocators();
test_alignment();
test_speed();
test_speed_heap();
- test_basic();
- test_copy();
- test_ctors();
}
+//int main()
+//{
+// //test_map_list_heap_stack();
+// run_all_tests();
+//}
+
//EOF
Modified: sandbox/monotonic/libs/monotonic/test/monotonic.vcproj
==============================================================================
--- sandbox/monotonic/libs/monotonic/test/monotonic.vcproj (original)
+++ sandbox/monotonic/libs/monotonic/test/monotonic.vcproj 2009-06-16 03:04:11 EDT (Tue, 16 Jun 2009)
@@ -243,6 +243,18 @@
>
</File>
</Filter>
+ <Filter
+ Name="test"
+ >
+ <File
+ RelativePath=".\Jamfile.v2"
+ >
+ </File>
+ </Filter>
+ <File
+ RelativePath=".\basic_tests.cpp"
+ >
+ </File>
<File
RelativePath=".\chain.cpp"
>
Modified: sandbox/monotonic/libs/monotonic/test/rope.cpp
==============================================================================
--- sandbox/monotonic/libs/monotonic/test/rope.cpp (original)
+++ sandbox/monotonic/libs/monotonic/test/rope.cpp 2009-06-16 03:04:11 EDT (Tue, 16 Jun 2009)
@@ -44,10 +44,10 @@
Foo(int N) : n(N) { }
};
-void test_rope()
+void test_chain()
{
{
- monotonic::fixed_storage<4000> storage; // create local storage on the stack
+ monotonic::storage<> storage;
{
monotonic::chain<int, 100> rope(storage);
for (int n = 0; n < 200; ++n)
@@ -58,7 +58,7 @@
}
- monotonic::fixed_storage<1000> storage;
+ monotonic::storage<> storage;
{
typedef monotonic::chain<Foo, 2> Rope2;
Rope2 foo(4, storage);
Modified: sandbox/monotonic/libs/monotonic/test/test_bubble_sort.cpp
==============================================================================
--- sandbox/monotonic/libs/monotonic/test/test_bubble_sort.cpp (original)
+++ sandbox/monotonic/libs/monotonic/test/test_bubble_sort.cpp 2009-06-16 03:04:11 EDT (Tue, 16 Jun 2009)
@@ -18,7 +18,6 @@
std::swap(*A, *C);
swapped = true;
}
-
}
}
while (swapped);
@@ -26,7 +25,7 @@
pair<double,double> test_bubble_sort(size_t count = 50*1000, size_t length = 20)
{
- monotonic::fixed_storage<100000> storage;// = new monotonic::storage<100000>();
+ monotonic::storage<> storage;
boost::timer mono_timer;
for (size_t n = 0; n < count; ++n)
{
Modified: sandbox/monotonic/libs/monotonic/test/test_chained_storage.cpp
==============================================================================
--- sandbox/monotonic/libs/monotonic/test/test_chained_storage.cpp (original)
+++ sandbox/monotonic/libs/monotonic/test/test_chained_storage.cpp 2009-06-16 03:04:11 EDT (Tue, 16 Jun 2009)
@@ -3,7 +3,7 @@
void test_chained_storage()
{
- monotonic::storage<10> store;
+ monotonic::storage<0> store;
{
typedef std::vector<char, monotonic::allocator<char> > Vector;
Vector vec(store);
Modified: sandbox/monotonic/libs/monotonic/test/test_map_list.cpp
==============================================================================
--- sandbox/monotonic/libs/monotonic/test/test_map_list.cpp (original)
+++ sandbox/monotonic/libs/monotonic/test/test_map_list.cpp 2009-06-16 03:04:11 EDT (Tue, 16 Jun 2009)
@@ -51,7 +51,7 @@
const size_t outter_loops = 10*1000;
const size_t inner_loops = 10000;
- monotonic::storage<1000000> storage;
+ monotonic::storage<> storage;
typedef std::map<size_t, pair<double, double> > Results;
Results results;
@@ -69,17 +69,6 @@
cout << result.first << '\t' << mono_time << '\t' << std_time << '\t' << perc << "%" << endl;
}
- //cout << "stack:" << endl;
- //{
- // test_map_list(outter_loops, inner_loops, storage);
- //}
-
- //cout << "heap:" << endl;
- //{
- // monotonic::storage<1000000> *storage = new monotonic::storage<1000000>;
- // test_map_list(outter_loops, inner_loops, *storage);
- // delete storage;
- //}
}
//EOF
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk