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.

treap_test.cc 1.5 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /**
  2. * Copyright 2019 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 "minddata/dataset/util/treap.h"
  17. #include "common/common.h"
  18. #include "gtest/gtest.h"
  19. #include "utils/log_adapter.h"
  20. using namespace mindspore::dataset;
  21. class MindDataTestTreap : public UT::Common {
  22. public:
  23. MindDataTestTreap() {}
  24. };
  25. TEST_F(MindDataTestTreap, TestALLFunction) {
  26. Treap<uint64_t, uint64_t> tree;
  27. srand(time(NULL));
  28. for (uint64_t i = 0; i < 1000; i++) {
  29. uint64_t sz = rand() % 500;
  30. tree.Insert(i, sz);
  31. }
  32. EXPECT_EQ(tree.size(), 1000);
  33. int n = 0;
  34. uint64_t key = 0;
  35. for (auto it : tree) {
  36. if (n > 0) {
  37. EXPECT_GT(it.key, key);
  38. }
  39. key = it.key;
  40. n++;
  41. }
  42. EXPECT_EQ(n, 1000);
  43. uint64_t prev = 0;
  44. n = 0;
  45. while (!tree.empty()) {
  46. auto p = tree.Top();
  47. EXPECT_TRUE(p.second);
  48. uint64_t v = p.first.priority;
  49. if (n > 0) {
  50. EXPECT_GE(prev, v);
  51. }
  52. prev = v;
  53. n++;
  54. tree.Pop();
  55. }
  56. }