]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/geometry/test/util/rational.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / geometry / test / util / rational.cpp
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2 // Unit Test
3
4 // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
5 // Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
6 // Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
7
8 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
9 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
10
11 // Use, modification and distribution is subject to the Boost Software License,
12 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
13 // http://www.boost.org/LICENSE_1_0.txt)
14
15
16 #include <geometry_test_common.hpp>
17
18 #include <boost/geometry/geometries/geometries.hpp>
19 #include <boost/geometry/io/wkt/wkt.hpp>
20 #include <boost/geometry/util/rational.hpp>
21
22 void test_coordinate_cast(std::string const& s, int expected_nom, int expected_denom)
23 {
24 boost::rational<int> a = bg::detail::coordinate_cast<boost::rational<int> >::apply(s);
25 BOOST_CHECK_EQUAL(a.numerator(), expected_nom);
26 BOOST_CHECK_EQUAL(a.denominator(), expected_denom);
27 }
28
29
30 void test_wkt(std::string const& wkt, std::string const expected_wkt)
31 {
32 bg::model::point<boost::rational<int>, 2, bg::cs::cartesian> p;
33 bg::read_wkt(wkt, p);
34 std::ostringstream out;
35 out << bg::wkt(p);
36
37 BOOST_CHECK_EQUAL(out.str(), expected_wkt);
38 }
39
40 int test_main(int, char* [])
41 {
42 test_coordinate_cast("0", 0, 1);
43 test_coordinate_cast("1", 1, 1);
44 test_coordinate_cast("-1", -1, 1);
45 test_coordinate_cast("-0.5", -1, 2);
46 test_coordinate_cast("-1.5", -3, 2);
47 test_coordinate_cast("0.5", 1, 2);
48 test_coordinate_cast("1.5", 3, 2);
49 test_coordinate_cast("2.12345", 42469, 20000);
50 test_coordinate_cast("1.", 1, 1);
51
52 test_coordinate_cast("3/2", 3, 2);
53 test_coordinate_cast("-3/2", -3, 2);
54
55 test_wkt("POINT(1.5 2.75)", "POINT(3/2 11/4)");
56 test_wkt("POINT(3/2 11/4)", "POINT(3/2 11/4)");
57 test_wkt("POINT(-1.5 2.75)", "POINT(-3/2 11/4)");
58 test_wkt("POINT(-3/2 11/4)", "POINT(-3/2 11/4)");
59
60 return 0;
61 }