blob: 58f2e096ea10aede4c8aa3354f15396cc92dda80 [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
62 public void sizeAndGet() {
63 Selection other = new Selection();
64 for (int i = 0; i < selection.size(); i++) {
65 other.add(selection.get(i));
66 }
67 assertEquals(selection.size(), other.size());
68 }
69
70 @Test
71 public void equalsSelf() {
72 assertEquals(selection, selection);
73 }
74
75 @Test
76 public void equalsOther() {
77 Selection other = new Selection();
78 other.add(3);
79 other.add(5);
80 other.add(9);
81 assertEquals(selection, other);
Steve McKayf4c06ab2015-07-22 11:42:14 -070082 assertEquals(selection.hashCode(), other.hashCode());
83 }
84
85 @Test
86 public void equalsCopy() {
87 Selection other = new Selection();
88 other.copyFrom(selection);
89 assertEquals(selection, other);
90 assertEquals(selection.hashCode(), other.hashCode());
91 }
92
93 @Test
94 public void notEquals() {
95 Selection other = new Selection();
96 other.add(789);
97 assertFalse(selection.equals(other));
Steve McKayef280152015-06-11 10:10:49 -070098 }
99
100 @Test
101 public void expandBefore() {
102 selection.expand(2, 10);
103 assertEquals(3, selection.size());
104 assertContains(13);
105 assertContains(15);
106 assertContains(19);
107 }
108
109 @Test
110 public void expandAfter() {
111 selection.expand(10, 10);
112 assertEquals(3, selection.size());
113 assertContains(3);
114 assertContains(5);
115 assertContains(9);
116 }
117
118 @Test
119 public void expandSplit() {
120 selection.expand(5, 10);
121 assertEquals(3, selection.size());
122 assertContains(3);
123 assertContains(15);
124 assertContains(19);
125 }
126
127 @Test
128 public void expandEncompased() {
129 selection.expand(2, 10);
130 assertEquals(3, selection.size());
131 assertContains(13);
132 assertContains(15);
133 assertContains(19);
134 }
135
136 @Test
137 public void collapseBefore() {
138 selection.collapse(0, 2);
139 assertEquals(3, selection.size());
140 assertContains(1);
141 assertContains(3);
142 assertContains(7);
143 }
144
145 @Test
146 public void collapseAfter() {
147 selection.collapse(10, 10);
148 assertEquals(3, selection.size());
149 assertContains(3);
150 assertContains(5);
151 assertContains(9);
152 }
153
154 @Test
155 public void collapseAcross() {
156 selection.collapse(0, 10);
157 assertEquals(0, selection.size());
158 }
159
160 private void assertContains(int i) {
161 String err = String.format("Selection %s does not contain %d", selection, i);
162 assertTrue(err, selection.contains(i));
163 }
164}