tuple_test.cc 2.0 KB
Newer Older
C
chengduo 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14
/* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */
#include "paddle/fluid/framework/tuple.h"
W
wanghuancoder 已提交
15
#include "gtest/gtest.h"
C
chengduo 已提交
16 17 18 19 20 21 22 23 24

TEST(Tuple, Make) {
  std::vector<paddle::framework::ElementVar> element_type;
  element_type.push_back(12);
  element_type.push_back(12.0f);
  element_type.push_back("ElementVar");

  paddle::framework::Tuple* tuple = paddle::framework::make_tuple(element_type);

25 26 27
  EXPECT_EQ(BOOST_GET(int, tuple->get(0)), 12);
  EXPECT_EQ(BOOST_GET(float, tuple->get(1)), 12.0f);
  EXPECT_EQ(BOOST_GET(std::string, tuple->get(2)), "ElementVar");
C
chengduo 已提交
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

  delete tuple;
}

TEST(Tuple, IsTheSameType) {
  std::vector<paddle::framework::ElementVar> element_type1;
  std::vector<paddle::framework::ElementVar> element_type2;
  std::vector<paddle::framework::ElementVar> element_type3;

  element_type1.push_back(12);
  element_type1.push_back(12.0f);
  element_type1.push_back("Tuple1");

  element_type2.push_back(13);
  element_type2.push_back(13.0f);
  element_type2.push_back("Tuple2");

  element_type3.push_back(14.0f);
  element_type3.push_back(14);
  element_type3.push_back("Tuple3");

  paddle::framework::Tuple* tuple1 =
      paddle::framework::make_tuple(element_type1);
  paddle::framework::Tuple* tuple2 =
      paddle::framework::make_tuple(element_type2);
  paddle::framework::Tuple* tuple3 =
      paddle::framework::make_tuple(element_type3);

  EXPECT_TRUE(tuple1->isSameType(*tuple2));
  EXPECT_FALSE(tuple1->isSameType(*tuple3));

  delete tuple1;
  delete tuple2;
  delete tuple3;
}