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

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