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 1.9 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 "dataset/engine/perf/cyclic_array.h"
  21. #include "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(), p2.size());
  35. p1.AddSample(row);
  36. p2.AddSample(row);
  37. EXPECT_EQ(p1.size(), p2.size());
  38. row = {4, 5, 6};
  39. p2.AddSample(row);
  40. auto r1 = p2.Row<int>(static_cast<int64_t>(0));
  41. for (auto i = 0; i < 3; i++) {
  42. EXPECT_EQ(r1[i], i + 1);
  43. }
  44. auto r2 = p2.Row<int>(1);
  45. for (auto i = 0; i < 3; i++) {
  46. EXPECT_EQ(r2[i], i + 4);
  47. }
  48. EXPECT_EQ(p2[0][1], 4);
  49. EXPECT_EQ(p2[1][1], 5);
  50. EXPECT_EQ(p2[2][1], 6);
  51. }
  52. TEST_F(MindDataTestPerfData, Test2) {
  53. auto pd = PerfData<CyclicArray<int>>(1000000, 3);
  54. auto row = {1, 2, 3};
  55. pd.AddSample(row);
  56. EXPECT_EQ(pd[0][0], 1);
  57. EXPECT_EQ(pd[1][0], 2);
  58. EXPECT_EQ(pd[2][0], 3);
  59. row = {4, 5, 6};
  60. pd.AddSample(row);
  61. EXPECT_EQ(pd[0][0], 1);
  62. EXPECT_EQ(pd[1][0], 2);
  63. EXPECT_EQ(pd[2][0], 3);
  64. }