Sha256: e5c5fb257dbcfa111ba3e54e19fea019009d21989cfef902b1af706d33f3dbb1

Contents?: true

Size: 1.56 KB

Versions: 34

Compression:

Stored size: 1.56 KB

Contents

import org.scalatest.{FunSuite, Matchers}

class ZipperTest extends FunSuite with Matchers {
  def empty[A]: Option[BinTree[A]] = None

  def bt[A](v: A, l: Option[BinTree[A]], r: Option[BinTree[A]]): Option[BinTree[A]] =
    Some(BinTree(v, l, r))

  def leaf[A](v: A): Option[BinTree[A]] =
    Some(BinTree(v, None, None))

  val t1: BinTree[Int] = BinTree(1, bt(2, empty,   leaf(3)), leaf(4))
  val t2: BinTree[Int] = BinTree(1, bt(5, empty,   leaf(3)), leaf(4))
  val t3: BinTree[Int] = BinTree(1, bt(2, leaf(5), leaf(3)), leaf(4))
  val t4: BinTree[Int] = BinTree(1, leaf(2),                 leaf(4))

  def fromSome[T](o: Option[T]) = o.get

  val z = Zipper

  test("data is retained") {
   z.toTree(z.fromTree(t1)) should be (t1)
  }

  test("left, right and value") {
    z.value(fromSome(z.right(fromSome(z.left(z.fromTree(t1)))))) should be (3)
  }

  test("dead end") {
    (z.left(fromSome(z.left(z.fromTree(t1))))) should be (None)
  }

  test("tree from deep focus") {
    z.toTree(fromSome(z.right(fromSome(z.left(z.fromTree(t1)))))) should be (t1)
  }

  test("setValue") {
    z.toTree(z.setValue(5, (fromSome(z.left(z.fromTree(t1)))))) should be (t2)
  }

  test("setLeft with Some") {
    z.toTree(z.setLeft(Some(BinTree(5, None, None)),
        (fromSome(z.left(z.fromTree(t1)))))) should be (t3)
  }

  test("setRight with None") {
    z.toTree(z.setRight(None, (fromSome(z.left(z.fromTree(t1)))))) should be (t4)
  }

  test("different paths to same zipper") {
    z.right(fromSome(z.up(fromSome(z.left(z.fromTree(t1)))))) should be
      (z.right(z.fromTree(t1)))
  }
}

Version data entries

34 entries across 34 versions & 1 rubygems

Version Path
trackler-2.0.3.8 tracks/scala/exercises/zipper/src/test/scala/ZipperTest.scala
trackler-2.0.3.7 tracks/scala/exercises/zipper/src/test/scala/ZipperTest.scala
trackler-2.0.3.6 tracks/scala/exercises/zipper/src/test/scala/ZipperTest.scala
trackler-2.0.3.5 tracks/scala/exercises/zipper/src/test/scala/ZipperTest.scala
trackler-2.0.3.4 tracks/scala/exercises/zipper/src/test/scala/ZipperTest.scala
trackler-2.0.3.3 tracks/scala/exercises/zipper/src/test/scala/ZipperTest.scala
trackler-2.0.3.2 tracks/scala/exercises/zipper/src/test/scala/ZipperTest.scala
trackler-2.0.3.1 tracks/scala/exercises/zipper/src/test/scala/ZipperTest.scala
trackler-2.0.3.0 tracks/scala/exercises/zipper/src/test/scala/ZipperTest.scala
trackler-2.0.2.0 tracks/scala/exercises/zipper/src/test/scala/ZipperTest.scala
trackler-2.0.1.2 tracks/scala/exercises/zipper/src/test/scala/ZipperTest.scala
trackler-2.0.1.1 tracks/scala/exercises/zipper/src/test/scala/ZipperTest.scala
trackler-2.0.1.0 tracks/scala/exercises/zipper/src/test/scala/ZipperTest.scala
trackler-2.0.0.10 tracks/scala/exercises/zipper/src/test/scala/ZipperTest.scala
trackler-2.0.0.9 tracks/scala/exercises/zipper/src/test/scala/ZipperTest.scala
trackler-2.0.0.8 tracks/scala/exercises/zipper/src/test/scala/ZipperTest.scala
trackler-2.0.0.7 tracks/scala/exercises/zipper/src/test/scala/ZipperTest.scala
trackler-2.0.0.6 tracks/scala/exercises/zipper/src/test/scala/ZipperTest.scala
trackler-2.0.0.5 tracks/scala/exercises/zipper/src/test/scala/ZipperTest.scala
trackler-2.0.0.4 tracks/scala/exercises/zipper/src/test/scala/ZipperTest.scala