Skip to content

Commit

Permalink
Update README.md (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
griswaldbrooks authored Oct 25, 2023
1 parent fd551bd commit fc070b6
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions functional_programming_tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

This directory contains examples of tests that do and do not follow functional programming principles. When working with ROS, it is tempting to follow the established paradigm of encapsulating code and associated data in classes that inherit from or are composed of `rclcpp::Node`.

```
```cpp
class MinimalPublisher : public rclcpp::Node
// ... class definition
int main(int argc, char * argv[])
Expand All @@ -14,9 +14,9 @@ int main(int argc, char * argv[])
}
```
This usually leads to the code being dependent on the ROS ecosystem to function, even when it is not needed. In `without_functional_programming.cpp`, there is class method that requires testing, `generate_global_path`.
This usually leads to the code being dependent on the ROS ecosystem to function, even when it is not needed. In [`without_functional_programming.cpp`](https://github.com/PickNikRobotics/ros_testing_templates/blob/ros2/functional_programming_tests/test/without_functional_programming.cpp), there is class method that requires testing, `generate_global_path`.
```
```cpp
class PathGenerator {
public:
// ... some code
Expand All @@ -27,7 +27,7 @@ public:

To test the method properly, an entire ROS2 pipeline must be spun up.

```
```cpp
class TaskPlanningFixture : public testing::Test {
public:
// Adapted from minimal_integration_test
Expand All @@ -44,12 +44,12 @@ public:
executor_thread_ = std::thread([this]() { executor_->spin(); });
}

// Cleanup actions that could throw an exception
// Cleanup actions that could throw an exception
void TearDown() override {
executor_->cancel();
executor_thread_.join();
}
// ... more code
```
Writing all this extra code can be time consuming and lead to bugs in testing. In `with_functional_programming.cpp`, the `generate_global_path` method is now a free function, and the `costmap_callback` and `get_costmap` functions aren't needed anymore. This leads to less boilerplate code required to test `generate_global_path`.
Writing all this extra code can be time consuming and lead to bugs in testing. In [`with_functional_programming.cpp`](https://github.com/PickNikRobotics/ros_testing_templates/blob/ros2/functional_programming_tests/test/with_functional_programming.cpp), the `generate_global_path` method is now a free function, and the `costmap_callback` and `get_costmap` functions aren't needed anymore. This leads to less boilerplate code required to test `generate_global_path`.

0 comments on commit fc070b6

Please sign in to comment.