Add new algorithm boost::power, which raises a number to an integer power

This commit is contained in:
Marshall Clow
2014-12-02 14:38:25 -08:00
parent c5c927bf25
commit 0c3f9a38f4
3 changed files with 88 additions and 4 deletions

View File

@ -27,8 +27,9 @@ alias unit_test_framework
[ compile-fail search_fail2.cpp : : : : ]
[ compile-fail search_fail3.cpp : : : : ]
# Clamp tests
# Misc tests
[ run clamp_test.cpp unit_test_framework : : : : clamp_test ]
[ run power_test.cpp unit_test_framework : : : : power_test ]
# Cxx11 tests
[ run all_of_test.cpp unit_test_framework : : : : all_of_test ]
@ -58,9 +59,6 @@ alias unit_test_framework
[ run hex_test4.cpp unit_test_framework : : : : hex_test4 ]
[ compile-fail hex_fail1.cpp ]
# Wrapper tests
[ run wrapper_test1.cpp unit_test_framework : : : : wrapper_test1 ]
# Gather tests
[ run gather_test1.cpp unit_test_framework : : : : gather_test1 ]
[ compile-fail gather_fail1.cpp ]

36
test/power_test.cpp Normal file
View File

@ -0,0 +1,36 @@
/*
Copyright (c) Marshall Clow 2014.
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)
For more information, see http://www.boost.org
*/
#include <iostream>
#include <boost/config.hpp>
#include <boost/algorithm/algorithm.hpp>
#define BOOST_TEST_MAIN
#include <boost/test/unit_test.hpp>
#include <string>
#include <vector>
#include <list>
namespace ba = boost::algorithm;
BOOST_AUTO_TEST_CASE( test_main )
{
BOOST_CHECK ( ba::power(0, 0) == 1);
BOOST_CHECK ( ba::power(5, 0) == 1);
BOOST_CHECK ( ba::power(1, 1) == 1);
BOOST_CHECK ( ba::power(1, 4) == 1);
BOOST_CHECK ( ba::power(3, 2) == 9);
BOOST_CHECK ( ba::power(2, 3) == 8);
BOOST_CHECK ( ba::power(3, 3) == 27);
BOOST_CHECK ( ba::power(2, 30) == 0x40000000);
BOOST_CHECK ( ba::power(5L, 10) == 3125*3125);
BOOST_CHECK ( ba::power(18, 3) == 18*18*18);
}