test_cond.cpp 1.68 KB
Newer Older
limm's avatar
limm committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Copyright (c) OpenMMLab. All rights reserved.

#include "catch.hpp"
#include "mmdeploy/archive/json_archive.h"
#include "mmdeploy/core/graph.h"
#include "mmdeploy/core/registry.h"
#include "mmdeploy/experimental/module_adapter.h"

using namespace mmdeploy;

namespace {

class PlusCreator : public Creator<Module> {
 public:
  std::string_view name() const noexcept override { return "Plus"; }
  std::unique_ptr<Module> Create(const Value&) override {
    return CreateTask([](int a, int b) { return a + b; });
  }
};

MMDEPLOY_REGISTER_CREATOR(Module, PlusCreator);

const auto json_config1 = R"(
{
  "type": "Cond",
  "input": ["pred", "a", "b"],
  "output": "c",
  "body": {
    "type": "Task",
    "module": "Plus"
  }
}
)"_json;

}  // namespace

TEST_CASE("test Cond node", "[graph]") {
  auto config = from_json<Value>(json_config1);
  auto builder = graph::Builder::CreateFromConfig(config).value();
  REQUIRE(builder);
  auto node = builder->Build().value();
  REQUIRE(node);
  {
    auto result = SyncWait(node->Process(Just(Value({{false}, {1}, {1}}))));
    MMDEPLOY_INFO("{}", result);
  }
  {
    auto result = SyncWait(node->Process(Just(Value({{true}, {1}, {1}}))));
    MMDEPLOY_INFO("{}", result);
  }
  {
    auto result = SyncWait(
        node->Process(Just(Value({{false, false, false, false}, {1, 2, 3, 4}, {1, 3, 5, 7}}))));
    MMDEPLOY_INFO("{}", result);
  }
  {
    auto result = SyncWait(
        node->Process(Just(Value({{true, true, true, true}, {1, 2, 3, 4}, {1, 3, 5, 7}}))));
    MMDEPLOY_INFO("{}", result);
  }
  {
    auto result = SyncWait(
        node->Process(Just(Value({{true, false, false, true}, {1, 2, 3, 4}, {1, 3, 5, 7}}))));
    MMDEPLOY_INFO("{}", result);
  }
}