Sha256: 1a3102808c7ef11fbce28896721a034bfbfbbb9046f8e117701c009e8664f15a

Contents?: true

Size: 1.67 KB

Versions: 148

Compression:

Stored size: 1.67 KB

Contents

import org.scalatest.{FunSuite, Matchers}

/** @version created manually **/
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") {
    pending
    z.value(fromSome(z.right(fromSome(z.left(z.fromTree(t1)))))) should be (3)
  }

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

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

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

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

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

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

Version data entries

148 entries across 148 versions & 1 rubygems

Version Path
trackler-2.2.1.98 tracks/scala/exercises/zipper/src/test/scala/ZipperTest.scala
trackler-2.2.1.97 tracks/scala/exercises/zipper/src/test/scala/ZipperTest.scala
trackler-2.2.1.96 tracks/scala/exercises/zipper/src/test/scala/ZipperTest.scala
trackler-2.2.1.95 tracks/scala/exercises/zipper/src/test/scala/ZipperTest.scala
trackler-2.2.1.94 tracks/scala/exercises/zipper/src/test/scala/ZipperTest.scala
trackler-2.2.1.93 tracks/scala/exercises/zipper/src/test/scala/ZipperTest.scala
trackler-2.2.1.92 tracks/scala/exercises/zipper/src/test/scala/ZipperTest.scala
trackler-2.2.1.91 tracks/scala/exercises/zipper/src/test/scala/ZipperTest.scala
trackler-2.2.1.90 tracks/scala/exercises/zipper/src/test/scala/ZipperTest.scala
trackler-2.2.1.89 tracks/scala/exercises/zipper/src/test/scala/ZipperTest.scala
trackler-2.2.1.88 tracks/scala/exercises/zipper/src/test/scala/ZipperTest.scala
trackler-2.2.1.87 tracks/scala/exercises/zipper/src/test/scala/ZipperTest.scala
trackler-2.2.1.86 tracks/scala/exercises/zipper/src/test/scala/ZipperTest.scala
trackler-2.2.1.85 tracks/scala/exercises/zipper/src/test/scala/ZipperTest.scala
trackler-2.2.1.84 tracks/scala/exercises/zipper/src/test/scala/ZipperTest.scala
trackler-2.2.1.83 tracks/scala/exercises/zipper/src/test/scala/ZipperTest.scala
trackler-2.2.1.82 tracks/scala/exercises/zipper/src/test/scala/ZipperTest.scala
trackler-2.2.1.81 tracks/scala/exercises/zipper/src/test/scala/ZipperTest.scala
trackler-2.2.1.80 tracks/scala/exercises/zipper/src/test/scala/ZipperTest.scala
trackler-2.2.1.79 tracks/scala/exercises/zipper/src/test/scala/ZipperTest.scala