File tree Expand file tree Collapse file tree 2 files changed +32
-2
lines changed
src/library/scala/collection/immutable
test/junit/scala/collection/immutable Expand file tree Collapse file tree 2 files changed +32
-2
lines changed Original file line number Diff line number Diff line change @@ -156,7 +156,7 @@ override def companion: GenericCompanion[Vector] = Vector
156
156
override def take (n : Int ): Vector [A ] = {
157
157
if (n <= 0 )
158
158
Vector .empty
159
- else if (startIndex + n < endIndex)
159
+ else if (startIndex < endIndex - n )
160
160
dropBack0(startIndex + n)
161
161
else
162
162
this
@@ -165,7 +165,7 @@ override def companion: GenericCompanion[Vector] = Vector
165
165
override def drop (n : Int ): Vector [A ] = {
166
166
if (n <= 0 )
167
167
this
168
- else if (startIndex + n < endIndex)
168
+ else if (startIndex < endIndex - n )
169
169
dropFront0(startIndex + n)
170
170
else
171
171
Vector .empty
Original file line number Diff line number Diff line change
1
+ package scala .collection .immutable
2
+
3
+ import org .junit .Assert ._
4
+ import org .junit .runner .RunWith
5
+ import org .junit .runners .JUnit4
6
+ import org .junit .Test
7
+
8
+ @ RunWith (classOf [JUnit4 ])
9
+ class VectorTest {
10
+
11
+ @ Test
12
+ def hasCorrectDropAndTakeMethods () {
13
+ val v = Vector (0 ) ++ Vector (1 to 64 : _* )
14
+
15
+ assertEquals(Vector (0 , 1 ), v take 2 )
16
+ assertEquals(Vector (63 , 64 ), v takeRight 2 )
17
+ assertEquals(Vector (2 to 64 : _* ), v drop 2 )
18
+ assertEquals(Vector (0 to 62 : _* ), v dropRight 2 )
19
+
20
+ assertEquals(v, v take Int .MaxValue )
21
+ assertEquals(v, v takeRight Int .MaxValue )
22
+ assertEquals(Vector .empty[Int ], v drop Int .MaxValue )
23
+ assertEquals(Vector .empty[Int ], v dropRight Int .MaxValue )
24
+
25
+ assertEquals(Vector .empty[Int ], v take Int .MinValue )
26
+ assertEquals(Vector .empty[Int ], v takeRight Int .MinValue )
27
+ assertEquals(v, v drop Int .MinValue )
28
+ assertEquals(v, v dropRight Int .MinValue )
29
+ }
30
+ }
You can’t perform that action at this time.
0 commit comments