Skip to content

Commit fa380d3

Browse files
julienrflrytz
authored andcommitted
Test: implement SeqOps with a value class
1 parent 83ea4af commit fa380d3

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package scala.collection
2+
3+
import org.junit.Test
4+
5+
class ValueClassSeqOpsImpl(private val array: Array[Int]) extends AnyVal with IterableOnce[Int] with SeqOps[Int, Seq, ValueClassSeqOpsImpl] {
6+
def apply(i: Int): Int = array(i)
7+
def length: Int = array.length
8+
def iterator: Iterator[Int] = array.iterator
9+
def toIterable: Iterable[Int] = array.toIndexedSeq
10+
protected def coll: ValueClassSeqOpsImpl = this
11+
protected def fromSpecific(coll: IterableOnce[Int]): ValueClassSeqOpsImpl =
12+
new ValueClassSeqOpsImpl(coll.iterator.toArray)
13+
def iterableFactory: IterableFactory[Seq] = Seq
14+
protected def newSpecificBuilder: mutable.Builder[Int, ValueClassSeqOpsImpl] =
15+
Array.newBuilder[Int].mapResult(new ValueClassSeqOpsImpl(_))
16+
override def toString = mkString("ValueClassSeqOpsImpl(", ", ", ")")
17+
}
18+
19+
class ValueClassSeqOpsTest {
20+
@Test
21+
def testPermutation(): Unit = {
22+
val array = Array(1, 2, 3)
23+
val wrapper = new ValueClassSeqOpsImpl(array)
24+
val permutations = wrapper.permutations.toSeq.map(_.toSeq)
25+
assert(permutations == List(1, 2, 3).permutations.toSeq)
26+
}
27+
}

0 commit comments

Comments
 (0)