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

Scala example source code file (DequeueTest.scala)

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

dequeue, dequeuetest, list, speclite

The DequeueTest.scala Scala example source code

package scalaz

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

object DequeueTest extends SpecLite {
  checkAll(monoid.laws[Dequeue[Int]])
  checkAll(isEmpty.laws[Dequeue])
  checkAll(foldable.laws[Dequeue])
  checkAll(plusEmpty.laws[Dequeue])
  checkAll(functor.laws[Dequeue])

  "fromList works" ! forAll{ (l: List[Int]) ⇒
    Dequeue.fromFoldable(l).toStream must_===(l.toStream)
  }

  "reverse twice is id" ! forAll{ (dq: Dequeue[Int]) ⇒
    dq.reverse.reverse.toIList.must_===(dq.toIList)
  }

  "size consistent with source list" ! forAll{ (l: List[Int]) ⇒
    Dequeue.fromFoldable(l).size must_===(l.size)
  }

  "reverse stream works" ! forAll{ (l: List[Int]) ⇒
    Dequeue.fromFoldable(l).toBackStream must_===(l.reverse.toStream)
  }

  "toIList consistent with Ilist.fromFoldable" ! forAll{ (l: List[Int]) ⇒
    Dequeue.fromFoldable(l).toIList must_===(IList.fromFoldable(l))
  }

  "toBackIList consistent with Ilist.fromFoldable" ! forAll{ (l: List[Int]) ⇒
    Dequeue.fromFoldable(l).toBackIList must_===(IList.fromFoldable(l.reverse))
  }

  "snoc works" ! forAll{ (l: List[Int]) ⇒
    (l.foldLeft[Dequeue[Int]](Dequeue.empty)((q,a) ⇒ q snoc a)).toStream must_=== l.toStream
  }

  "cons works" ! forAll{ (l: List[Int]) ⇒
    (l.foldRight[Dequeue[Int]](Dequeue.empty)((a,q) ⇒ q cons a)).toStream must_=== l.toStream
  }
}

Other Scala examples (source code examples)

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