Skip to content

Commit

Permalink
Added test for network traversal
Browse files Browse the repository at this point in the history
  • Loading branch information
gregjesl committed Feb 5, 2023
1 parent f67d1cc commit 663f840
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
14 changes: 14 additions & 0 deletions inc/glnav_route.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,20 @@ namespace glnav
}
return result;
}

bool traverses(const network<T, Q> &net) const
{
if(this->empty()) return false;
typename std::deque<heading<T, Q> >::const_iterator it, last;
last = this->begin();
for(it = this->begin(); it != this->end(); ++it)
{
if(!net.contains(it->target)) return false;
if(it != last && !net.contains(path<T>(last->target, it->target))) return false;
last = it;
}
return true;
}
};
}

Expand Down
9 changes: 9 additions & 0 deletions test/route.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@ int main(void)
test.push_back(glnav::heading<double, double>(target, 1));
TEST_TRUE(test.target() == target);

{
glnav::network<double, double> net;
TEST_FALSE(test.traverses(net));
net.add(glnav::path<double>(start, midpoint), 3);
net.add(glnav::path<double>(midpoint, target), 3);
TEST_TRUE(test.traverses(net));
}


glnav::travel_result<double, double> result = test.follow(start, 1);
TEST_TRUE(result.target == midpoint);
TEST_TRUE(result.location.x > 0.99 && result.location.x < 1.01);
Expand Down

0 comments on commit 663f840

Please sign in to comment.