diff --git a/chapter-10-testing/examples/AutoBrake.h b/chapter-10-testing/examples/AutoBrake.h index 5ce2ef4..190c377 100644 --- a/chapter-10-testing/examples/AutoBrake.h +++ b/chapter-10-testing/examples/AutoBrake.h @@ -1,6 +1,7 @@ // AutoBrake class template #pragma once +#include #include #include "AutoBrakePods.h" diff --git a/chapter-10-testing/examples/test_AutoBrake b/chapter-10-testing/examples/test_AutoBrake index b526b79..5e6ada8 100755 Binary files a/chapter-10-testing/examples/test_AutoBrake and b/chapter-10-testing/examples/test_AutoBrake differ diff --git a/chapter-10-testing/examples/test_AutoBrake.cpp b/chapter-10-testing/examples/test_AutoBrake.cpp index e40a993..f005169 100644 --- a/chapter-10-testing/examples/test_AutoBrake.cpp +++ b/chapter-10-testing/examples/test_AutoBrake.cpp @@ -1,6 +1,7 @@ // Autobrake unit tests #include +#include #include #include "AutoBrake.h" @@ -45,11 +46,11 @@ void speed_is_saved() { void alert_when_imminent() { int brake_commands_published{}; - AutoBrake auto_brake{ - [&brake_commands_published](const BrakeCommand&) { + auto count_brake_commands = + [&brake_commands_published](const BrakeCommand) { brake_commands_published++; - } - }; + }; + AutoBrake auto_brake{ count_brake_commands }; auto_brake.set_collision_threshold_s(10L); auto_brake.observe(SpeedUpdate{ 100L }); auto_brake.observe(CarDetected{ 100L, 0L}); diff --git a/chapter-10-testing/examples/test_capture b/chapter-10-testing/examples/test_capture new file mode 100755 index 0000000..d002dd7 Binary files /dev/null and b/chapter-10-testing/examples/test_capture differ diff --git a/chapter-10-testing/examples/test_capture.cpp b/chapter-10-testing/examples/test_capture.cpp new file mode 100644 index 0000000..1a21725 --- /dev/null +++ b/chapter-10-testing/examples/test_capture.cpp @@ -0,0 +1,10 @@ +// Test_capture + +#include +#include + +int main() { + int num {}; + std::function test_func = [&num]() {num ++;}; + std::cout << num; +}