1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
|
/*
* (C) Copyright 1996- ECMWF.
*
* This software is licensed under the terms of the Apache Licence Version 2.0
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
*
* In applying this licence, ECMWF does not waive the privileges and immunities
* granted to it by virtue of its status as an intergovernmental organisation nor
* does it submit to any jurisdiction.
*/
#include <cmath>
#include "eckit/geo/PointXYZ.h"
#include "eckit/testing/Test.h"
#include "eckit/types/FloatCompare.h"
namespace eckit::geo::test {
CASE("PointXYZ initialisation") {
PointXYZ z;
EXPECT(z.X() == 0.);
EXPECT(z.Y() == 0.);
EXPECT(z.Z() == 0.);
PointXYZ p = {1., 2., 3.};
PointXYZ s(p);
EXPECT(s.X() == 1.);
EXPECT(s.Y() == 2.);
EXPECT(s.Z() == 3.);
}
CASE("PointXYZ addition") {
PointXYZ p1 = {1., 2., 3.};
PointXYZ p2{1., 2., 3.};
PointXYZ r = p1 + p2;
EXPECT(r.X() == 2.);
EXPECT(r.Y() == 4.);
EXPECT(r.Z() == 6.);
}
CASE("PointXYZ subtraction") {
PointXYZ p1{2., 5., 7.};
PointXYZ p2{1., 2., 3.};
PointXYZ r = p1 - p2;
EXPECT(r.X() == 1.);
EXPECT(r.Y() == 3.);
EXPECT(r.Z() == 4.);
}
CASE("PointXYZ scaling") {
PointXYZ p1{1., 2., 3.};
PointXYZ r = p1 * 42.;
EXPECT(r.X() == 42.);
EXPECT(r.Y() == 84.);
EXPECT(r.Z() == 126.);
}
CASE("PointXYZ equality") {
PointXYZ p1{1., 2., 3.};
PointXYZ p2{1., 2., 3.};
EXPECT(p1 == p2);
}
CASE("PointXYZ inequality") {
PointXYZ p1{1., 2., 3.};
PointXYZ p2{1., 2., 4.};
EXPECT(p1 != p2);
}
CASE("PointXYZ distance comparison") {
PointXYZ p1{2., 1., 0.};
PointXYZ p2{1., 2., 4.};
PointXYZ p3{5., 5., 5.};
EXPECT(types::is_approximately_equal(std::sqrt(18.), p1.distance(p2)));
EXPECT(types::is_approximately_equal(std::sqrt(50.), p1.distance(p3)));
}
CASE("PointXYZ distance2 comparison") {
PointXYZ p1{2., 1., 0.};
PointXYZ p2{1., 2., 4.};
PointXYZ p3;
EXPECT(types::is_approximately_equal(p1.distance2(p2), 18.));
EXPECT(types::is_approximately_equal(p1.distance2(p3), 5.));
EXPECT(p2.distance2(p1) > p3.distance2(p1));
}
} // namespace eckit::geo::test
int main(int argc, char** argv) {
return eckit::testing::run_tests(argc, argv);
}
|