alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Scala example source code file (TreeLocTest.scala)

This example Scala source code file (TreeLocTest.scala) is included in the alvinalexander.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Scala by Example" TM.

Learn more about this Scala project at its project page.

Java - Scala tags/keywords

equal, option, order, speclite, tree, treeloc, treeloctest

The TreeLocTest.scala Scala example source code

package scalaz

import std.AllInstances._
import scalaz.scalacheck.ScalazProperties._
import scalaz.scalacheck.ScalazArbitrary._

object TreeLocTest extends SpecLite {

  checkAll("TreeLoc", order.laws[TreeLoc[Int]])
  checkAll("TreeLoc", traverse1.laws[TreeLoc])
  checkAll(FoldableTests.anyAndAllLazy[TreeLoc])

  {
    def treeEqual[A: Equal]: Equal[Tree[A]] = new Equal[Tree[A]] {
      import std.stream.streamEqual
      def streamEqualApprox = streamEqual[Tree[A]].contramap((_: Stream[Tree[A]]).take(1000))
      def equal(a1: Tree[A], a2: Tree[A]) =
        Equal[A].equal(a1.rootLabel, a2.rootLabel) && streamEqualApprox.equal(a1.subForest, a2.subForest)
    }

    // TODO checkAll("TreeLoc", applicative.laws[TreeLoc])
    checkAll("TreeLoc", comonad.laws[TreeLoc])
  }

  "TreeLoc from empty forest does not throw an exception" ! {
    import scalaz.std.option._
    val result: Option[TreeLoc[Int]] = TreeLoc.fromForest(Stream.empty[Tree[Int]])
    result must_==(none[TreeLoc[Int]])
  }

  object instances {
    def equal[A: Equal] = Equal[TreeLoc[A]]
    def order[A: Order] = Order[TreeLoc[A]]

    // checking absence of ambiguity
    def equal[A: Order] = Equal[TreeLoc[A]]
  }
}

Other Scala examples (source code examples)

Here is a short list of links related to this Scala TreeLocTest.scala source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.