tqchen commented on a change in pull request #4628: [Object] Add String
container
URL: https://github.com/apache/incubator-tvm/pull/4628#discussion_r374450097
##########
File path: tests/cpp/container_test.cc
##########
@@ -226,6 +226,63 @@ TEST(Map, Iterator) {
CHECK(map2[a].as<IntImmNode>()->value == 2);
}
+TEST(String, MoveFromStd) {
+ using namespace std;
+ std::string source = "this is a string";
+ std::string expect = source;
+ String s(std::move(source));
+ std::string copy = (std::string)s;
+ CHECK_EQ(copy, expect);
+ CHECK_EQ(source.size(), 0);
+}
+
+TEST(String, CopyFromStd) {
+ using namespace std;
+ std::string source = "this is a string";
+ std::string expect = source;
+ String s{source};
+ std::string copy = (std::string)s;
+ CHECK_EQ(copy, expect);
+ CHECK_EQ(source.size(), expect.size());
+}
+
+TEST(String, Comparisons) {
+ using namespace std;
+ std::string source = "a string";
+ std::string mismatch = "a string but longer";
+ String s{source};
+
+ CHECK_EQ(s == source, true);
+ CHECK_EQ(s == mismatch, false);
+ CHECK_EQ(s == source.data(), true);
+ CHECK_EQ(s == mismatch.data(), false);
+}
+
+TEST(String, c_str) {
+ using namespace std;
+ std::string source = "this is a string";
+ std::string mismatch = "mismatch";
+ String s{source};
+
+ CHECK_EQ(std::strcmp(s.c_str(), source.data()), 0);
+ CHECK_NE(std::strcmp(s.c_str(), mismatch.data()), 0);
+}
+
+TEST(String, hash) {
+ using namespace std;
+ std::string source = "this is a string";
+ String s{source};
+ std::hash<String>()(s);
Review comment:
add testcase of std::unordered_map<String, xyz>
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services