|
Boost-Commit : |
From: zeux_at_[hidden]
Date: 2007-06-02 13:00:54
Author: zeux
Date: 2007-06-02 13:00:52 EDT (Sat, 02 Jun 2007)
New Revision: 4419
URL: http://svn.boost.org/trac/boost/changeset/4419
Log:
Number ctors unit tests
Added:
sandbox/SOC/2007/bigint/libs/bigint/test/number_ctors.cpp
Text files modified:
sandbox/SOC/2007/bigint/libs/bigint/test/Jamfile.v2 | 7 ++++---
sandbox/SOC/2007/bigint/libs/bigint/test/bigint_simple_test.cpp | 2 ++
sandbox/SOC/2007/bigint/libs/bigint/todo.txt | 4 ++--
3 files changed, 8 insertions(+), 5 deletions(-)
Modified: sandbox/SOC/2007/bigint/libs/bigint/test/Jamfile.v2
==============================================================================
--- sandbox/SOC/2007/bigint/libs/bigint/test/Jamfile.v2 (original)
+++ sandbox/SOC/2007/bigint/libs/bigint/test/Jamfile.v2 2007-06-02 13:00:52 EDT (Sat, 02 Jun 2007)
@@ -7,9 +7,10 @@
import testing ;
{
- test-suite bigint:
- : [ run bigint_simple_test.cpp
- : : : : bigint_simple ]
+ test-suite bigint
+ :
+ [ run bigint_simple_test.cpp ]
+ [ run number_ctors.cpp ]
;
}
Modified: sandbox/SOC/2007/bigint/libs/bigint/test/bigint_simple_test.cpp
==============================================================================
--- sandbox/SOC/2007/bigint/libs/bigint/test/bigint_simple_test.cpp (original)
+++ sandbox/SOC/2007/bigint/libs/bigint/test/bigint_simple_test.cpp 2007-06-02 13:00:52 EDT (Sat, 02 Jun 2007)
@@ -7,6 +7,8 @@
* copy at http://www.boost.org/LICENSE_1_0.txt)
*/
+#define BOOST_DISABLE_WIN32
+
#include <boost/test/included/test_exec_monitor.hpp>
#include <boost/bigint/bigint.hpp>
Added: sandbox/SOC/2007/bigint/libs/bigint/test/number_ctors.cpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2007/bigint/libs/bigint/test/number_ctors.cpp 2007-06-02 13:00:52 EDT (Sat, 02 Jun 2007)
@@ -0,0 +1,144 @@
+/* Boost number_ctors.cpp test file
+ *
+ * Copyright 2007 Arseny Kapoulkine
+ *
+ * Distributed under the Boost Software License, Version 1.0.
+ * (See accompanying file LICENSE_1_0.txt or
+ * copy at http://www.boost.org/LICENSE_1_0.txt)
+ */
+
+#define BOOST_DISABLE_WIN32
+
+#include <boost/test/included/test_exec_monitor.hpp>
+
+#include <boost/bigint/bigint.hpp>
+
+#include <sstream>
+
+#include <iostream>
+
+#pragma comment(lib, "libgmp-3.lib")
+
+// This macro is not quite good, but - it's ok for our needs
+#define ARRAY_SIZE(array) sizeof(array) / sizeof(array[0])
+
+template <typename T> T convert_to_number(T value)
+{
+ return value;
+}
+
+int convert_to_number(char value)
+{
+ return value;
+}
+
+unsigned int convert_to_number(unsigned char value)
+{
+ return value;
+}
+
+template <typename I, typename T> void test_number_ctors(T* values, size_t count)
+{
+ typedef boost::bigint_base<I> number;
+
+ for (size_t i = 0; i < count; ++i)
+ {
+ std::ostringstream oss;
+ oss << convert_to_number(values[i]);
+
+ BOOST_CHECK_EQUAL(oss.str(), number(values[i]).str());
+ }
+}
+
+template <typename I> void test()
+{
+ {
+ char values[] = {-128, -127, -10, -1, 0, 1, 33, 124, 125, 126, 127};
+
+ test_number_ctors<I>(values, ARRAY_SIZE(values));
+ }
+
+ {
+ unsigned char values[] = {0, 1, 33, 124, 125, 126, 127, 200, 240, 254, 255};
+
+ test_number_ctors<I>(values, ARRAY_SIZE(values));
+ }
+
+ {
+ short values[] = {-32768, -32767, -23032, -3407, -10, -1, 0, 1, 33, 124, 125, 126, 127, 3489, 31900, 32766, 32767};
+
+ test_number_ctors<I>(values, ARRAY_SIZE(values));
+ }
+
+ {
+ unsigned short values[] = {0, 1, 33, 124, 125, 126, 127, 200, 240, 254, 255, 3000, 48950, 65534, 65535};
+
+ test_number_ctors<I>(values, ARRAY_SIZE(values));
+ }
+
+ {
+ int values[] = {-2147483647 - 1, -2147483647, -2147483646, -34294039, -3409, -1, 0, 1, 3940, 4950424, 2147483646, 2147483647};
+
+ test_number_ctors<I>(values, ARRAY_SIZE(values));
+ }
+
+ {
+ unsigned int values[] = {0, 1, 200, 65535, 384983, 23849384, 1203002930, 2147483648, 4294967294, 4294967295};
+
+ test_number_ctors<I>(values, ARRAY_SIZE(values));
+ }
+
+ {
+ boost::int64_t values[] = {-2147483647 - 1, -2147483647, -2147483646, -34294039, -3409, -1, 0, 1, 3940, 4950424, 2147483646, 2147483647};
+
+ // small values
+ test_number_ctors<I>(values, ARRAY_SIZE(values));
+
+ for (size_t i = 0; i < ARRAY_SIZE(values); ++i)
+ {
+ values[i] *= 2147483648; // 2^31
+ values[i] *= 2; // 2^32
+ }
+
+ // first element is -2^31 * 2^32 == -2^63 - ok
+ // last element is (2^31 - 1) * 2^32 == 2^63 - 2^32 - too small
+ values[ARRAY_SIZE(values) - 1] += 4294967295;
+
+ // testing unit tests
+ BOOST_CHECK(values[0] < 0 && values[0] - 1 > 0); // underflow
+ BOOST_CHECK(values[ARRAY_SIZE(values) - 1] > 0 && values[ARRAY_SIZE(values) - 1] + 1 < 0); // overflow
+ BOOST_CHECK_EQUAL(values[0] - 1, values[ARRAY_SIZE(values) - 1]);
+
+ // large values
+ test_number_ctors<I>(values, ARRAY_SIZE(values));
+ }
+
+ {
+ boost::uint64_t values[] = {0, 1, 200, 65535, 384983, 23849384, 1203002930, 2147483648, 4294967294, 4294967295};
+
+ // small values
+ test_number_ctors<I>(values, ARRAY_SIZE(values));
+
+ for (size_t i = 0; i < ARRAY_SIZE(values); ++i)
+ {
+ values[i] *= 2147483648; // 2^31
+ values[i] *= 2; // 2^32
+ }
+
+ // last element is (2^32 - 1) * 2^32 == 2^64 - 2^32 - too small
+ values[ARRAY_SIZE(values) - 1] += 4294967295;
+
+ // testing unit tests
+ BOOST_CHECK_EQUAL(values[ARRAY_SIZE(values) - 1] + 1, 0); // overflow
+
+ // large values
+ test_number_ctors<I>(values, ARRAY_SIZE(values));
+ }
+}
+
+int test_main( int argc, char* argv[] )
+{
+ test<boost::detail::bigint_gmp_implementation>();
+
+ return 0;
+}
Modified: sandbox/SOC/2007/bigint/libs/bigint/todo.txt
==============================================================================
--- sandbox/SOC/2007/bigint/libs/bigint/todo.txt (original)
+++ sandbox/SOC/2007/bigint/libs/bigint/todo.txt 2007-06-02 13:00:52 EDT (Sat, 02 Jun 2007)
@@ -93,8 +93,8 @@
3. Correctness tests
-- test all ctors for numbers
-Status: needs implementing
++ test all ctors for numbers
+Status: implemented
- test all ctors for strings (various bases - 2, 9, 18, 27, 36)
Status: needs implementing
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