custom_order_test.cpp
Go to the documentation of this file.
1 #include <gtest/gtest.h>
2 #include "fields2cover/types.h"
5 
6 TEST(fields2cover_route_custom_order, defined_order) {
7  const int n = 11;
9  for (int i = 1; i < n; ++i) {
10  swaths.emplace_back(F2CLineString({F2CPoint(0, i), F2CPoint(1, i)}), i, i-1);
11  }
12 
13  f2c::rp::CustomOrder swath_sorter;
14  swath_sorter.setCustomOrder({1,0,3,2,5,4,7,6,8,9});
15 
16  swaths = swath_sorter.genSortedSwaths(swaths, 0);
17 
18  EXPECT_EQ(swaths[0].getId(), 1);
19  EXPECT_EQ(swaths[1].getId(), 0);
20  EXPECT_EQ(swaths[2].getId(), 3);
21  EXPECT_EQ(swaths[3].getId(), 2);
22  EXPECT_EQ(swaths[4].getId(), 5);
23  EXPECT_EQ(swaths[5].getId(), 4);
24  EXPECT_EQ(swaths[6].getId(), 7);
25  EXPECT_EQ(swaths[7].getId(), 6);
26  EXPECT_EQ(swaths[8].getId(), 8);
27  EXPECT_EQ(swaths[9].getId(), 9);
28 }
29 
30 TEST(fields2cover_route_custom_order, constructor_order) {
31  const int n = 11;
33  for (int i = 1; i < n; ++i) {
34  swaths.emplace_back(F2CLineString({F2CPoint(0, i), F2CPoint(1, i)}), i, i-1);
35  }
36 
37  f2c::rp::CustomOrder swath_sorter({9,0,8,1,7,2,6,3,5,4});
38  f2c::rp::CustomOrder swath_sorter2;
39  swath_sorter2.setCustomOrder({9,0,8,1,7,2,6,3,5,4});
40 
42 
43  swaths = swath_sorter.genSortedSwaths(swaths);
44  auto swaths2 = swath_sorter2.genSortedSwaths(swaths);
45 
46  EXPECT_EQ(swaths[0].getId(), 9);
47  EXPECT_EQ(swaths[1].getId(), 0);
48  EXPECT_EQ(swaths[2].getId(), 8);
49  EXPECT_EQ(swaths[3].getId(), 1);
50  EXPECT_EQ(swaths[4].getId(), 7);
51  EXPECT_EQ(swaths[5].getId(), 2);
52  EXPECT_EQ(swaths[6].getId(), 6);
53  EXPECT_EQ(swaths[7].getId(), 3);
54  EXPECT_EQ(swaths[8].getId(), 5);
55  EXPECT_EQ(swaths[9].getId(), 4);
56  EXPECT_EQ(swaths2[0].getId(), 9);
57  EXPECT_EQ(swaths2[1].getId(), 0);
58  EXPECT_EQ(swaths2[2].getId(), 8);
59  EXPECT_EQ(swaths2[3].getId(), 1);
60  EXPECT_EQ(swaths2[4].getId(), 7);
61  EXPECT_EQ(swaths2[5].getId(), 2);
62  EXPECT_EQ(swaths2[6].getId(), 6);
63  EXPECT_EQ(swaths2[7].getId(), 3);
64  EXPECT_EQ(swaths2[8].getId(), 5);
65  EXPECT_EQ(swaths2[9].getId(), 4);
66 }
67 
68 TEST(fields2cover_route_custom_order, incomplete_order) {
69  const int n = 11;
71  for (int i = 1; i < n; ++i) {
72  swaths.emplace_back(F2CLineString({F2CPoint(0, i), F2CPoint(1, i)}), i, i-1);
73  }
74  f2c::rp::CustomOrder swath_sorter({9,0,8,1,7,2,6,3});
75 
76  EXPECT_ANY_THROW(swath_sorter.genSortedSwaths(swaths));
77 }
78 
79 TEST(fields2cover_route_custom_order, bad_order) {
80  const int n = 11;
82  for (int i = 1; i < n; ++i) {
83  swaths.emplace_back(F2CLineString({F2CPoint(0, i), F2CPoint(1, i)}), i, i-1);
84  }
85  f2c::rp::CustomOrder swath_sorter({9,1,8,1,7,2,6,3,5,4});
86 
87  EXPECT_ANY_THROW(swath_sorter.genSortedSwaths(swaths));
88 }
89 
90 TEST(fields2cover_route_custom_order, out_of_range) {
91  const int n = 11;
93  for (int i = 1; i < n; ++i) {
94  swaths.emplace_back(F2CLineString({F2CPoint(0, i), F2CPoint(1, i)}), i, i-1);
95  }
96  f2c::rp::CustomOrder swath_sorter({10,0,8,1,7,2,6,3,5,4});
97 
98  EXPECT_ANY_THROW(swath_sorter.genSortedSwaths(swaths));
99 }
5_route_planning.swaths
swaths
Definition: 5_route_planning.py:58
custom_order.h
types.h
f2c::obj::DirectDistPathObj
Path cost function as the straight distance between points in a route.
Definition: direct_dist_path_obj.h:17
f2c::rp::CustomOrder::setCustomOrder
void setCustomOrder(const std::vector< size_t > &order)
Definition: custom_order.cpp:11
f2c::rp::SingleCellSwathsOrderBase::genSortedSwaths
virtual F2CSwaths genSortedSwaths(const F2CSwaths &swaths, uint32_t variant=0) const
Definition: single_cell_swaths_order_base.cpp:12
F2CLineString
f2c::types::LineString F2CLineString
Definition: types.h:40
direct_dist_path_obj.h
f2c::rp::CustomOrder
Definition: custom_order.h:15
f2c::types::Swaths
Definition: Swaths.h:20
F2CPoint
f2c::types::Point F2CPoint
Definition: types.h:38
TEST
TEST(fields2cover_route_custom_order, defined_order)
Definition: custom_order_test.cpp:6


fields2cover
Author(s):
autogenerated on Fri Apr 25 2025 02:18:31