github.com/bytedance/gopkg@v0.0.0-20240514070511-01b2cbcf35e1/collection/skipset/flag_test.go (about) 1 // Copyright 2021 ByteDance Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package skipset 16 17 import ( 18 "testing" 19 ) 20 21 func TestFlag(t *testing.T) { 22 // Correctness. 23 const ( 24 f0 = 1 << iota 25 f1 26 f2 27 f3 28 f4 29 f5 30 f6 31 f7 32 ) 33 x := &bitflag{} 34 35 x.SetTrue(f1 | f3) 36 if x.Get(f0) || !x.Get(f1) || x.Get(f2) || !x.Get(f3) || !x.MGet(f0|f1|f2|f3, f1|f3) { 37 t.Fatal("invalid") 38 } 39 x.SetTrue(f1) 40 x.SetTrue(f1 | f3) 41 if x.data != f1+f3 { 42 t.Fatal("invalid") 43 } 44 45 x.SetFalse(f1 | f2) 46 if x.Get(f0) || x.Get(f1) || x.Get(f2) || !x.Get(f3) || !x.MGet(f0|f1|f2|f3, f3) { 47 t.Fatal("invalid") 48 } 49 x.SetFalse(f1 | f2) 50 if x.data != f3 { 51 t.Fatal("invalid") 52 } 53 }