|
Scala example source code file (DievTest.scala)
The DievTest.scala Scala example source codepackage scalaz import std.AllInstances._ import scalaz.scalacheck.ScalazProperties._ import scalaz.scalacheck.ScalazArbitrary._ import scala.util.Random import org.scalacheck.Prop.forAll object DievTest extends SpecLite { val random = new Random() "insert order makes no difference" ! forAll { (list: List[Int]) => { val shuffledList = random.shuffle(list) val dievFromList = list.foldLeft(Diev.empty[Int])(_ + _) val dievFromShuffledList = shuffledList.foldLeft(Diev.empty[Int])(_ + _) dievFromList must_===(dievFromShuffledList) } } "fixIntervalOrder" ! forAll { (tuple: (Int, Int)) => { val expectedResult = if (tuple._1 > tuple._2) tuple.swap else tuple DievInterval.fixIntervalOrder(tuple) must_===(expectedResult) } } // TODO: Use data table to test subtractInterval. "fromValuesSeq / toSet" ! forAll { (set: Set[Int]) => Diev.fromValuesSeq(set.toSeq).toSet must_===(set) } "fromValuesSeq / toList" ! forAll { (list: List[Int]) => { val sortedList = list.toSet.toList.sorted Diev.fromValuesSeq(list).toList must_===(sortedList) } } "++ associativity" ! forAll { (first: Diev[Int], second: Diev[Int]) => first ++ second must_===(second ++ first) } "intervals / fromIntervalsSeq" ! forAll { (original: Diev[Int]) => Diev.fromIntervalsSeq(original.intervals) must_===(original) } "-- / ++" ! forAll { (first: Diev[Int], second: Diev[Int]) => first -- second ++ second must_===(first ++ second) } checkAll(equal.laws[Diev[Int]]) checkAll(monoid.laws[Diev[Int]]) } Other Scala examples (source code examples)Here is a short list of links related to this Scala DievTest.scala source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
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.