1 /*******************************************************************************
2 * ============LICENSE_START==================================================
4 * * ===========================================================================
5 * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6 * * ===========================================================================
7 * * Licensed under the Apache License, Version 2.0 (the "License");
8 * * you may not use this file except in compliance with the License.
9 * * You may obtain a copy of the License at
11 * * http://www.apache.org/licenses/LICENSE-2.0
13 * * Unless required by applicable law or agreed to in writing, software
14 * * distributed under the License is distributed on an "AS IS" BASIS,
15 * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * * See the License for the specific language governing permissions and
17 * * limitations under the License.
18 * * ============LICENSE_END====================================================
20 * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 ******************************************************************************/
24 package org.onap.dmaap.datarouter.provisioning.utils;
27 import static org.hamcrest.Matchers.is;
28 import static org.junit.Assert.assertThat;
29 import org.junit.Before;
30 import org.junit.Test;
31 import org.junit.runner.RunWith;
32 import org.powermock.modules.junit4.PowerMockRunner;
34 @RunWith(PowerMockRunner.class)
35 public class RLEBitSetTest {
38 private static RLEBitSet RLEBSet;
41 public void setUp() throws Exception {
42 RLEBSet = new RLEBitSet();
46 public void Given_Method_Is_Length_And_BitSet_Is_Empty_Return_0()
48 assertThat(RLEBSet.length(), is(0L));
52 public void Given_Method_Is_Length_And_BitSet_Is_Not_Empty_Return_Length()
55 assertThat(RLEBSet.length(), is(5L));
59 public void Given_Method_Is_Get_And_Value_Is_Inside_BitSet_Return_True()
63 assertThat(RLEBSet.get(val), is(true));
67 public void Given_Method_Is_Get_And_Value_Is_Not_Inside_BitSet_Return_False()
71 assertThat(RLEBSet.get(val), is(false));
75 public void Given_Method_Is_Set_And_Value_Is_Range_And_Is_Outside_BitSet_Then_Update_Range()
80 assertThat(RLEBSet.toString(), is("2-8"));
84 public void Given_Method_Is_Set_And_Value_Is_Not_Range_And_Is_Inside_BitSet_Then_Keep_Same_Range()
89 assertThat(RLEBSet.toString(), is("2-6"));
93 public void Given_Method_Is_Set_And_Value_Is_Not_Range_And_Is_Outside_BitSet_Then_Add_New_Range()
98 assertThat(RLEBSet.toString(), is("2-6,9"));
102 public void Given_Method_Is_Clear_Return_Blank_Set()
106 assertThat(RLEBSet.toString(), is(""));
110 public void Given_Method_Is_Clear_ValueRange_And_Range_Overlaps_BitSet_Return_Trimmed_BitSet()
115 RLEBSet.clear(from, to);
116 assertThat(RLEBSet.toString(), is("4-6"));
120 public void Given_Method_Is_Clear_ValueRange_And_Range_Is_Inside_BitSet_Return_Split_BitSets()
125 RLEBSet.clear(from, to);
126 assertThat(RLEBSet.toString(), is("2-3,7-8"));
130 public void Given_Method_Is_Clear_ValueRange_And_Range_Is_Outside_BitSet_Return_Unchanged_BitSets()
135 RLEBSet.clear(from, to);
136 assertThat(RLEBSet.toString(), is("2-6"));
140 public void Given_Method_Is_And_Return_Common_Value_Set()
142 RLEBitSet bSet = new RLEBitSet();
146 assertThat(RLEBSet.toString(), is("6-8"));
150 public void Given_Method_Is_AndNot_Return_Non_Common_Value_Set()
152 RLEBitSet bSet = new RLEBitSet();
155 RLEBSet.andNot(bSet);
156 assertThat(RLEBSet.toString(), is("2-5"));
160 public void Given_Method_Is_Cardinality_Return_Bits_Set_To_True()
163 assertThat(RLEBSet.cardinality(), is(7));
167 public void Given_Method_Is_Clone_Return_Identical_Clone()
170 assertThat(RLEBSet.clone().toString(), is(RLEBSet.toString()));