Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r64339 - sandbox/SOC/2010/bits_and_ints/libs/integer/test
From: muriloufg_at_[hidden]
Date: 2010-07-25 13:50:19


Author: murilov
Date: 2010-07-25 13:50:19 EDT (Sun, 25 Jul 2010)
New Revision: 64339
URL: http://svn.boost.org/trac/boost/changeset/64339

Log:
Added isqrt() functions wich calculate the saquare root of integers
Added:
   sandbox/SOC/2010/bits_and_ints/libs/integer/test/isqrt_test.cpp (contents, props changed)
Text files modified:
   sandbox/SOC/2010/bits_and_ints/libs/integer/test/Jamfile.v2 | 1 +
   sandbox/SOC/2010/bits_and_ints/libs/integer/test/ilog2_test.cpp | 9 +++++++--
   2 files changed, 8 insertions(+), 2 deletions(-)

Modified: sandbox/SOC/2010/bits_and_ints/libs/integer/test/Jamfile.v2
==============================================================================
--- sandbox/SOC/2010/bits_and_ints/libs/integer/test/Jamfile.v2 (original)
+++ sandbox/SOC/2010/bits_and_ints/libs/integer/test/Jamfile.v2 2010-07-25 13:50:19 EDT (Sun, 25 Jul 2010)
@@ -29,6 +29,7 @@
                 [ run count_leading_zeros_test.cpp ]
                 [ run ilog2_test.cpp ]
                 [ run inc_rev_test.cpp ]
+ [ run isqrt_test.cpp ]
                 [ compile cstdint_include_test.cpp ]
                 [ compile integer_traits_include_test.cpp ]
                 [ compile integer_include_test.cpp ]

Modified: sandbox/SOC/2010/bits_and_ints/libs/integer/test/ilog2_test.cpp
==============================================================================
--- sandbox/SOC/2010/bits_and_ints/libs/integer/test/ilog2_test.cpp (original)
+++ sandbox/SOC/2010/bits_and_ints/libs/integer/test/ilog2_test.cpp 2010-07-25 13:50:19 EDT (Sun, 25 Jul 2010)
@@ -5,14 +5,14 @@
 // accompanying file LICENSE_1_0.txt or copy at
 // http://www.boost.org/LICENSE_1_0.txt
 
+#include <limits>
 #include <boost/detail/lightweight_test.hpp>
 #include <boost/integer/ilog2.hpp>
 #include <boost/cstdint.hpp>
 #include <iostream>
 
 #define ILOG2_TEST(x, y) \
-BOOST_TEST((::boost::ilog2(x) == y)); \
-std::cout << "deu " << ::boost::ilog2(x) << " era pra ser " << y << std::endl
+BOOST_TEST((::boost::ilog2(x) == y))
 
 // Main testing function
 int main(int, char* [])
@@ -20,6 +20,11 @@
         using namespace boost;
         std::cout << "Doing tests on ilog2 function." << std::endl;
         
+ ILOG2_TEST((unsigned)0, -1);
+ ILOG2_TEST((unsigned)1, 0);
+ ILOG2_TEST((unsigned)0xFFFFFFFF, 31);
+ ILOG2_TEST((unsigned)0xF0000000, 31);
+ ILOG2_TEST((unsigned)0x80000000, 31);
         ILOG2_TEST((unsigned)100, 6);
         ILOG2_TEST((unsigned)265, 8);
         ILOG2_TEST((unsigned)158741, 17);

Added: sandbox/SOC/2010/bits_and_ints/libs/integer/test/isqrt_test.cpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2010/bits_and_ints/libs/integer/test/isqrt_test.cpp 2010-07-25 13:50:19 EDT (Sun, 25 Jul 2010)
@@ -0,0 +1,55 @@
+// Boost count_leading_zeros_test.hpp test program --------------------------------------//
+
+// (C) Copyright Murilo Adriano Vasconcelos 2010.
+// 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
+
+
+#include <iostream>
+#include <cmath>
+#include <limits>
+#include <boost/cstdint.hpp>
+#include <boost/detail/lightweight_test.hpp>
+#include <boost/integer/isqrt.hpp>
+
+
+
+int main()
+{
+
+ for (uint8_t i = 0; i < 255; ++i) {
+ BOOST_TEST((boost::isqrt(i) == int(sqrt(i))));
+ }
+
+ for (uint16_t i = 0x0; i < 0xFF; ++i) {
+ BOOST_TEST((boost::isqrt(i) == int(sqrt(i))));
+ }
+
+ for (uint16_t i = 0x0FFF; i < 0xFFFF; ++i) {
+ BOOST_TEST((boost::isqrt(i) == int(sqrt(i))));
+ }
+
+ for (uint32_t i = 0x0; i < 0xFF; ++i) {
+ BOOST_TEST((boost::isqrt(i) == int(sqrt(i))));
+ }
+
+ for (uint32_t i = 0xFFFF; i < 0xFFFFF; ++i) {
+ BOOST_TEST((boost::isqrt(i) == int(sqrt(i))));
+ }
+
+ BOOST_TEST((boost::isqrt(unsigned(0)) == int(sqrt(0))));
+ BOOST_TEST((boost::isqrt(unsigned(1)) == int(sqrt(1))));
+ BOOST_TEST((boost::isqrt(unsigned(2)) == int(sqrt(2))));
+ BOOST_TEST((boost::isqrt(unsigned(3)) == int(sqrt(3))));
+ BOOST_TEST((boost::isqrt(std::numeric_limits<uint8_t>::max())
+ == int(sqrt(std::numeric_limits<uint8_t>::max()))));
+
+ BOOST_TEST((boost::isqrt(std::numeric_limits<uint16_t>::max())
+ == int(sqrt(std::numeric_limits<uint16_t>::max()))));
+
+ BOOST_TEST((boost::isqrt(std::numeric_limits<uint32_t>::max())
+ == int(sqrt(std::numeric_limits<uint32_t>::max()))));
+
+ return boost::report_errors();
+}


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