Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Zolotarev <deathbaba@gmail.com>2010-12-05 19:24:16 +0300
committerAlex Zolotarev <alex@maps.me>2015-09-22 22:33:57 +0300
commitd6e12b7ce4bcbf0ccd1c07eb25de143422913c34 (patch)
treea7e910c330ce4da9b4f2d8be76067adece2561c4 /geometry/geometry_tests/angle_test.cpp
One Month In Minsk. Made in Belarus.
Diffstat (limited to 'geometry/geometry_tests/angle_test.cpp')
-rw-r--r--geometry/geometry_tests/angle_test.cpp54
1 files changed, 54 insertions, 0 deletions
diff --git a/geometry/geometry_tests/angle_test.cpp b/geometry/geometry_tests/angle_test.cpp
new file mode 100644
index 0000000000..c59bd66276
--- /dev/null
+++ b/geometry/geometry_tests/angle_test.cpp
@@ -0,0 +1,54 @@
+#include "../../base/SRC_FIRST.hpp"
+
+#include "equality.hpp"
+
+#include "../../base/macros.hpp"
+
+#include "../../testing/testing.hpp"
+
+#include "../angles.hpp"
+
+using namespace test;
+
+UNIT_TEST(Atan)
+{
+ double const h4 = math::pi/4.0;
+
+ TEST(is_equal_atan(1, 1, h4), ());
+ TEST(is_equal_atan(-1, 1, math::pi - h4), ());
+ TEST(is_equal_atan(-1, -1, h4 - math::pi), ());
+ TEST(is_equal_atan(1, -1, -h4), ());
+
+ double const hh = atan(1.0/2.0);
+
+ TEST(is_equal_atan(2, 1, hh), ());
+ TEST(is_equal_atan(-2, 1, math::pi - hh), ());
+ TEST(is_equal_atan(-2, -1, hh - math::pi), ());
+ TEST(is_equal_atan(2, -1, -hh), ());
+}
+
+namespace
+{
+ void check_avg(double arr[], size_t n, double v)
+ {
+ ang::AverageCalc calc;
+ for (size_t i = 0; i < n; ++i)
+ calc.Add(arr[i]);
+
+ double const avg = calc.GetAverage();
+ TEST(is_equal_angle(avg, v), (avg, v));
+ }
+}
+
+UNIT_TEST(Average)
+{
+ double const eps = 1.0E-3;
+
+ double arr1[] = { math::pi-eps, -math::pi+eps };
+ TEST(is_equal_angle(ang::GetMiddleAngle(arr1[0], arr1[1]), math::pi), ());
+ check_avg(arr1, ARRAY_SIZE(arr1), math::pi);
+
+ double arr2[] = { eps, -eps };
+ TEST(is_equal_angle(ang::GetMiddleAngle(arr2[0], arr2[1]), 0.0), ());
+ check_avg(arr2, ARRAY_SIZE(arr2), 0.0);
+}