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

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