summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2009-07-18 13:20:09 +0000
committerPaul Phillips <paulp@improving.org>2009-07-18 13:20:09 +0000
commit1f6c8f2be985dd24cb47dc1569d7980cf7a0fd2f (patch)
tree78c93f549f0ed59e172ae0b5b41aa81939ac9a26
parentd6798ac2ab92a8414678fc075c4381e0bc51f438 (diff)
downloadscala-1f6c8f2be985dd24cb47dc1569d7980cf7a0fd2f.tar.gz
scala-1f6c8f2be985dd24cb47dc1569d7980cf7a0fd2f.tar.bz2
scala-1f6c8f2be985dd24cb47dc1569d7980cf7a0fd2f.zip
Removed some identical code from the collection...
Removed some identical code from the collections classes in hopes of finding some consistency in collections equality. Added more test cases to the sequenceComparisons test.
-rw-r--r--src/library/scala/collection/generic/LinearSequenceTemplate.scala12
-rw-r--r--src/library/scala/collection/generic/SequenceTemplate.scala12
-rw-r--r--src/library/scala/collection/generic/VectorTemplate.scala11
-rw-r--r--test/files/run/sequenceComparisons.check2
-rw-r--r--test/files/run/sequenceComparisons.scala12
5 files changed, 12 insertions, 37 deletions
diff --git a/src/library/scala/collection/generic/LinearSequenceTemplate.scala b/src/library/scala/collection/generic/LinearSequenceTemplate.scala
index 285170f63d..5a66f4cfa5 100644
--- a/src/library/scala/collection/generic/LinearSequenceTemplate.scala
+++ b/src/library/scala/collection/generic/LinearSequenceTemplate.scala
@@ -361,15 +361,7 @@ trait LinearSequenceTemplate[+A, +This <: LinearSequenceTemplate[A, This] with L
}
override def equals(that: Any): Boolean = that match {
- case that1: LinearSequence[a] =>
- var these = this
- var those = that1
- while (!these.isEmpty && !those.isEmpty && these.head == those.head) {
- these = these.tail
- those = those.tail
- }
- these.isEmpty && those.isEmpty
- case _ =>
- super.equals(that)
+ case that: LinearSequence[_] => this sameElements that
+ case _ => super.equals(that)
}
}
diff --git a/src/library/scala/collection/generic/SequenceTemplate.scala b/src/library/scala/collection/generic/SequenceTemplate.scala
index 6696ca9e8c..0b210dd3f5 100644
--- a/src/library/scala/collection/generic/SequenceTemplate.scala
+++ b/src/library/scala/collection/generic/SequenceTemplate.scala
@@ -569,16 +569,8 @@ trait SequenceTemplate[+A, +This <: IterableTemplate[A, This] with Sequence[A]]
}
override def equals(that: Any): Boolean = that match {
- case that1: Sequence[a] =>
- val these = this.iterator
- val those = that1.iterator
- while (these.hasNext && those.hasNext)
- if (these.next() != those.next())
- return false
-
- !these.hasNext && !those.hasNext
- case _ =>
- false
+ case that: Sequence[_] => this sameElements that
+ case _ => false
}
/** Need to override string, so that it's not the Function1's string that gets mixed in.
diff --git a/src/library/scala/collection/generic/VectorTemplate.scala b/src/library/scala/collection/generic/VectorTemplate.scala
index 96e80276b8..daba1709cd 100644
--- a/src/library/scala/collection/generic/VectorTemplate.scala
+++ b/src/library/scala/collection/generic/VectorTemplate.scala
@@ -258,15 +258,8 @@ trait VectorTemplate[+A, +This <: VectorTemplate[A, This] with Vector[A]] extend
}
override def equals(that: Any): Boolean = that match {
- case that1: Vector[a] =>
- val len = this.length
- len == that1.length && {
- var i = 0
- while (i < len && this(i) == that1(i)) i += 1
- i == len
- }
- case _ =>
- super.equals(that)
+ case that: Vector[_] => this.length == that.length && startsWith(that, 0)
+ case _ => super.equals(that)
}
override def view = new VectorView[A, This] {
diff --git a/test/files/run/sequenceComparisons.check b/test/files/run/sequenceComparisons.check
index bb7669b154..df8e41125d 100644
--- a/test/files/run/sequenceComparisons.check
+++ b/test/files/run/sequenceComparisons.check
@@ -1 +1 @@
-All 3600 tests passed.
+All 4000 tests passed.
diff --git a/test/files/run/sequenceComparisons.scala b/test/files/run/sequenceComparisons.scala
index ee4df8e40e..192002bdd6 100644
--- a/test/files/run/sequenceComparisons.scala
+++ b/test/files/run/sequenceComparisons.scala
@@ -9,6 +9,7 @@ object Test {
// the commented out ones in seqMakers
val seqMakers = List[List[Int] => Sequence[Int]](
+ // scala.Array(_: _*),
mutable.ArrayBuffer(_: _*),
// mutable.ArrayStack(_: _*),
mutable.Buffer(_: _*),
@@ -30,6 +31,7 @@ object Test {
abstract class Data[T] {
val seq: Sequence[T]
+ private def seqList = seq.toList
// _1 is inputs which must be true, _2 which must be false
type Inputs = (List[List[T]], List[List[T]])
case class Method(
@@ -41,6 +43,8 @@ object Test {
def falseList = inputs._2
}
+ lazy val eqeq = Method(_ == _, (List(seqList), List(Nil, seqList drop 1, seqList ::: seqList)), "%s == %s")
+
val startsWithInputs: Inputs
lazy val startsWith = Method(_ startsWith _, startsWithInputs, "%s startsWith %s")
@@ -54,7 +58,7 @@ object Test {
val sameElementsInputs: Inputs
lazy val sameElements = Method(_ sameElements _, sameElementsInputs, "%s sameElements %s")
- def methodList = List(startsWith, endsWith, indexOfSeq, sameElements)
+ def methodList = List(eqeq, startsWith, endsWith, indexOfSeq, sameElements)
}
object test1 extends Data[Int] {
@@ -98,12 +102,6 @@ object Test {
import testData._
val scrut = s1f(seq)
- // for (s <- starters ; val rhs = s2f(s))
- // assertOne(scrut, rhs, scrut startsWith rhs, "%s startsWith %s")
- //
- // for (ns <- nonStarters ; val rhs = s2f(ns))
- // assertOne(scrut, rhs, !(scrut startsWith rhs), "!(%s startsWith %s)")
-
for (Method(f, (trueList, falseList), descr) <- methodList) {
for (s <- trueList; val rhs = s2f(s))
assertOne(scrut, rhs, f(scrut, rhs), descr)