34 lines
990 B
C++
34 lines
990 B
C++
#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"));
|
|
} |