| career | drupal | java | mac | mysql | perl | scala | uml | unix  

Scala example source code file (StrictTreeTest.scala)

This example Scala source code file (StrictTreeTest.scala) is included in the "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

ascii, equal, node, seq, speclite, stricttree, stricttreetest, traverse, tree\'s, vector

The StrictTreeTest.scala Scala example source code

package scalaz

import std.AllInstances._
import scalaz.scalacheck.ScalazProperties._
import scalaz.scalacheck.ScalazArbitrary._
import StrictTree._
import org.scalacheck.Prop.forAll

object StrictTreeTest extends SpecLite {

  checkAll("StrictTree", order.laws[StrictTree[Int]])
  checkAll("StrictTree", traverse1.laws[StrictTree])
  checkAll("StrictTree", applicative.laws[StrictTree])
  checkAll("StrictTree", comonad.laws[StrictTree])
  checkAll("StrictTree", align.laws[StrictTree])
  checkAll("StrictTree", zip.laws[StrictTree])


  "indexed" ! forAll { xs: StrictTree[Byte] =>
    val F = Traverse[StrictTree]
    val a = F.indexed(xs)
    Equal[StrictTree[Byte]].equal(, xs) must_=== true
    F.toList(a) must_=== F.toList(xs){case (a, b) => (b, a)}

  "A tree must can be rendered as an ASCII string" ! {
    Node(1, Vector(Node(2, Vector(Leaf(3))), Leaf(4))).drawTree must_== Seq(
      "+- 2",
      "|  |",
      "|  `- 3",
      "`- 4").mkString("", "\n", "\n")

  "Equals.equal works" ! forAll { (s: StrictTree[Byte]) =>
    val E = Equal[StrictTree[Byte]]
    E.equal(s, s) must_== true

  "flatMap((Leaf(_)) is identity" ! forAll { (s: StrictTree[Byte]) =>
    val actualTree = s.flatMap(Leaf(_))
    Equal[StrictTree[Byte]].equal(actualTree, s) must_== true

  "flatten is the same as the lazy Tree's flatten" ! forAll { (s: StrictTree[Byte]) =>
    s.flatten must_=== s.toTree.flatten.toVector

  "StrictTree#toTree and Tree#toStrictTree are inverses" ! forAll { (s: StrictTree[Byte]) =>
    Equal[StrictTree[Byte]].equal(s, s.toTree.toStrictTree) must_=== true

  "size gives the same number of elements as flatten" ! forAll { (s: StrictTree[Byte]) =>
    s.flatten.size must_=== s.size


Other Scala examples (source code examples)

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

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

#1 New Release!

FP Best Seller


new blog posts


Copyright 1998-2021 Alvin Alexander,
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.