You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

perf_data_test.cc 2.1 kB

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