blob: 51b542b2ae8ccdb041ed903fde7c218eb817927a [file] [log] [blame]
Steve McKayef280152015-06-11 10:10:49 -07001/*
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
17package com.android.documentsui;
18
Steve McKayf4c06ab2015-07-22 11:42:14 -070019import static org.junit.Assert.*;
Steve McKayef280152015-06-11 10:10:49 -070020
21import com.android.documentsui.MultiSelectManager.Selection;
22
23import org.junit.Before;
24import org.junit.Test;
25
26public class MultiSelectManager_SelectionTest {
27
28 private Selection selection;
29
30 @Before
31 public void setUp() throws Exception {
32 selection = new Selection();
33 selection.add(3);
34 selection.add(5);
35 selection.add(9);
36 }
37
38 @Test
39 public void add() {
40 // We added in setUp.
41 assertEquals(3, selection.size());
42 assertContains(3);
43 assertContains(5);
44 assertContains(9);
45 }
46
47 @Test
48 public void remove() {
49 selection.remove(3);
50 selection.remove(5);
51 assertEquals(1, selection.size());
52 assertContains(9);
53 }
54
55 @Test
56 public void clear() {
57 selection.clear();
58 assertEquals(0, selection.size());
59 }
60
61 @Test
Steve McKay9459a7c2015-07-24 13:14:20 -070062 public void isEmpty() {
63 assertTrue(new Selection().isEmpty());
64 selection.clear();
65 assertTrue(selection.isEmpty());
66 }
67
68 @Test
Steve McKayef280152015-06-11 10:10:49 -070069 public void sizeAndGet() {
70 Selection other = new Selection();
71 for (int i = 0; i < selection.size(); i++) {
72 other.add(selection.get(i));
73 }
74 assertEquals(selection.size(), other.size());
75 }
76
77 @Test
78 public void equalsSelf() {
79 assertEquals(selection, selection);
80 }
81
82 @Test
83 public void equalsOther() {
84 Selection other = new Selection();
85 other.add(3);
86 other.add(5);
87 other.add(9);
88 assertEquals(selection, other);
Steve McKayf4c06ab2015-07-22 11:42:14 -070089 assertEquals(selection.hashCode(), other.hashCode());
90 }
91
92 @Test
93 public void equalsCopy() {
94 Selection other = new Selection();
95 other.copyFrom(selection);
96 assertEquals(selection, other);
97 assertEquals(selection.hashCode(), other.hashCode());
98 }
99
100 @Test
101 public void notEquals() {
102 Selection other = new Selection();
103 other.add(789);
104 assertFalse(selection.equals(other));
Steve McKayef280152015-06-11 10:10:49 -0700105 }
106
107 @Test
108 public void expandBefore() {
109 selection.expand(2, 10);
110 assertEquals(3, selection.size());
111 assertContains(13);
112 assertContains(15);
113 assertContains(19);
114 }
115
116 @Test
117 public void expandAfter() {
118 selection.expand(10, 10);
119 assertEquals(3, selection.size());
120 assertContains(3);
121 assertContains(5);
122 assertContains(9);
123 }
124
125 @Test
126 public void expandSplit() {
127 selection.expand(5, 10);
128 assertEquals(3, selection.size());
129 assertContains(3);
130 assertContains(15);
131 assertContains(19);
132 }
133
134 @Test
135 public void expandEncompased() {
136 selection.expand(2, 10);
137 assertEquals(3, selection.size());
138 assertContains(13);
139 assertContains(15);
140 assertContains(19);
141 }
142
143 @Test
144 public void collapseBefore() {
145 selection.collapse(0, 2);
146 assertEquals(3, selection.size());
147 assertContains(1);
148 assertContains(3);
149 assertContains(7);
150 }
151
152 @Test
153 public void collapseAfter() {
154 selection.collapse(10, 10);
155 assertEquals(3, selection.size());
156 assertContains(3);
157 assertContains(5);
158 assertContains(9);
159 }
160
161 @Test
162 public void collapseAcross() {
163 selection.collapse(0, 10);
164 assertEquals(0, selection.size());
165 }
166
167 private void assertContains(int i) {
168 String err = String.format("Selection %s does not contain %d", selection, i);
169 assertTrue(err, selection.contains(i));
170 }
171}