1/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
2// test_complex.cpp
3
4// (C) Copyright 2005 Matthias Troyer .
5// Use, modification and distribution is subject to the Boost Software
6// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
7// http://www.boost.org/LICENSE_1_0.txt)
8
9// should pass compilation and execution
10
11#include <fstream>
12
13#include <cstddef> // NULL
14#include <cstdlib> // rand
15#include <cstdio> // remove
16#include <boost/config.hpp>
17#include <boost/detail/workaround.hpp>
18#if BOOST_CXX_VERSION > 199711L // only include floating point if C++ version >= C++11
19#include <boost/math/special_functions/next.hpp>
20#endif
21
22#if defined(BOOST_NO_STDC_NAMESPACE)
23#include <boost/limits.hpp>
24namespace std{
25 using ::rand;
26 using ::remove;
27 #if BOOST_WORKAROUND(BOOST_MSVC, >= 1400) && !defined(UNDER_CE)
28 using ::numeric_limits;
29 #endif
30}
31#endif
32
33#include "test_tools.hpp"
34
35#include <boost/preprocessor/stringize.hpp>
36#include BOOST_PP_STRINGIZE(BOOST_ARCHIVE_TEST)
37
38#include <boost/serialization/complex.hpp>
39
40#include <iostream>
41
42int test_main( int /* argc */, char* /* argv */[] )
43{
44 const char * testfile = boost::archive::tmpnam(NULL);
45 BOOST_REQUIRE(NULL != testfile);
46
47 // test array of objects
48 std::complex<float> a(
49 static_cast<float>(std::rand()) / static_cast<float>(std::rand()),
50 static_cast<float>(std::rand()) / static_cast<float>(std::rand())
51 );
52 std::complex<double> b(
53 static_cast<double>(std::rand()) / static_cast<double>(std::rand()),
54 static_cast<double>(std::rand()) / static_cast<double>(std::rand())
55 );
56 {
57 test_ostream os(testfile, TEST_STREAM_FLAGS);
58 test_oarchive oa(os);
59 oa << boost::serialization::make_nvp(n: "afloatcomplex", v&: a);
60 oa << boost::serialization::make_nvp(n: "adoublecomplex", v&: b);
61 }
62 std::complex<float> a1;
63 std::complex<double> b1;
64 {
65 test_istream is(testfile, TEST_STREAM_FLAGS);
66 test_iarchive ia(is);
67 ia >> boost::serialization::make_nvp(n: "afloatcomplex", v&: a1);
68 ia >> boost::serialization::make_nvp(n: "adoublecomplex", v&: b1);
69 }
70
71 #if BOOST_CXX_VERSION > 199711L // only include floating point if C++ version >= C++11
72 std::cerr << "a.real()-a1a.real() distance = " << std::abs( x: boost::math::float_distance(a: a.real(), b: a1.real())) << std::endl;
73 BOOST_CHECK(std::abs(boost::math::float_distance(a.real(), a1.real())) < 2);
74 std::cerr << "a.imag() - a1a.imag() distance = " << std::abs( x: boost::math::float_distance(a: a.imag(), b: a1.imag())) << std::endl;
75 BOOST_CHECK(std::abs(boost::math::float_distance(a.imag(), a1.imag())) < 2);
76 std::cerr << "b.real() - b1.real() distance = " << std::abs( x: boost::math::float_distance(a: b.real(), b: b1.real())) << std::endl;
77 BOOST_CHECK(std::abs(boost::math::float_distance(b.real(), b1.real())) < 2);
78 std::cerr << "b.imag() - b1.imag() distance = " << std::abs( x: boost::math::float_distance(a: b.imag(), b: b1.imag())) << std::endl;
79 BOOST_CHECK(std::abs(boost::math::float_distance(b.imag(), b1.imag())) < 2);
80 #endif
81
82 std::remove(filename: testfile);
83 return EXIT_SUCCESS;
84}
85
86// EOF
87

source code of boost/libs/serialization/test/test_complex.cpp