tvm-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [incubator-tvm] zhiics commented on a change in pull request #5314: [RUNTIME][IR] Allow non-nullable ObjectRef, introduce Optional<T>.
Date Sun, 12 Apr 2020 23:58:37 GMT
zhiics commented on a change in pull request #5314: [RUNTIME][IR] Allow non-nullable ObjectRef,
introduce Optional<T>.
URL: https://github.com/apache/incubator-tvm/pull/5314#discussion_r407260236
 
 

 ##########
 File path: tests/cpp/container_test.cc
 ##########
 @@ -401,6 +401,58 @@ TEST(String, Cast) {
   String s2 = Downcast<String>(r);
 }
 
+
+TEST(Optional, Composition) {
+  Optional<String> opt0 = nullptr;
+  Optional<String> opt1 = String("xyz");
+  Optional<String> opt2 = String("xyz1");
+  // operator bool
+  CHECK(!opt0);
+  CHECK(opt1);
+  // comparison op
+  CHECK(opt0 != "xyz");
+  CHECK(opt1 == "xyz");
+  CHECK(opt1 != nullptr);
+  CHECK(opt0 == nullptr);
+  CHECK(opt0 != opt1);
+  CHECK(opt1 == Optional<String>(String("xyz")));
+  CHECK(opt0 == Optional<String>(nullptr));
+  opt0 = opt1;
+  CHECK(opt0 == opt1);
+  CHECK(opt0.value().same_as(opt1.value()));
+  opt0 = std::move(opt2);
+  CHECK(opt0 != opt2);
+}
+
+TEST(Optional, PackedCall) {
+  auto tf = [](Optional<String> s, bool isnull) {
+    if (isnull) {
+      CHECK(s == nullptr);
+    } else {
+      CHECK(s != nullptr);
+    }
+    return s;
+  };
+  auto func = TypedPackedFunc<Optional<String>(Optional<String>, bool)>(tf);
+  func(String("xyz"), false);
 
 Review comment:
   Check the returned value for these funcs?

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

Mime
View raw message