Branch data Line data Source code
1 : : /*
2 : : * Copyright 2010 Savarese Software Research Corporation
3 : : *
4 : : * Licensed under the Apache License, Version 2.0 (the "License");
5 : : * you may not use this file except in compliance with the License.
6 : : * You may obtain a copy of the License at
7 : : *
8 : : * https://www.savarese.com/software/ApacheLicense-2.0
9 : : *
10 : : * Unless required by applicable law or agreed to in writing, software
11 : : * distributed under the License is distributed on an "AS IS" BASIS,
12 : : * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 : : * See the License for the specific language governing permissions and
14 : : * limitations under the License.
15 : : */
16 : : #include <iostream>
17 : : #include <ssrc/spatial/distance.h>
18 : :
19 : : #include <array>
20 : :
21 : : #define BOOST_TEST_MODULE DistanceTest
22 : : #include <boost/test/unit_test.hpp>
23 : : #include <boost/mpl/list.hpp>
24 : :
25 : : using namespace ssrc::spatial;
26 : :
27 : : typedef boost::mpl::list<unsigned int, int, double> coordinate_types;
28 : :
29 [ + - ]: 4 : BOOST_AUTO_TEST_CASE_TEMPLATE(test_d2_0, coordinate_type, coordinate_types) {
30 : : typedef NS_TR1::array<coordinate_type, 1> Point;
31 : :
32 [ + - ][ - + ]: 3 : BOOST_REQUIRE_EQUAL(euclidean_distance<Point>::d2(Point{{1}}, Point{{1}}), 0);
[ + - ][ - + ]
[ + - ][ - + ]
33 [ + - ][ - + ]: 3 : BOOST_REQUIRE_EQUAL(euclidean_distance<Point>::d2(Point{{1}}, Point{{2}}), 1);
[ + - ][ - + ]
[ + - ][ - + ]
34 [ + - ][ - + ]: 3 : BOOST_REQUIRE_EQUAL(euclidean_distance<Point>::d2(Point{{48}},
[ + - ][ - + ]
[ + - ][ - + ]
35 : : Point{{52}}), 16);
36 [ + - ][ - + ]: 3 : BOOST_REQUIRE_EQUAL(euclidean_distance<Point>::d2(Point{{4}},
[ + - ][ - + ]
[ + - ][ - + ]
37 : : Point{{1}}), 9);
38 : 3 : }
39 : :
40 [ + - ]: 4 : BOOST_AUTO_TEST_CASE_TEMPLATE(test_d2_1, coordinate_type, coordinate_types) {
41 : : typedef NS_TR1::array<coordinate_type, 2> Point;
42 : :
43 [ + - ][ - + ]: 3 : BOOST_REQUIRE_EQUAL(euclidean_distance<Point>::d2(Point{{1,1}},
[ + - ][ - + ]
[ + - ][ - + ]
44 : : Point{{1,1}}), 0);
45 [ + - ][ - + ]: 3 : BOOST_REQUIRE_EQUAL(euclidean_distance<Point>::d2(Point{{1,1}},
[ + - ][ - + ]
[ + - ][ - + ]
46 : : Point{{2,2}}), 2);
47 [ + - ][ - + ]: 3 : BOOST_REQUIRE_EQUAL(euclidean_distance<Point>::d2(Point{{83,9451}},
[ + - ][ - + ]
[ + - ][ - + ]
48 : : Point{{4382,2383}}),
49 : : 68438025);
50 : 3 : }
51 : :
52 [ + - ]: 4 : BOOST_AUTO_TEST_CASE_TEMPLATE(test_d2_2, coordinate_type, coordinate_types) {
53 : : typedef NS_TR1::array<coordinate_type, 3> Point;
54 : :
55 [ + - ][ - + ]: 3 : BOOST_REQUIRE_EQUAL(euclidean_distance<Point>::d2(Point{{1,1,1}},
[ + - ][ - + ]
[ + - ][ - + ]
56 : : Point{{1,1,1}}), 0);
57 [ + - ][ - + ]: 3 : BOOST_REQUIRE_EQUAL(euclidean_distance<Point>::d2(Point{{1,1,1}},
[ + - ][ - + ]
[ + - ][ - + ]
58 : : Point{{2,2,2}}), 3);
59 [ + - ][ - + ]: 3 : BOOST_REQUIRE_EQUAL(euclidean_distance<Point>::d2(Point{{9,0,4}},
[ + - ][ - + ]
[ + - ][ - + ]
60 : : Point{{100,32,0}}), 9321);
61 : 3 : }
62 : :
63 [ + - ][ - + ]: 4 : BOOST_AUTO_TEST_CASE_TEMPLATE(test_d2_4, coordinate_type, coordinate_types) {
[ # # ]
64 : : typedef NS_TR1::array<coordinate_type, 4> Point;
65 : :
66 [ + - ][ - + ]: 3 : BOOST_REQUIRE_EQUAL(euclidean_distance<Point>::d2(Point{{1,1,1,1}},
[ + - ][ - + ]
[ + - ][ - + ]
67 : : Point{{1,1,1,1}}), 0);
68 [ + - ][ - + ]: 3 : BOOST_REQUIRE_EQUAL(euclidean_distance<Point>::d2(Point{{1,1,1,1}},
[ + - ][ - + ]
[ + - ][ - + ]
69 : : Point{{2,2,2,2}}), 4);
70 [ + - ][ + - ]: 6 : }
|