Skip to content

Commit

Permalink
implement length checks for title
Browse files Browse the repository at this point in the history
titles may not be too long nor too short, according to the requirements
  • Loading branch information
arnemertz committed Aug 20, 2021
1 parent 5c239a2 commit b610046
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 7 deletions.
7 changes: 5 additions & 2 deletions src/domain/title.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

using fix::domain::title;

bool title::create(std::string_view) { // NOLINT
return false;
constexpr size_t MIN_LENGTH = 6;
constexpr size_t MAX_LENGTH = 120;

bool title::create(std::string_view text) {
return (text.length() >= MIN_LENGTH) && (text.length() <= MAX_LENGTH);
}
2 changes: 1 addition & 1 deletion src/domain/title.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace fix::domain {

class title {
public:
static bool create(std::string_view str);
static bool create(std::string_view text);
};

} // namespace fix::domain
Expand Down
File renamed without changes.
22 changes: 18 additions & 4 deletions test/domain/title_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,30 @@

#include "title.hpp"

#include <string>

using fix::domain::title;
using namespace std::literals;

constexpr size_t MIN_LENGTH = 6;
constexpr size_t MAX_LENGTH = 120;

TEST_CASE("Titles have restricted length") {
SECTION("titles may not be empty") {
CHECK_FALSE(title::create(""));
}

SECTION("titles may not be too short") {}
SECTION("titles may not be too long") {}
SECTION("titles with a length in the allowed range can be created") {}
SECTION("titles may not be too short") {
CHECK_FALSE(title::create("short"));
}
SECTION("titles may not be too long") {
const auto long_scream = std::string(MAX_LENGTH, 'a') + "h"s;
CHECK_FALSE(title::create(long_scream));
}
SECTION("titles with a length in the allowed range can be created") {
const auto valid_string = GENERATE(std::string(MIN_LENGTH, 'n'), std::string(MAX_LENGTH, 'x'), "some title with sufficient length"s);
const auto title = title::create(valid_string);
CHECK(title);
}
}

TEST_CASE("Titles have a restricted character set") {
Expand Down

0 comments on commit b610046

Please sign in to comment.