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.

bit_functions_test.cc 1.6 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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/include/constants.h"
  17. #include "common/common.h"
  18. using namespace mindspore::dataset;
  19. class MindDataTestBits : public UT::Common {
  20. public:
  21. MindDataTestBits() {}
  22. };
  23. TEST_F(MindDataTestBits, Basics) {
  24. uint32_t x = 0; // 00000
  25. BitSet(&x, 16); // 10000
  26. ASSERT_TRUE(BitTest(x, 16)); // 10000
  27. ASSERT_FALSE(BitTest(x, 1)); // 00001
  28. ASSERT_FALSE(BitTest(x, 17)); // 10001 is failing
  29. BitSet(&x, 1); // 10001
  30. ASSERT_TRUE(BitTest(x, 16)); // 10000
  31. ASSERT_TRUE(BitTest(x, 1)); // 00001
  32. ASSERT_TRUE(BitTest(x, 17)); // 10001 is failing
  33. BitClear(&x, 16); // 00001
  34. ASSERT_FALSE(BitTest(x, 16)); // 10000
  35. ASSERT_TRUE(BitTest(x, 1)); // 00001
  36. // ASSERT_FALSE(BitTest(x, 17)); // 10001 is failing
  37. BitSet(&x, 31); // 11111
  38. for (uint32_t i = 1; i < 32; i++) {
  39. ASSERT_TRUE(BitTest(x, i));
  40. }
  41. BitClear(&x, 31); // 00000
  42. for (uint32_t i = 1; i < 32; i++) {
  43. ASSERT_FALSE(BitTest(x, i));
  44. }
  45. }