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

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