#include "gtest/gtest.h" #include "jianzhi_offer.h" TEST(ReplaceSpaceTest, BasicAssertions) { std::string input = "We are happy."; std::string expected = "We%20are%20happy."; yaha::String s; ASSERT_EQ(expected, s.replace_space(input)); } TEST(IsNumberTest, BasicAssertions) { yaha::String s; ASSERT_TRUE(s.is_number("0")); ASSERT_TRUE(s.is_number(" .1 ")); ASSERT_FALSE(s.is_number(".")); ASSERT_FALSE(s.is_number("e")); ASSERT_FALSE(s.is_number("e9")); } TEST(ReverseLeftWordsTest, BasicAssertions) { yaha::String s; ASSERT_EQ("cdefgab", s.reverse_left_words("abcdefg", 2)); ASSERT_EQ("umghlrlose", s.reverse_left_words("lrloseumgh", 6)); } TEST(StringToIntTest, BasicAssertions) { yaha::String s; ASSERT_EQ(42, s.str_to_int("42")); ASSERT_EQ(-42, s.str_to_int("-42")); ASSERT_EQ(-42, s.str_to_int(" -42")); ASSERT_EQ(4193, s.str_to_int("4193 with words")); ASSERT_EQ(0, s.str_to_int("words and 987")); } TEST(UriTest, BasicAssertions) { std::string url = "http://pdxo.poms.bae.baidu.com/rest/2.0/poms/object?method=download&consume_idc=pdxo&service=pcsImageTranr"; // Find the position of the first '/' character size_t pos = url.find("/rest"); if (pos != std::string::npos) { // Extract the substring starting from the found position std::string extracted = url.substr(pos); std::cout << "Extracted URL: " << extracted << std::endl; } else { std::cout << "Substring not found." << std::endl; } }