• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 2020 Huawei Technologies Co., Ltd
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #include <memory>
17 #include <string>
18 #include "minddata/dataset/core/client.h"
19 #include "common/common.h"
20 #include "gtest/gtest.h"
21 #include "securec.h"
22 #include "minddata/dataset/core/tensor.h"
23 #include "mindspore/ccsrc/minddata/dataset/text/kernels/truncate_sequence_pair_op.h"
24 
25 using namespace mindspore::dataset;
26 
27 namespace py = pybind11;
28 
29 class MindDataTestTruncatePairOp : public UT::Common {
30  public:
31   MindDataTestTruncatePairOp() {}
32 
33   void SetUp() { GlobalInit(); }
34 };
35 
36 TEST_F(MindDataTestTruncatePairOp, Basics) {
37   std::shared_ptr<Tensor> t1;
38   Tensor::CreateFromVector(std::vector<uint32_t>({1, 2, 3}), &t1);
39   std::shared_ptr<Tensor> t2;
40   Tensor::CreateFromVector(std::vector<uint32_t>({4, 5}), &t2);
41   TensorRow in({t1, t2});
42   std::shared_ptr<TruncateSequencePairOp> op = std::make_shared<TruncateSequencePairOp>(4);
43   TensorRow out;
44   ASSERT_TRUE(op->Compute(in, &out).IsOk());
45   std::shared_ptr<Tensor> out1;
46   Tensor::CreateFromVector(std::vector<uint32_t>({1, 2}), &out1);
47   std::shared_ptr<Tensor> out2;
48   Tensor::CreateFromVector(std::vector<uint32_t>({4, 5}), &out2);
49   ASSERT_EQ(*out1, *out[0]);
50   ASSERT_EQ(*out2, *out[1]);
51 }
52