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

Scala example source code file (HeapTest.scala)

This example Scala source code file (HeapTest.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

heap, heaptest, int, speclite

The HeapTest.scala Scala example source code

package scalaz

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

object HeapTest extends SpecLite {
  checkAll(equal.laws[Heap[Int]])
  checkAll(monoid.laws[Heap[Int]])
  checkAll(foldable.laws[Heap])

  def pred(i: Int) = i % 2 == 0

  "order maintained for toList" ! forAll {
    (a: Heap[Int]) => a.toList must_===(a.toList.sorted)
  }

  "toList / toStream" ! forAll {
    (a: Heap[Int]) => a.toStream must_===(a.toList.toStream)
  }

  "filter" ! forAll {
    (a: Heap[Int]) => a.filter(pred).toStream must_===(a.toStream.filter(pred))
  }

  "partition" ! forAll {
    (a: Heap[Int]) =>
      val (ts, fs) = a.partition(pred)
      ts.forall(pred) must_===(true)
      fs.exists(pred) must_===(false)
  }

  "split" ! forAll {
    (a: Heap[Int], x: Int) =>
      val (lt, eq, gt) = a.split(x)
      lt.forall(_ < x) must_===(true)
      eq.forall(_ == x) must_===(true)
      gt.forall(_ > x) must_===(true)
  }
}

Other Scala examples (source code examples)

Here is a short list of links related to this Scala HeapTest.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.