phone_number: initial commit

This commit is contained in:
Dmitry Kokorin 2016-03-02 20:24:21 +03:00
parent 1e2dd2cf99
commit 86f77239eb
3 changed files with 162 additions and 0 deletions

View file

@ -0,0 +1,54 @@
#include "phone_number.h"
#define BOOST_TEST_MAIN
#include <boost/test/unit_test.hpp>
BOOST_AUTO_TEST_CASE(cleans_parens_dashes_and_spaces_from_the_number)
{
const phone_number phone("(123) 456-7890");
BOOST_REQUIRE_EQUAL("1234567890", phone.number());
}
#if defined(EXERCISM_RUN_ALL_TESTS)
BOOST_AUTO_TEST_CASE(cleans_numbers_with_dots)
{
const phone_number phone("123.456.7890");
BOOST_REQUIRE_EQUAL("1234567890", phone.number());
}
BOOST_AUTO_TEST_CASE(valid_when_11_digits_and_first_digit_is_1)
{
const phone_number phone("11234567890");
BOOST_REQUIRE_EQUAL("1234567890", phone.number());
}
BOOST_AUTO_TEST_CASE(invalid_when_11_digits)
{
const phone_number phone("21234567890");
BOOST_REQUIRE_EQUAL("0000000000", phone.number());
}
BOOST_AUTO_TEST_CASE(invalid_when_9_digits)
{
const phone_number phone("123456789");
BOOST_REQUIRE_EQUAL("0000000000", phone.number());
}
BOOST_AUTO_TEST_CASE(has_an_area_code)
{
const phone_number phone("1234567890");
BOOST_REQUIRE_EQUAL("123", phone.area_code());
}
BOOST_AUTO_TEST_CASE(formats_a_number)
{
const phone_number phone("1234567890");
BOOST_REQUIRE_EQUAL("(123) 456-7890", std::string(phone));
}
#endif