| 1 |
/* |
| 2 |
* Copyright (C) 2015 The Android Open Source Project |
| 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 |
|
| 17 |
package android.databinding.tool.writer; |
| 18 |
|
| 19 |
import org.junit.Test; |
| 20 |
|
| 21 |
import java.util.BitSet; |
| 22 |
|
| 23 |
import static org.junit.Assert.assertEquals; |
| 24 |
|
| 25 |
public class FlagSetTest { |
| 26 |
@Test |
| 27 |
public void testSimple1Level() { |
| 28 |
BitSet bs = new BitSet(); |
| 29 |
bs.set(7); |
| 30 |
FlagSet flagSet = new FlagSet(bs, 3); |
| 31 |
assertEquals(3, flagSet.buckets.length); |
| 32 |
assertEquals(1 << 7, flagSet.buckets[0]); |
| 33 |
assertEquals(0, flagSet.buckets[1]); |
| 34 |
assertEquals(0, flagSet.buckets[2]); |
| 35 |
} |
| 36 |
|
| 37 |
@Test |
| 38 |
public void testSimple2Level() { |
| 39 |
BitSet bs = new BitSet(); |
| 40 |
bs.set(FlagSet.sBucketSize + 2); |
| 41 |
FlagSet flagSet = new FlagSet(bs, 3); |
| 42 |
assertEquals(3, flagSet.buckets.length); |
| 43 |
assertEquals(0, flagSet.buckets[0]); |
| 44 |
assertEquals(1 << 2, flagSet.buckets[1]); |
| 45 |
assertEquals(0, flagSet.buckets[2]); |
| 46 |
} |
| 47 |
|
| 48 |
@Test |
| 49 |
public void testSimple3Level() { |
| 50 |
BitSet bs = new BitSet(); |
| 51 |
bs.set(5); |
| 52 |
bs.set(FlagSet.sBucketSize + 2); |
| 53 |
bs.set(FlagSet.sBucketSize * 2 + 10); |
| 54 |
FlagSet flagSet = new FlagSet(bs, 3); |
| 55 |
assertEquals(3, flagSet.buckets.length); |
| 56 |
assertEquals(1 << 5, flagSet.buckets[0]); |
| 57 |
assertEquals(1 << 2, flagSet.buckets[1]); |
| 58 |
assertEquals(1 << 10, flagSet.buckets[2]); |
| 59 |
} |
| 60 |
|
| 61 |
@Test |
| 62 |
public void testLargeValue() { |
| 63 |
BitSet bs = new BitSet(); |
| 64 |
bs.set(43); |
| 65 |
FlagSet flagSet = new FlagSet(bs, 1); |
| 66 |
assertEquals(1, flagSet.buckets.length); |
| 67 |
assertEquals(1L << 43, flagSet.buckets[0]); |
| 68 |
} |
| 69 |
} |