diff options
author | Alex Zolotarev <deathbaba@gmail.com> | 2011-01-17 22:49:54 +0300 |
---|---|---|
committer | Alex Zolotarev <alex@maps.me> | 2015-09-23 01:10:28 +0300 |
commit | f9d27b14811b9dbbb9a19b08aa3969a4c9c5b35f (patch) | |
tree | 9ead76d2faa4a70fe501ea0cb6384b6782886abc /geometry/geometry_tests/region_test.cpp | |
parent | ab919c89216198f804ce9e27be148e2b9dc90f26 (diff) |
Added m2::Region::ForEachPoint, updated unit tests
Diffstat (limited to 'geometry/geometry_tests/region_test.cpp')
-rw-r--r-- | geometry/geometry_tests/region_test.cpp | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/geometry/geometry_tests/region_test.cpp b/geometry/geometry_tests/region_test.cpp index 46b1887095..a8a79a6b5d 100644 --- a/geometry/geometry_tests/region_test.cpp +++ b/geometry/geometry_tests/region_test.cpp @@ -33,6 +33,25 @@ void Test() } +UNIT_TEST(Region) +{ + typedef m2::PointD P; + P p1[] = { P(0.1, 0.2) }; + + m2::Region<P> region(p1, p1 + ARRAY_SIZE(p1)); + TEST(!region.IsValid(), ()); + + { + P p2[] = { P(1.0, 2.0), P(55.0, 33.0) }; + region.Assign(p2, p2 + ARRAY_SIZE(p2)); + } + TEST(!region.IsValid(), ()); + + region.AddPoint(P(34.4, 33.2)); + TEST(region.IsValid(), ()); + +} + UNIT_TEST(Region_Contains) { Test<m2::PointU>(); @@ -68,3 +87,29 @@ UNIT_TEST(Region_Contains) TEST(!region.Contains(P(1, 1)), ()); } } + +template <class TPoint> +struct PointsSummator +{ + double m_xSumm; + double m_ySumm; + PointsSummator() : m_xSumm(0), m_ySumm(0) {} + void operator()(TPoint const & pt) + { + m_xSumm += pt.x; + m_ySumm += pt.y; + } +}; + +UNIT_TEST(Region_ForEachPoint) +{ + typedef m2::PointF P; + P const points[] = { P(0.0, 1.0), P(1.0, 2.0), P(10.5, 11.5) }; + m2::Region<P> region(points, points + ARRAY_SIZE(points)); + + PointsSummator<P> s; + region.ForEachPoint(s); + + TEST_EQUAL(s.m_xSumm, 11.5, ()); + TEST_EQUAL(s.m_ySumm, 14.5, ()); +} |