1 /*
2  * Copyright (C) 2018 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 package com.android.launcher3.util;
17 
18 import static com.google.common.truth.Truth.assertThat;
19 
20 import static org.junit.Assert.assertEquals;
21 import static org.junit.Assert.assertFalse;
22 import static org.junit.Assert.assertTrue;
23 
24 import androidx.test.ext.junit.runners.AndroidJUnit4;
25 import androidx.test.filters.SmallTest;
26 
27 import org.junit.Test;
28 import org.junit.runner.RunWith;
29 
30 /**
31  * Unit tests for {@link IntSet}
32  */
33 @SmallTest
34 @RunWith(AndroidJUnit4.class)
35 public class IntSetTest {
36 
37     @Test
shouldBeEmptyInitially()38     public void shouldBeEmptyInitially() {
39         IntSet set = new IntSet();
40         assertThat(set.size()).isEqualTo(0);
41     }
42 
43     @Test
oneElementSet()44     public void oneElementSet() {
45         IntSet set = new IntSet();
46         set.add(2);
47         assertThat(set.size()).isEqualTo(1);
48         assertTrue(set.contains(2));
49         assertFalse(set.contains(1));
50     }
51 
52 
53     @Test
twoElementSet()54     public void twoElementSet() {
55         IntSet set = new IntSet();
56         set.add(2);
57         set.add(1);
58         assertThat(set.size()).isEqualTo(2);
59         assertTrue(set.contains(2));
60         assertTrue(set.contains(1));
61     }
62 
63     @Test
threeElementSet()64     public void threeElementSet() {
65         IntSet set = new IntSet();
66         set.add(2);
67         set.add(1);
68         set.add(10);
69         assertThat(set.size()).isEqualTo(3);
70         assertEquals("1, 2, 10", set.mArray.toConcatString());
71     }
72 
73 
74     @Test
duplicateEntries()75     public void duplicateEntries() {
76         IntSet set = new IntSet();
77         set.add(2);
78         set.add(2);
79         assertEquals(1, set.size());
80     }
81 }
82