Created
February 27, 2024 07:53
-
-
Save iglesias/c480ba6a83e673aef2fc47d7a859870d to your computer and use it in GitHub Desktop.
Rewiring your brain with test driven thinking in C++ - Phil Nash - Meeting C++ 2023
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <string> | |
| #include <string_view> | |
| #include <catch2/catch_test_macros.hpp> | |
| std::string left_pad(std::string_view str, std::size_t min_len) { | |
| auto const pad_len = std::max<int>(0, min_len-str.length()); | |
| return std::string(pad_len, ' ') + std::string(str); | |
| } | |
| TEST_CASE("left_pad") { | |
| REQUIRE(left_pad("", 0) == ""); | |
| REQUIRE(left_pad("a", 0) == "a"); | |
| REQUIRE(left_pad("", 1) == " "); | |
| REQUIRE(left_pad("", 2) == " "); | |
| REQUIRE(left_pad("abc", 5) == " abc"); | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://godbolt.org/z/hcrxTesf5