• 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 "common/common.h"
17 #include "gtest/gtest.h"
18 #include "securec.h"
19 #include "minddata/dataset/engine/perf/cyclic_array.h"
20 #include "minddata/dataset/engine/perf/perf_data.h"
21 
22 using namespace mindspore::dataset;
23 
24 class MindDataTestPerfData : public UT::Common {
25  public:
MindDataTestPerfData()26   MindDataTestPerfData() {}
27 };
28 
TEST_F(MindDataTestPerfData,Test1)29 TEST_F(MindDataTestPerfData, Test1) {
30   PerfData<std::vector<int64_t>> p1(2, 3);
31   PerfData<CyclicArray<int>> p2(2, 3);
32   EXPECT_EQ(p1.capacity(), p2.capacity());
33   std::vector<int64_t> row = {1, 2, 3};
34   p1.AddSample(row);
35   p2.AddSample(row);
36   EXPECT_EQ(p1.size(), 1);
37   EXPECT_EQ(p1.size(), p2.size());
38   p1.AddSample(row);
39   p2.AddSample(row);
40   EXPECT_EQ(p1.size(), 2);
41   EXPECT_EQ(p1.size(), p2.size());
42   std::vector<int64_t> row1 = {4, 5, 6};
43   p2.AddSample(row1);
44   EXPECT_EQ(p2.size(), 2);
45   auto r1 = p2.Row<int>(static_cast<int64_t>(0));
46   for (auto i = 0; i < 3; i++) {
47     EXPECT_EQ(r1[i], i + 1);
48   }
49 
50   auto r2 = p2.Row<int>(1);
51   for (auto i = 0; i < 3; i++) {
52     EXPECT_EQ(r2[i], i + 4);
53   }
54 
55   EXPECT_EQ(p2[0][1], 4);
56   EXPECT_EQ(p2[1][1], 5);
57   EXPECT_EQ(p2[2][1], 6);
58 }
59 
TEST_F(MindDataTestPerfData,Test2)60 TEST_F(MindDataTestPerfData, Test2) {
61   auto pd = PerfData<CyclicArray<int>>(1000000, 3);
62   auto row = {1, 2, 3};
63   pd.AddSample(row);
64   EXPECT_EQ(pd[0][0], 1);
65   EXPECT_EQ(pd[1][0], 2);
66   EXPECT_EQ(pd[2][0], 3);
67   auto row1 = {4, 5, 6};
68   pd.AddSample(row1);
69   EXPECT_EQ(pd[0][0], 1);
70   EXPECT_EQ(pd[1][0], 2);
71   EXPECT_EQ(pd[2][0], 3);
72   EXPECT_EQ(pd[0][1], 4);
73   EXPECT_EQ(pd[1][1], 5);
74   EXPECT_EQ(pd[2][1], 6);
75 }