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