b2/core/test/generating/std_complex.cpp
2025-01-14 01:15:53 +01:00

103 lines
2.8 KiB
C++

//This file is part of Bertini 2.
//
//test/generating/double.cpp is free software: you can redistribute it and/or modify
//it under the terms of the GNU General Public License as published by
//the Free Software Foundation, either version 3 of the License, or
//(at your option) any later version.
//
//test/generating/double.cpp is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//GNU General Public License for more details.
//
//You should have received a copy of the GNU General Public License
//along with test/generating/double.cpp. If not, see <http://www.gnu.org/licenses/>.
//
// Copyright(C) 2015 - 2017 by Bertini2 Development Team
//
// See <http://www.gnu.org/licenses/> for a copy of the license,
// as well as COPYING. Bertini2 is provided with permitted
// additional terms in the b2/licenses/ directory.
/**
\file test/generating/double.cpp Tests the generating of text from double's.
*/
#include "bertini2/io/generators.hpp"
#include "bertini2/io/parsing/number_parsers.hpp"
#include <boost/test/unit_test.hpp>
BOOST_AUTO_TEST_SUITE(complex_double_generation)
BOOST_AUTO_TEST_CASE(zero)
{
bertini::DefaultPrecision(30);
std::complex<double> z(0,0);
std::string result;
std::back_insert_iterator<std::string> sink(result);
BOOST_CHECK(bertini::generators::Classic::generate(sink, z));
std::complex<double> rt;
BOOST_CHECK(bertini::parsing::classic::parse(result.begin(), result.end(), rt));
BOOST_CHECK_EQUAL(rt,z);
}
BOOST_AUTO_TEST_CASE(one)
{
bertini::DefaultPrecision(30);
std::complex<double> z(1,1);
std::string result;
std::back_insert_iterator<std::string> sink(result);
BOOST_CHECK(bertini::generators::Classic::generate(sink, z));
std::complex<double> rt;
BOOST_CHECK(bertini::parsing::classic::parse(result.begin(), result.end(), rt));
BOOST_CHECK_EQUAL(rt,z);
}
BOOST_AUTO_TEST_CASE(sqrt_2)
{
bertini::DefaultPrecision(30);
std::complex<double> z(sqrt(2),sqrt(3));
std::string result;
std::back_insert_iterator<std::string> sink(result);
BOOST_CHECK(bertini::generators::Classic::generate(sink, z));
std::complex<double> rt;
BOOST_CHECK(bertini::parsing::classic::parse(result.begin(), result.end(), rt));
BOOST_CHECK_EQUAL(rt,z);
}
BOOST_AUTO_TEST_CASE(check_135_477005)
{
bertini::DefaultPrecision(30);
std::complex<double> z(135.477005,135.477005234989817410289);
std::string result;
std::back_insert_iterator<std::string> sink(result);
BOOST_CHECK(bertini::generators::Classic::generate(sink, z));
std::complex<double> rt;
BOOST_CHECK(bertini::parsing::classic::parse(result.begin(), result.end(), rt));
BOOST_CHECK_EQUAL(rt,z);
}
BOOST_AUTO_TEST_SUITE_END()