Update dynamic_programming/word_break.cpp

Co-authored-by: David Leal <halfpacho@gmail.com>
This commit is contained in:
Akshay Anand 2020-10-16 01:00:20 +05:30 committed by GitHub
parent a3c9e701c3
commit d8ab6b0282
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -148,6 +148,24 @@ bool wordBreak(const std::string &s, const std::vector<std::string> &wordDict) {
} // namespace word_break
} // namespace dynamic_programming
/**
* @brief Test implementations
* @returns void
*/
static void test() {
// the complete string
const std::string s = "applepenapple";
// the dictionary to be used
const std::vector<std::string> wordDict = {"apple", "pen"};
assert(dynamic_programming::word_break::wordBreak(s, wordDict));
// should return true, as applepenapple can be segmented as apple + pen +
// apple
std::cout << dynamic_programming::word_break::wordBreak(s, wordDict)
<< std::endl;
std::cout << "Test implementation passed!\n";
}
/**
* @brief Main function
* @returns 0 on exit